G-T commited on
Commit
c9fb5b3
1 Parent(s): 0d993ab

Update src/utils_fct.py

Browse files

Change function utils to return normal chat when no information on function calling is invoked

Files changed (1) hide show
  1. 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
- tool_call = response.choices[0].message.tool_calls[0]
105
- function_name = tool_call.function.name
106
- function_params = json.loads(tool_call.function.arguments)
107
- function_result = names_to_functions[function_name](**function_params)
108
- date = function_result["ds"][-1]
109
- lower = function_result["yhat_lower"][-1]
110
- upper = function_result["yhat_upper"][-1]
111
- prediction = function_result["yhat"][-1]
112
-
113
- messages.append(ChatMessage(role="tool",
114
- name=function_name,
115
- content=str({"date" : date, "prix_minimum": lower, "prix_maximum": upper, "prix_estimé": prediction})
116
- ))
117
- return messages
 
 
 
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