-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
When using Structured Outputs, only strings fields are marked as required #376
When using Structured Outputs, only strings fields are marked as required #376
Comments
Pretty sure I've already fixed this is #375 |
They recently updated how schemas work on the backend that started breaking existing implementation. |
Great! |
it's not an additional attribute, but part of the FunctionAttribute:
[Function(description: "blah blah")]
private void Function()
{
} |
Look at this example in the OpenAI documentation: Properties also contains descriptions to give more context. |
I'm well aware.
I've already fixed some of this recently just needs to get ported. Recently OpenAI updated their rules on this stuff and broke compatibility. I simply disabled If you provide your own schema definitions, then that is another story. |
FWIW if you're using .net 9, then there is a json schema generator that should be compliant: https://devblogs.microsoft.com/dotnet/system-text-json-in-dotnet-9/#json-schema-exporter |
Thank you for the response. So, is there currently any way to provide attributes with descriptions to obtain a structured outputs? |
see last comment about .net 9 json schema exporter. Likely I'll remove/deprecate the custom impl in this library once .net 8 EOL comes around. |
Finally I was able to add my own schema. I did it using the library Newtonsoft.Json.Schema. JSchemaGenerator generator = new()
{
DefaultRequired = Required.AllowNull,
GenerationProviders =
{
new StringEnumGenerationProvider(),
}
};
JSchema jSChema = generator.Generate(typeof(OpenAIStructuredOutput));
SetAdditionalPropertiesFalse(jSChema); // this method set AllowAdditionalProperties=false to all objects
var schema = jSChema.ToString();
var jsonSchema = new global::OpenAI.JsonSchema("OpenAIStructuredOutput", schema);
var chatRequest = new ChatRequest(
messages: messages,
model: MODEL_NAME,
temperature: TEMPERATURE,
responseFormat: ChatResponseFormat.JsonSchema,
jsonSchema: jsonSchema
);
ChatResponse chatResponse = Task.Run(async () => await OpenAIClient.ChatEndpoint.GetCompletionAsync(chatRequest)).Result;
var structuredOutput = JsonConvert.DeserializeObject<OpenAIStructuredOutput>(chatResponse.FirstChoice); |
Bug Report
Overview
When using Structured Outputs, only strings fields are marked as required. According to OpenAI documentation "all fields or function parameters must be specified as required".
When adding number or boolean fields, they are not marked as required and OpenAI API responds with an error.
Screenshots
Part of the input schema
Response from OpenAI:
The text was updated successfully, but these errors were encountered: