[BUGS] Resolve reference in JSON schema for OCI Generative AI compatibility #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
with_structured_output(..., method="json_schema") fails when using Pydantic models containing Enums or nested models because OCI Generative AI API doesn't support JSON Schema $ref and $defs keywords.
Error:
See issue #65
Solutions
Testing
For Literal Pydantic data structure:
Input:
Output:
answer='The Statue of Liberty is a colossal neoclassical sculpture on Liberty Island in New York Harbor in New York City. The copper statue, a gift from the people of France to the people of the United States, was designed by French sculptor Frédéric Auguste Bartholdi and built by Gustave Eiffel. It was dedicated on October 28, 1886.' user_request='Tell me something about the statue of liberty' status=Status(status='done')For Enum Pydantic data structure:
Input:
Output:
answer='The Statue of Liberty was a gift from the people of France to the United States and was dedicated on October 28, 1886. It is a symbol of freedom and democracy.' user_request='Tell me something about the statue of liberty' domain=<Domain.HISTORICAL: 'HISTORICAL'>For nested reference Pydantic data structure:
Input:
Output:
message='Here are 3 colored objects.' items=[Item(name='Apple', color=<Color.RED: 'RED'>), Item(name='Sky', color=<Color.BLUE: 'BLUE'>), Item(name='Grass', color=<Color.GREEN: 'GREEN'>)]