Skip to content
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

Add support for structured output in Ollama #1150

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

andreadimaio
Copy link
Collaborator

This PR enables the use of structured output with json_schema in Ollama.

My idea is to force the use of the structured output + json_schema every time an AIService returns a POJO and the developer doesn't fill the "format" property. In this second case, the value chosen by the developer will have the priority.

@andreadimaio andreadimaio requested a review from a team as a code owner December 11, 2024 22:18
Copy link

quarkus-bot bot commented Dec 11, 2024

Status for workflow Build (on pull request)

This is the status report for running Build (on pull request) on commit cead717.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Copy link
Collaborator

@geoand geoand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@geoand geoand merged commit d2a0f7e into quarkiverse:main Dec 12, 2024
64 checks passed
@andreadimaio
Copy link
Collaborator Author

I realize that I can improve the format checks a bit at build time, but before I start adding those checks, let me know what you think.

Today, the format property can take the value json or a json object that must conform to a json-schema {...}.

Suppose we have an AIService that returns a Person object and the format property has the value

  • null | empty: The json schema is automatically generated and used by quarkus.
  • json: The structured output is not used and the string "You must..." is appended to the prompt.
  • {...} (a manual json schema is provided. I don't know how often this can happen, but it could):
    • json-schema invalid: raises an exception.
    • json-schema matches the Person object: continue without exception.
    • json-schema doesn't match the Person object: throws an exception, or we have to use whatever the developer wrote?

What do you think about these checks.. do they make sense or I'll increase the lines of code without giving a value?

My doubt is what to do when the developer writes a correct json-schema in the format property?

@geoand
Copy link
Collaborator

geoand commented Dec 12, 2024

The way things are now with my initial commit, both the json_schema and the old You must... are captured at build time and available at runtime to the AiService implementation.

I believe that initially we should default to the latter for now, while allowing the users to opt-in to the new structured output (like the test I had added does). In the future we can flip that default.
To be honest, I don't see a scenario where the user writes the schema themselves.

@andreadimaio
Copy link
Collaborator Author

To be honest, I don't see a scenario where the user writes the schema themselves.

I think so too 👍 . Let's see if some future issues show us if other developers think differently.

@geoand
Copy link
Collaborator

geoand commented Dec 12, 2024

We'll find out soon enough :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants