added structured output for tools !

pull/938/head
harshalmore31 2 months ago
parent b873c35986
commit 1bad76b5d6

@ -1188,9 +1188,15 @@ class Agent:
f"[Structured Output] [Time: {time.strftime('%H:%M:%S')}] \n\n {json.dumps(response, indent=4)}", f"[Structured Output] [Time: {time.strftime('%H:%M:%S')}] \n\n {json.dumps(response, indent=4)}",
loop_count, loop_count,
) )
elif self.streaming_on: elif self.streaming_on and isinstance(response, dict) and response.get("choices"):
pass # Handle streaming tool calls structured output
else: tool_calls = response.get("choices", [{}])[0].get("message", {}).get("tool_calls", [])
if tool_calls:
self.pretty_print(
f"[Structured Output] [Time: {time.strftime('%H:%M:%S')}] \n\n {json.dumps(tool_calls, indent=4)}",
loop_count,
)
elif not self.streaming_on:
self.pretty_print( self.pretty_print(
response, loop_count response, loop_count
) )

@ -3109,6 +3109,7 @@ class BaseTool(BaseModel):
"id": tc.get("id") "id": tc.get("id")
}) })
return {"choices": [{"message": {"tool_calls": formatted_calls}}]} if formatted_calls else text_response return {"choices": [{"message": {"tool_calls": formatted_calls}}]} if formatted_calls else text_response
return text_response return text_response

Loading…
Cancel
Save