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

Allow structured outputs via function calling #828

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

greysteil
Copy link
Contributor

@greysteil greysteil commented Aug 16, 2024

Describe the change

Allows strict: true to be passed to OpenAI within a function's definition, triggering OpenAI's new structured outputs setup to ensure the function's schema is strictly adhered to.

Provide OpenAI documentation link

https://openai.com/index/introducing-structured-outputs-in-the-api/

Describe your solution

Add Strict to the properties of FunctionDefinition. Only serialise it in the JSON if its value is true (to avoid wasting tokens).

Tests
Added a test.

Additional context
None

@greysteil
Copy link
Contributor Author

@sashabaranov the linting error on my first commit wasn't related to this PR. I've fixed it in the second commit since it was a trivial one.

Copy link

codecov bot commented Aug 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.00%. Comparing base (774fc9d) to head (76e5279).
Report is 41 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #828      +/-   ##
==========================================
+ Coverage   98.46%   99.00%   +0.54%     
==========================================
  Files          24       26       +2     
  Lines        1364     1410      +46     
==========================================
+ Hits         1343     1396      +53     
+ Misses         15        8       -7     
  Partials        6        6              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sashabaranov
Copy link
Owner

@greysteil thank you for the PR! Could you please fix the merge conflict and add an integration test — it's pretty hard to follow all the OpenAI API updates these days

@greysteil
Copy link
Contributor Author

@sashabaranov done!

@sashabaranov sashabaranov merged commit d86425a into sashabaranov:master Aug 16, 2024
3 checks passed
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