Spaces:
Sleeping
Sleeping
Update src/utils_fct.py
Browse filesChange function utils to return normal chat when no information on function calling is invoked
- src/utils_fct.py +17 -15
src/utils_fct.py
CHANGED
@@ -100,18 +100,20 @@ def forecast(messages
|
|
100 |
tools=model_predict_tool,
|
101 |
tool_choice="auto"
|
102 |
)
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
|
|
|
|
|
100 |
tools=model_predict_tool,
|
101 |
tool_choice="auto"
|
102 |
)
|
103 |
+
is_ok = True
|
104 |
+
try:
|
105 |
+
tool_call = response.choices[0].message.tool_calls[0]
|
106 |
+
function_name = tool_call.function.name
|
107 |
+
function_params = json.loads(tool_call.function.arguments)
|
108 |
+
function_result = names_to_functions[function_name](**function_params)
|
109 |
+
date = function_result["ds"][-1]
|
110 |
+
lower = function_result["yhat_lower"][-1]
|
111 |
+
upper = function_result["yhat_upper"][-1]
|
112 |
+
prediction = function_result["yhat"][-1]
|
113 |
+
except:
|
114 |
+
is_ok = False
|
115 |
+
pass
|
116 |
+
if is_ok:
|
117 |
+
return {"date" : str(date), "prix_minimum": lower, "prix_maximum": upper, "prix_estimé": prediction}
|
118 |
+
else:
|
119 |
+
return response.choices[0].message.content
|