Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,78 @@
|
|
1 |
---
|
2 |
license: llama2
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: llama2
|
3 |
---
|
4 |
+
|
5 |
+
---
|
6 |
+
license: apache-2.0
|
7 |
+
---
|
8 |
+
|
9 |
+
# LMCocktail-10.7B function calling
|
10 |
+
|
11 |
+
This is a merged model of the https://huggingface.co/Yhyu13/LMCocktail-10.7B-v1 and sft function calling lora [here](https://huggingface.co/Yhyu13/LMCocktail-10.7B-v1-function-calling-lora)
|
12 |
+
|
13 |
+
This model is acompanied with pr on textgen-webui to enable its function calling ability like GPTs: [Add function calling ability to openai extension](https://github.com/oobabooga/text-generation-webui/pull/5185)
|
14 |
+
|
15 |
+
This model is recommanded over my [ph-2 variant](https://huggingface.co/Yhyu13/dolphin-2_6-phi-2-sft-glaive-function-calling-v2-ep1) since this model has more grounding ability on following function calling prompt
|
16 |
+
|
17 |
+
This model is by far my 2nd best function calling model, it can achieve 9/10 success on [openai function calling cook book](https://github.com/openai/openai-cookbook/blob/main/examples/How_to_call_functions_with_chat_models.ipynb)
|
18 |
+
|
19 |
+
Also, checkout my best function calling model here: https://huggingface.co/Yhyu13/dolphin-2.6-mistral-7b-dpo-laser-function-calling
|
20 |
+
|
21 |
+
|
22 |
+
The function calling is wrapped in simple xml tag for eaiser identification.
|
23 |
+
|
24 |
+
```
|
25 |
+
<functioncall> {\"name\": \"calculate_loan_payment\", \"arguments\": '{\"principal\": 50000, \"interest_rate\": 5, \"loan_term\": 10}'} </functioncall>
|
26 |
+
```
|
27 |
+
|
28 |
+
that can be extracted like this
|
29 |
+
|
30 |
+
```
|
31 |
+
import re
|
32 |
+
import json
|
33 |
+
|
34 |
+
input_str = "<functioncall> {\"name\": \"calculate_loan_payment\", \"arguments\": '{\"principal\": 50000, \"interest_rate\": 5, \"loan_term\": 10}'} </functioncall>"
|
35 |
+
|
36 |
+
# Define the pattern to match the JSON string within the functioncall tags
|
37 |
+
pattern = r'<functioncall>(.*?)</functioncall>'
|
38 |
+
|
39 |
+
# Use re.search to find the matched pattern
|
40 |
+
match = re.search(pattern, input_str, re.DOTALL)
|
41 |
+
|
42 |
+
if match:
|
43 |
+
json_str = match.group(1)
|
44 |
+
# Remove the single quotes surrounding the inner JSON string
|
45 |
+
json_str = json_str.replace("'", "")
|
46 |
+
|
47 |
+
# Load the JSON string into a Python dictionary
|
48 |
+
json_data = json.loads(json_str)
|
49 |
+
print(json_data)
|
50 |
+
else:
|
51 |
+
print("No match found.")
|
52 |
+
```
|
53 |
+
|
54 |
+
Or, if you want to faithfully keep the single quotes that wrapps the `arguments` value (where openai does it like this, which makes `json.loads` fail shortly on the original `json_str`), use `ast.literal_eval` for the rescue.
|
55 |
+
|
56 |
+
```
|
57 |
+
if match:
|
58 |
+
import ast
|
59 |
+
json_str = match.group(1)
|
60 |
+
json_str = json_str.strip()
|
61 |
+
"""
|
62 |
+
https://www.datasciencebyexample.com/2023/03/16/what-to-do-when-single-quotes-in-json-string/
|
63 |
+
"""
|
64 |
+
json_dict = ast.literal_eval(json_str)
|
65 |
+
print(json_dict['name'], json_dict['arguments'])
|
66 |
+
else:
|
67 |
+
print("No match found.")
|
68 |
+
```
|
69 |
+
|
70 |
+
Hopefully, this model can be a drop-in replacement for apps (e.g. memgpt) that require function calling ability from LLMs.
|
71 |
+
|
72 |
+
Another note on interpreting function call result:
|
73 |
+
|
74 |
+
Function response has been put between `<functionresponse>` in order to be identified as a function call result (which could be evaluted behind the scene, and its result in principle should be interpreted as part of the user input), which then will be processed by the assistant for form a conversational response.
|
75 |
+
|
76 |
+
```
|
77 |
+
<functionresponse> jons_str </functionresponse>
|
78 |
+
```
|