Find answers from the community

Updated 2 months ago

Is Strict = True Default For Structured Outputs For Function Calling With Openai (Ex. FunctionCallingProgram)?

At a glance

The community members are discussing the default behavior of the strict parameter in the OpenAI FunctionCallingProgram. The consensus is that strict=True is not the default, as it can have latency impacts and may not work with all pydantic classes. However, the community members note that strict=True can be set manually when using the OpenAI API. They also discuss issues with the FunctionCallingProgram where it may return an error (0 tool calls), but the regular response format from OpenAI works. The community members suggest that the structured output through function calling may be supported exclusively in the llamaindex library. They also ask about setting the system prompt for the FunctionCallingProgram, and a community member provides a solution using the ChatMessagePromptTemplate and setting the tool_choice parameter.

Hey all, is strict = True default for structured outputs for function calling with openai (ex. FunctionCallingProgram)?
L
D
8 comments
not at the moment (mostly because it has latency impacts, doesn't work with every pydantic class)
You can set it though
OpenAI(...., strict=True)
It will break for some pydantic classes though
since openai restricts it
I noticed that for some data models and prompts, when I tried to extract via FunctionCallingProgram I ran into an error (0 tool calls) but was able to get proper output using the response format (ie. not function calling) through openai - I'm assuming it's the structured output through function calling that is supported in llamaindex exclusively, correct? maybe if I set strict=True with the FunctionCallingProgram I will get the same output as calling OpenAI directly?
also, is there a simple way to set the system prompt for the FunctionCallingProgram? via chat_history or something else?
Pass in a ChatMessagePromptTemplate with your chat messages to FunctionCallingProgram

program(OutputCLS, prompt, arg1="val1", ...)

You can also set tool choice to force the function call

program(...., llm_kwargs={"tool_choice": "<class name>"})
Add a reply
Sign up and join the conversation on Discord