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

feat: Use structured outputs for more control over response #5195

Open
wants to merge 1 commit into
base: mealie-next
Choose a base branch
from

Conversation

dbz10
Copy link

@dbz10 dbz10 commented Mar 9, 2025

What this PR does / why we need it:

Hi,

This pull request leverages structured outputs to provide more granular control + guarantees over the responses from LLM providers. In a few of the usages in this project we expect a specific json object back. While mealie is already providing the expected json schema in the prompt this PR goes one step further and enforces that this schema is (allegedly) guaranteed to be respected in the response.

In theory this makes LLM calling more reliable and possibly makes prompting a bit more ergonomic in the future as well as pleading with LLMs to please for the love of all that is holy return json in the desired format or else my whole family will die should be less necessary.

Which issue(s) this PR fixes:

No specific related issue that I saw.

Special notes for your reviewer:

I tried to join the discord server but the invite was invalid. Happy to hear if I should have communicated prior to submitting this PR somewhere.

Testing

I ran unit test using task py:check in the devcontainer and got

1230 passed, 18 skipped, 153 warnings in 3069.26s (0:51:09)

I don't believe the tests actually executed any calls to OpenAI, especially since I didn't provide my API key, so I'm happy to take feedback or suggestions on additional testing I can do to validate this PR. I'm just getting started with mealie and don't have an extensive database of recipes nor URLs, etc, to test it on so would appreciate any suggestions how to go about that.

@michael-genson
Copy link
Collaborator

michael-genson commented Mar 13, 2025

Looks good! I will try to find some time this weekend to toy around with it and make sure it works as expected, but based on my understanding of how structured outputs works this should work great.

I don't believe the tests actually executed any calls to OpenAI

This is correct, we mock the call to OpenAI (since otherwise, as you said, you'd need to provide a key). I'll test manually with my key when I get the time (and welcome others to do the same!).

@michael-genson
Copy link
Collaborator

I tried to join the discord server but the invite was invalid

Where was the invalid invite? We should get that updated. Here's a new one: https://discord.gg/qA9zCWB5ay

@michael-genson michael-genson self-assigned this Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants