You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use the structured response API from OpenAI but always get this error:
org.springframework.ai.retry.NonTransientAiException: 400 - {
"error": {
"message": "Invalid schema for response_format 'custom_schema': In context=(), 'required' is required to be supplied and to be an array including every key in properties. Missing 'customer_address'.",
"type": "invalid_request_error",
"param": "response_format",
"code": null
}
}
This the sample code:
Stringtext = "<text extracted from PDF invoice>";
StringuserPrompt = "Extract this invoice metadata in json format. The date fields need to be in \"yyyyMMddHHmmss\" format. " +
"The fields to extract are described in the provided json schema."StringfullPrompt = userPrompt + " : " + text;
BeanOutputConverter<?> outputConverter = newBeanOutputConverter<>(InvoiceMetadata.class);
Promptprompt = newPrompt(fullPrompt,
OpenAiChatOptions.builder()
.responseFormat(ResponseFormat.builder()
.type(ResponseFormat.Type.JSON_SCHEMA)
.jsonSchema(outputConverter.getJsonSchema())
.build())
.build());
ChatResponseresponse = chatModel.call(prompt);
returnresponse.getResult().getOutput().getText();
This is the bean used to get the structured data:
@JsonIgnoreProperties(ignoreUnknown = true)
public static class InvoiceMetadata {
public String invoice_number;
public String invoice_date;
public String invoice_amount;
public String customer_cif;
public String customer_name;
public String customer_address;
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to use the structured response API from OpenAI but always get this error:
This the sample code:
This is the bean used to get the structured data:
Beta Was this translation helpful? Give feedback.
All reactions