-
Couldn't load subscription status.
- Fork 6.5k
feat: add OpenAI JSON Schema structured output support #18897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/base.py
Outdated
Show resolved
Hide resolved
1f693aa to
0c8a87f
Compare
|
@logan-markewich It seems that it is now ready to merge, I remove all the added program logic and keep the modification local to the base openAI class methods, also added some unit tests. Lmk what you think |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we actually need to import/use a private function? I thought the openai client let you directly pass in a pydantic object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah this is probably because we are using the chat api?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea, this is indeed because I'm using the chat and achat APIs.
I’m also not entirely comfortable with calling that _type_to_response_format function directly. It might be safer in the long run to extract that logic into our own utility function within the repo...
do you think that could be the best approach here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eh, I think this is fine for now. In a future PR we can extract out that logic into a util
llama-index-integrations/llms/llama-index-llms-openai/llama_index/llms/openai/base.py
Outdated
Show resolved
Hide resolved
|
@dbuos would the idea be for this to have an interface with FunctionCalling agents while being called during Workflows? |
|
@pazevedo-hyland this is kind of separate from function agents for now I do have an idea to add output class/structured responses to the FunctionAgent class though
From what I can see, openai does not let you mix |
17bb422 to
4227dee
Compare
|
@logan-markewich I just added support for the two streaming methods (sync and async) |
- Add JSON_SCHEMA mode to PydanticProgramMode enum - Create JsonSchemaProgram class using response_format API - Add automatic model detection for JSON schema support - Implement graceful fallback to function calling for unsupported models - Maintain full backward compatibility with existing APIs
Description
Overview
This PR implements support for OpenAI's native JSON Schema structured output capabilities while maintaining minimal architectural changes and leveraging the existing program pattern.
Approach
1. Minimal Integration Changes
structured_predict()andastructured_predict()methodsFixes # (issue)
New Package?
Did I fill in the
tool.llamahubsection in thepyproject.tomland provide a detailed README.md for my new integration or package?Version Bump?
Did I bump the version in the
pyproject.tomlfile of the package I am updating? (Except for thellama-index-corepackage)Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.
Suggested Checklist:
uv run make format; uv run make lintto appease the lint gods