yhyu13 commited on
Commit
8c8a586
1 Parent(s): dd81688
Files changed (1) hide show
  1. README.md +44 -0
README.md CHANGED
@@ -4,3 +4,47 @@ license_name: microsoft-research-license
4
  license_link: >-
5
  https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2/blob/main/LICENSE
6
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  license_link: >-
5
  https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2/blob/main/LICENSE
6
  ---
7
+
8
+ # Phi-2 function calling
9
+
10
+ This is a merged model of the https://huggingface.co/cognitivecomputations/dolphin-2_6-phi-2 and sft function calling lora
11
+
12
+ The sft dataset is https://huggingface.co/datasets/Yhyu13/glaive-function-calling-v2-llama-factory-convert, which I converted for llama_factory from original dataset https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2
13
+
14
+ The function calling is wrapped in simple xml tag for eaiser identification.
15
+
16
+ ```
17
+ <functioncall> {\"name\": \"calculate_loan_payment\", \"arguments\": '{\"principal\": 50000, \"interest_rate\": 5, \"loan_term\": 10}'} </functioncall>
18
+ ```
19
+
20
+ that can be extracted like this
21
+
22
+ ```
23
+ import re
24
+ import json
25
+
26
+ input_str = "<functioncall> {\"name\": \"calculate_loan_payment\", \"arguments\": '{\"principal\": 50000, \"interest_rate\": 5, \"loan_term\": 10}'} </functioncall>"
27
+
28
+ # Define the pattern to match the JSON string within the functioncall tags
29
+ pattern = r'<functioncall>(.*?)</functioncall>'
30
+
31
+ # Use re.search to find the matched pattern
32
+ match = re.search(pattern, input_str, re.DOTALL)
33
+
34
+ if match:
35
+ json_str = match.group(1)
36
+ # Remove the single quotes surrounding the inner JSON string
37
+ json_str = json_str.replace("'", "")
38
+
39
+ # Load the JSON string into a Python dictionary
40
+ json_data = json.loads(json_str)
41
+ print(json_data)
42
+ else:
43
+ print("No match found.")
44
+ ```
45
+
46
+ Hopefully this can be drop-in replacement for many app (e.g. memgpt) that requires function calling for open source llms.
47
+
48
+ # Result
49
+
50
+ ![img](./asset/fn_phi2.png)