Skip to content

Commit fbd03b7

Browse files
krsamueltzolov
authored andcommitted
feat(mistral-schema): allow custom structured output with json schema (#2211)
Signed-off-by: krsamuel <[email protected]>
1 parent 5127662 commit fbd03b7

File tree

1 file changed

+11
-11
lines changed
  • models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api

1 file changed

+11
-11
lines changed

Diff for: models/spring-ai-mistral-ai/src/main/java/org/springframework/ai/mistralai/api/MistralAiApi.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,11 @@ public record EmbeddingList<T>(
627627
* @param stop A list of tokens that the model should stop generating after. If set,
628628
* @param randomSeed The seed to use for random sampling. If set, different calls will
629629
* generate deterministic results.
630-
* @param responseFormat An object specifying the format that the model must output.
631-
* Setting to { "type": "json_object" } enables JSON mode, which guarantees the
632-
* message the model generates is valid JSON.
630+
* @param responseFormat An object specifying the format or schema that the model must
631+
* output. Setting to { "type": "json_object" } enables JSON mode, which guarantees
632+
* the message the model generates is valid JSON. Setting to { "type": "json_object" ,
633+
* "json_schema": schema} allows you to ensure the model provides an answer in a very
634+
* specific JSON format by supplying a clear JSON schema.
633635
*/
634636
@JsonInclude(Include.NON_NULL)
635637
public record ChatCompletionRequest(
@@ -718,12 +720,9 @@ public ChatCompletionRequest(List<ChatCompletionMessage> messages, Boolean strea
718720
public enum ToolChoice {
719721

720722
// @formatter:off
721-
@JsonProperty("auto")
722-
AUTO,
723-
@JsonProperty("any")
724-
ANY,
725-
@JsonProperty("none")
726-
NONE
723+
@JsonProperty("auto") AUTO,
724+
@JsonProperty("any") ANY,
725+
@JsonProperty("none") NONE
727726
// @formatter:on
728727

729728
}
@@ -732,10 +731,11 @@ public enum ToolChoice {
732731
* An object specifying the format that the model must output.
733732
*
734733
* @param type Must be one of 'text' or 'json_object'.
734+
* @param jsonSchema A specific JSON schema to match, if 'type' is 'json_object'.
735735
*/
736736
@JsonInclude(Include.NON_NULL)
737-
public record ResponseFormat(@JsonProperty("type") String type) {
738-
737+
public record ResponseFormat(@JsonProperty("type") String type,
738+
@JsonProperty("json_schema") Map<String, Object> jsonSchema) {
739739
}
740740

741741
}

0 commit comments

Comments
 (0)