yhyu13 commited on
Commit
71384c6
1 Parent(s): 9846914
Files changed (2) hide show
  1. README.md +41 -1
  2. asset/fn_phi2-2.png +0 -0
README.md CHANGED
@@ -43,8 +43,32 @@ else:
43
  print("No match found.")
44
  ```
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  Hopefully, this model can be a drop-in replacement for apps (e.g. memgpt) that require function calling ability from LLMs.
47
 
 
 
 
 
 
 
 
 
48
  # Result
49
 
50
  Prompt:
@@ -53,4 +77,20 @@ Prompt:
53
  SYSTEM: You are a helpful assistant with access to the following functions. Use them if required -\n{\n \"name\": \"get_news_headlines\",\n \"description\": \"Get the latest news headlines\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"country\": {\n \"type\": \"string\",\n \"description\": \"The country for which to fetch news\"\n }\n },\n \"required\": [\n \"country\"\n ]\n }\n}\n\nWhat date is it today?"
54
  ```
55
 
56
- ![img](./asset/fn_phi2.png)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  print("No match found.")
44
  ```
45
 
46
+ 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.
47
+
48
+ ```
49
+ if match:
50
+ import ast
51
+ json_str = match.group(1)
52
+ json_str = json_str.strip()
53
+ """
54
+ https://www.datasciencebyexample.com/2023/03/16/what-to-do-when-single-quotes-in-json-string/
55
+ """
56
+ json_dict = ast.literal_eval(json_str)
57
+ print(json_dict['name'], json_dict['arguments'])
58
+ else:
59
+ print("No match found.")
60
+ ```
61
+
62
  Hopefully, this model can be a drop-in replacement for apps (e.g. memgpt) that require function calling ability from LLMs.
63
 
64
+ Another note on interpreting function call result:
65
+
66
+ 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.
67
+
68
+ ```
69
+ <functionresponse> jons_str </functionresponse>
70
+ ```
71
+
72
  # Result
73
 
74
  Prompt:
 
77
  SYSTEM: You are a helpful assistant with access to the following functions. Use them if required -\n{\n \"name\": \"get_news_headlines\",\n \"description\": \"Get the latest news headlines\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"country\": {\n \"type\": \"string\",\n \"description\": \"The country for which to fetch news\"\n }\n },\n \"required\": [\n \"country\"\n ]\n }\n}\n\nWhat date is it today?"
78
  ```
79
 
80
+ ![img](./asset/fn_phi2.png)
81
+
82
+
83
+ Prompt:
84
+
85
+ ```
86
+ SYSTEM: You are a helpful assistant with access to the following functions. Use them if required -\n{\n \"name\": \"calculate_median\",\n \"description\": \"Calculate the median of a list of numbers\",\n \"parameters\": {\n \"type\": \"object\",\n \"properties\": {\n \"numbers\": {\n \"type\": \"array\",\n \"items\": {\n \"type\": \"number\"\n },\n \"description\": \"A list of numbers\"\n }\n },\n \"required\": [\n \"numbers\"\n ]\n }\n}\n\nHi, I have a list of numbers and I need to find the median. Can you help me with that?
87
+ ```
88
+
89
+ Function response:
90
+
91
+ ```
92
+ <functionresponse> {"median": 5} </functionresponse>
93
+ ```
94
+
95
+ ![img](./asset/fn_phi2-2.png)
96
+
asset/fn_phi2-2.png ADDED