-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 SchemaRaw
option for strict json response format
#824
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #824 +/- ##
==========================================
+ Coverage 98.46% 99.02% +0.56%
==========================================
Files 24 26 +2
Lines 1364 1432 +68
==========================================
+ Hits 1343 1418 +75
+ Misses 15 8 -7
Partials 6 6 ☔ View full report in Codecov by Sentry. |
JSONSchemaRaw
option for strict json response formatSchemaRaw
option for strict json response format
03b6379
to
03508ae
Compare
Good on you for submitting this change, this is exactly what I need to proceed with my POC. |
@monstercameron @h0rv can you review this comment as an alternative to adding a |
+1 |
Hey all, we've just merged #819 with Schema improvements — please let me know if it works for you! |
@sashabaranov I am trying to test with
Any reason maps aren't supported? I am using a struct to JSON Schema library which has some mapped fields like this and its not in the actual struct. It looks like structs are mapping to JSON Objects, and I think maps should be mapped to a JSON Object too. |
EDIT: just use As an alternative, if you already have your schema in a string and want to avoid having to transform it to a
That was from the hip so you may need to fix as needed but you get the idea. |
When converting map types to JSON Schema, the main challenges are:
You can directly use |
Thanks the replies - I will try using the the string schema directly. |
Oh nice, I was not aware of that gem. This is much better than implementing your own as I suggested above. Thanks for calling this out! Perhaps it should go in the documentation... |
Awesome - was able to get it working and add support for strict mode with instructor. Just added the feature in the latest release. |
I'm going to close this as its not required with the last PR. Thanks for the help everyone! |
Describe the change
Added the ability to pass a raw JSON Schema (
[]byte
) to ResponseFormat for strict mode (structured output).This is done to be more dynamic with the JSON schema, as there is many features that are there and may be added to the API that would be out of scope for this client to support. For example: https://platform.openai.com/docs/guides/structured-outputs/definitions-are-supported.
These JSON spec features are provided by other Go libraries, and would not make sense to add to this client (unless wanting to add a json schema package it as a dependency).
Provide OpenAI documentation link
https://platform.openai.com/docs/guides/structured-outputs/definitions-are-supported
Describe your solution
I added a solution to pass in a raw JSON schema and overrode the marshalling method to be compatibile with the existing way and support this way while blocking it if the struct and raw schema are both defined.
Tests
I added an integration test to pass the raw JSON schema throught the new field.
Issue: #814