From 15783f505f2c7ef44afa9e04a7729a29b1e120b5 Mon Sep 17 00:00:00 2001 From: samuel-taleez Date: Tue, 11 Feb 2025 10:56:38 +0100 Subject: [PATCH] feat(mistral-schema): allow custom structured output with json schema Signed-off-by: krsamuel --- .../ai/mistralai/api/MistralAiApi.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java index 6b9e23d22b..cd068e2aa5 100644 --- a/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java +++ b/models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java @@ -633,9 +633,11 @@ public record EmbeddingList( * @param stop A list of tokens that the model should stop generating after. If set, * @param randomSeed The seed to use for random sampling. If set, different calls will * generate deterministic results. - * @param responseFormat An object specifying the format that the model must output. - * Setting to { "type": "json_object" } enables JSON mode, which guarantees the - * message the model generates is valid JSON. + * @param responseFormat An object specifying the format or schema that the model must + * output. Setting to { "type": "json_object" } enables JSON mode, which guarantees + * the message the model generates is valid JSON. Setting to { "type": "json_object" , + * "json_schema": schema} allows you to ensure the model provides an answer in a very + * specific JSON format by supplying a clear JSON schema. */ @JsonInclude(Include.NON_NULL) public record ChatCompletionRequest( @@ -738,11 +740,12 @@ public enum ToolChoice { * An object specifying the format that the model must output. * * @param type Must be one of 'text' or 'json_object'. + * @param jsonSchema A specific JSON schema to match, if 'type' is 'json_object'. */ @JsonInclude(Include.NON_NULL) - public record ResponseFormat(@JsonProperty("type") String type) { + public record ResponseFormat(@JsonProperty("type") String type, + @JsonProperty("json_schema") Map jsonSchema) { - } }