File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -142,6 +142,23 @@ def modified_create_chat_completion(*args, **kwargs) -> str:
142142
143143 # Try to add step to the trace
144144 try :
145+ output_content = response .choices [0 ].message .content
146+ output_function_call = response .choices [0 ].message .function_call
147+ output_tool_calls = response .choices [0 ].message .tool_calls
148+ if output_content :
149+ output_data = output_content .strip ()
150+ elif output_function_call or output_tool_calls :
151+ if output_function_call :
152+ function_call = dict (output_function_call )
153+ else :
154+ function_call = dict (output_tool_calls [0 ].function )
155+ metadata = {
156+ "function_call_name" : function_call .get ("name" ),
157+ "function_call_arguments" : function_call .get ("arguments" ),
158+ }
159+ output_data = str (function_call )
160+ else :
161+ output_data = None
145162 output_data = response .choices [0 ].message .content
146163 cost = self .get_cost_estimate (
147164 model = kwargs .get ("model" ),
@@ -164,6 +181,7 @@ def modified_create_chat_completion(*args, **kwargs) -> str:
164181 model_parameters = kwargs .get ("model_parameters" ),
165182 raw_output = response .model_dump (),
166183 provider = "OpenAI" ,
184+ metadata = metadata ,
167185 )
168186 # pylint: disable=broad-except
169187 except Exception as e :
You can’t perform that action at this time.
0 commit comments