Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest.ResponseFormat;
import org.springframework.ai.mistralai.api.MistralAiApi.ChatCompletionRequest.ToolChoice;
import org.springframework.ai.mistralai.api.MistralAiApi.FunctionTool;
import org.springframework.ai.model.ModelOptionsUtils;
import org.springframework.ai.model.tool.StructuredOutputChatOptions;
import org.springframework.ai.model.tool.ToolCallingChatOptions;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.lang.Nullable;
Expand All @@ -49,7 +51,7 @@
* @since 0.8.1
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MistralAiChatOptions implements ToolCallingChatOptions {
public class MistralAiChatOptions implements ToolCallingChatOptions, StructuredOutputChatOptions {

/**
* ID of the model to use
Expand Down Expand Up @@ -367,6 +369,22 @@ public void setToolContext(Map<String, Object> toolContext) {
this.toolContext = toolContext;
}

@Override
@JsonIgnore
public String getOutputSchema() {
if (this.responseFormat == null || this.responseFormat.getJsonSchema() == null) {
return null;
}
return ModelOptionsUtils.toJsonString(this.responseFormat.getJsonSchema().getSchema());
}

@Override
@JsonIgnore
public void setOutputSchema(String outputSchema) {
this.setResponseFormat(
ResponseFormat.builder().type(ResponseFormat.Type.JSON_SCHEMA).jsonSchema(outputSchema).build());
}

@Override
@SuppressWarnings("unchecked")
public MistralAiChatOptions copy() {
Expand Down Expand Up @@ -518,6 +536,11 @@ public Builder toolContext(Map<String, Object> toolContext) {
return this;
}

public Builder outputSchema(String outputSchema) {
this.options.setOutputSchema(outputSchema);
return this;
}

public MistralAiChatOptions build() {
return this.options;
}
Expand Down
Loading