phidata icon indicating copy to clipboard operation
phidata copied to clipboard

Made changes to support structured output from OpenAI models along with tools calling

Open gauravdhiman opened this issue 3 months ago • 0 comments

All this is in context of OpenAI models. Because of big test run logs, I am putting them in pastebin and linking them here, else this description becomes too big and github does not allow too big descriptions.

Details:

As of now structured output works, but only in case if agent is not given any tools. If we give tools to an agent and also expect it to give structured output, it fails with below error: https://pastebin.com/Ckgi1YCU

Here is the test script: https://pastebin.com/72SgZ00j

When either tools are not provided or below two arguments are not passed (or commented) in call to Agent(), the test pass without any issues.

    structured_outputs=True,
    response_model=ResponseObj,

As from error, we can see that OpenAI expects functions to be marked as "strict": True when structured output is enabled. This diff is to make that change. With this diff now tools along with structured output can be used.

Here is the test run for tools with structured output: https://pastebin.com/xFYcfV8M

Here is the test run for tools without structured output (as markdown): https://pastebin.com/rEwcgrBA

gauravdhiman avatar Oct 28 '24 21:10 gauravdhiman