nguyenthanhthuan commited on
Commit
c2ebcbc
·
verified ·
1 Parent(s): 43e2f47

Upload Readme

Browse files
Files changed (1) hide show
  1. README.md +224 -10
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- base_model: unsloth/llama-3.2-1b-instruct
 
3
  language:
4
  - en
5
- - vi
6
  license: apache-2.0
7
  tags:
8
  - text-generation-inference
@@ -10,17 +10,231 @@ tags:
10
  - unsloth
11
  - llama
12
  - trl
13
- - ollama
 
14
  datasets:
15
- - lilacai/glaive-function-calling-v2-sharegpt
16
  ---
 
17
 
18
- # Uploaded model
 
19
 
20
- - **Developed by:** nguyenthanhthuan
21
- - **License:** apache-2.0
22
- - **Finetuned from model :** unsloth/llama-3.2-1b-instruct
23
 
24
- This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
 
 
 
 
25
 
26
- [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ base_model:
3
+ - meta-llama/Llama-3.2-1B-Instruct
4
  language:
5
  - en
 
6
  license: apache-2.0
7
  tags:
8
  - text-generation-inference
 
10
  - unsloth
11
  - llama
12
  - trl
13
+ - Ollama
14
+ - Tool-Calling
15
  datasets:
16
+ - hiyouga/glaive-function-calling-v2-sharegpt
17
  ---
18
+ # Function Calling Llama Model
19
 
20
+ ## Overview
21
+ A specialized fine-tuned version of the meta-llama/Llama-3.2-1B-Instruct model enhanced with function/tool calling capabilities. The model leverages the **hiyouga/glaive-function-calling-v2-sharegpt** dataset for training.
22
 
23
+ ## Model Specifications
 
 
24
 
25
+ * **Base Architecture**: meta-llama/Llama-3.2-1B-Instruct
26
+ * **Primary Language**: English (Function/Tool Calling), Vietnamese
27
+ * **Licensing**: Apache 2.0
28
+ * **Primary Developer**: nguyenthanhthuan_banhmi
29
+ * **Key Capabilities**: text-generation-inference, transformers, unsloth, llama, trl, Ollama, Tool-Calling
30
 
31
+ ## Getting Started
32
+
33
+ ### Prerequisites
34
+
35
+ 1. Install [Ollama](https://ollama.com/)
36
+ 2. Install required Python packages:
37
+ ```bash
38
+ pip install langchain pydantic torch langchain-ollama
39
+ ```
40
+
41
+ ### Installation Steps
42
+
43
+ 1. Clone the repository
44
+ 2. Navigate to the project directory
45
+ 3. Create the model in Ollama:
46
+ ```bash
47
+ ollama create <model_name> -f <path_to_modelfile>
48
+ ```
49
+
50
+ ## Implementation Guide
51
+
52
+ ### Model Initialization
53
+
54
+ ```python
55
+ from langchain_ollama import ChatOllama
56
+
57
+ # Initialize model instance
58
+ llm = ChatOllama(model="<model_name>")
59
+ ```
60
+
61
+ ### Basic Usage Example
62
+
63
+ ```python
64
+ # Arithmetic computation example
65
+ query = "What is 3 * 12? Also, what is 11 + 49?"
66
+ response = llm.invoke(query)
67
+
68
+ print(response.content)
69
+ # Output:
70
+ # 1. 3 times 12 is 36.
71
+ # 2. 11 plus 49 is 60.
72
+ ```
73
+
74
+ ### Advanced Function Calling (English Recommended)
75
+
76
+ #### Basic Arithmetic Tools
77
+ ```python
78
+ from pydantic import BaseModel, Field
79
+
80
+ class add(BaseModel):
81
+ """Addition operation for two integers."""
82
+ a: int = Field(..., description="First integer")
83
+ b: int = Field(..., description="Second integer")
84
+
85
+ class multiply(BaseModel):
86
+ """Multiplication operation for two integers."""
87
+ a: int = Field(..., description="First integer")
88
+ b: int = Field(..., description="Second integer")
89
+
90
+ # Tool registration
91
+ tools = [add, multiply]
92
+ llm_tools = llm.bind_tools(tools)
93
+
94
+ # Execute query
95
+ response = llm_tools.invoke(query)
96
+ print(response.content)
97
+ # Output:
98
+ # {"type":"function","function":{"name":"multiply","arguments":[{"a":3,"b":12}]}}
99
+ # {"type":"function","function":{"name":"add","arguments":[{"a":11,"b":49}}]}}
100
+ ```
101
+
102
+ #### Complex Tool Integration
103
+
104
+ ```python
105
+ from pydantic import BaseModel, Field
106
+ from typing import List, Optional
107
+
108
+ class SendEmail(BaseModel):
109
+ """Email dispatch functionality."""
110
+ to: List[str] = Field(..., description="List of email recipients")
111
+ subject: str = Field(..., description="Email subject")
112
+ body: str = Field(..., description="Email content/body")
113
+ cc: Optional[List[str]] = Field(None, description="CC recipients")
114
+ attachments: Optional[List[str]] = Field(None, description="List of attachment file paths")
115
+
116
+ class WeatherInfo(BaseModel):
117
+ """Weather information retrieval."""
118
+ city: str = Field(..., description="City name")
119
+ country: Optional[str] = Field(None, description="Country name")
120
+ units: str = Field("celsius", description="Temperature units (celsius/fahrenheit)")
121
+
122
+ class SearchWeb(BaseModel):
123
+ """Web search functionality."""
124
+ query: str = Field(..., description="Search query")
125
+ num_results: int = Field(5, description="Number of results to return")
126
+ language: str = Field("en", description="Search language")
127
+
128
+ class CreateCalendarEvent(BaseModel):
129
+ """Calendar event creation."""
130
+ title: str = Field(..., description="Event title")
131
+ start_time: str = Field(..., description="Event start time (ISO format)")
132
+ end_time: str = Field(..., description="Event end time (ISO format)")
133
+ description: Optional[str] = Field(None, description="Event description")
134
+ attendees: Optional[List[str]] = Field(None, description="List of attendee emails")
135
+
136
+ # Tool integration
137
+ tools = [SendEmail, WeatherInfo, SearchWeb, CreateCalendarEvent]
138
+ llm_tools = llm.bind_tools(tools)
139
+
140
+ # Example usage
141
+ query = "Can you send an email to [email protected] about tomorrow's meeting?"
142
+ print(llm_tools.invoke(query).content)
143
+ # Output:
144
+ #{
145
+ # "type": "function",
146
+ # "function": {
147
+ # "name": "SendEmail",
148
+ # "arguments": {
149
+ # "to": ["[email protected]"],
150
+ # "subject": "",
151
+ # "body": "",
152
+ # "cc": "",
153
+ # "attachments": "",
154
+ # "body": {
155
+ # "message": "Hello John, I wanted to let you know that we have a meeting scheduled for tomorrow. Please mark your calendar."
156
+ # }
157
+ # }
158
+ # }
159
+ # }
160
+
161
+ ```
162
+
163
+ ## Core Features
164
+
165
+ * Arithmetic computation support
166
+ * Advanced function/tool calling capabilities
167
+ * Seamless Langchain integration
168
+ * Full Ollama platform compatibility
169
+
170
+ ## Technical Details
171
+
172
+ ### Dataset Information
173
+ Training utilized the hiyouga/glaive-function-calling-v2-sharegpt dataset, featuring comprehensive function calling interaction examples.
174
+
175
+ ### Known Limitations
176
+
177
+ * Basic function/tool calling
178
+ * English language support exclusively
179
+ * Ollama installation dependency
180
+
181
+ ## Important Notes & Considerations
182
+
183
+ ### Potential Limitations and Edge Cases
184
+
185
+ * **Function Parameter Sensitivity**: The model may occasionally misinterpret complex parameter combinations, especially when multiple optional parameters are involved. Double-check parameter values in critical applications.
186
+
187
+ * **Response Format Variations**:
188
+ - In some cases, the function calling format might deviate from the expected JSON structure
189
+ - The model may generate additional explanatory text alongside the function call
190
+ - Multiple function calls in a single query might not always be processed in the expected order
191
+
192
+ * **Error Handling Considerations**:
193
+ - Empty or null values might not be handled consistently across different function types
194
+ - Complex nested objects may sometimes be flattened unexpectedly
195
+ - Array inputs might occasionally be processed as single values
196
+
197
+ ### Best Practices for Reliability
198
+
199
+ 1. **Input Validation**:
200
+ - Always validate input parameters before processing
201
+ - Implement proper error handling for malformed function calls
202
+ - Consider adding default values for optional parameters
203
+
204
+ 2. **Testing Recommendations**:
205
+ - Test with various input combinations and edge cases
206
+ - Implement retry logic for inconsistent responses
207
+ - Log and monitor function call patterns for debugging
208
+
209
+ 3. **Performance Optimization**:
210
+ - Keep function descriptions concise and clear
211
+ - Limit the number of simultaneous function calls
212
+ - Cache frequently used function results when possible
213
+
214
+ ### Known Issues
215
+
216
+ * Model may struggle with:
217
+ - Very long function descriptions
218
+ - Highly complex nested parameter structures
219
+ - Ambiguous or overlapping function purposes
220
+ - Non-English parameter values or descriptions
221
+
222
+ ## Development
223
+
224
+ ### Contributing Guidelines
225
+ We welcome contributions through issues and pull requests for improvements and bug fixes.
226
+
227
+ ### License Information
228
+ Released under Apache 2.0 license. See LICENSE file for complete terms.
229
+
230
+ ## Academic Citation
231
+
232
+ ```bibtex
233
+ @misc{function-calling-llama,
234
+ author = {nguyenthanhthuan_banhmi},
235
+ title = {Function Calling Llama Model},
236
+ year = {2024},
237
+ publisher = {GitHub},
238
+ journal = {GitHub repository}
239
+ }
240
+ ```