Repository navigation
Conversation
nicolaskrier
left a comment
There was a problem hiding this comment.
Thanks for this PR! Adding the missing low and medium reasoning effort levels is a feature I have been looking forward to. I left a few review comments.
| void chatReasoningEffortProperty(String value, ReasoningEffort expected) { | ||
|
|
||
| new ApplicationContextRunner() | ||
| .withPropertyValues("spring.ai.mistralai.api-key=API_KEY", "spring.ai.mistralai.chat.model=mistral-large-4", |
There was a problem hiding this comment.
You could consider updating the value of MistralAiApi.ChatModel.MISTRAL_LARGE to mistral-large-4 and removing its deprecation.
There was a problem hiding this comment.
Good call, thanks! Updated MISTRAL_LARGE to mistral-large-4 and removed its deprecation. I also added a note to the 2.1.0 upgrade notes about the value change.
|
|
||
| @ParameterizedTest | ||
| @CsvSource({ "NONE, none", "LOW, low", "MEDIUM, medium", "HIGH, high" }) | ||
| void testJsonSerializationOfReasoningEffort(ReasoningEffort reasoningEffort, String value) { |
There was a problem hiding this comment.
Could you have a look at ThinkingModelSource and ThinkingModelUtils? They are used in the following IT classes:
MistralAiApiIT,MistralAiChatModelIT.
It would be great if you could add MISTRAL_LARGE and one of the new reasoning efforts associated with it, maybe LOW to get faster responses.
There was a problem hiding this comment.
Done. MISTRAL_LARGE is now included in ThinkingModelSource / ThinkingModelUtils with LOW reasoning effort (Small and Medium stay on HIGH).
One caveat: I don't have a Mistral API key locally, so I couldn't run the ITs. thinkingCall / thinkingStream and two tests in MistralAiApiIT assert that thinking content is returned. If Large with LOW turns out not to return thinking, switching it to MEDIUM should fix that. Happy to adjust.
| * {@link ReasoningEffort#HIGH} enables comprehensive reasoning traces, | ||
| * {@link ReasoningEffort#NONE} disables reasoning effort. | ||
| * Controls the reasoning effort level for adjustable reasoning models. The | ||
| * accepted levels depend on the model: Mistral Small 4 and Mistral Medium 3.5 |
There was a problem hiding this comment.
I wonder if we should describe the supported reasoning effort levels per model here. That would have to be maintained over time, whereas simply referring to Mistral AI's documentation might be enough.
There was a problem hiding this comment.
Agreed, that would be hard to keep in sync. The ReasoningEffort Javadoc and mistralai-chat.adoc now link to the Mistral AI reasoning docs instead of listing levels per model.
ab058e7 to
00b9d35
Compare
00b9d35 to
eca652e
Compare
Mistral Large 4 accepts the low, medium and high reasoning effort levels, but ReasoningEffort only defined HIGH and NONE, so setting spring.ai.mistralai.chat.reasoning-effort to low or medium failed at property binding. Add LOW and MEDIUM, document which levels each model accepts, and cover binding and JSON serialization with tests. Fixes spring-projects#7312 Signed-off-by: Ajax-1 <85230126+Ajax-1@users.noreply.github.com>
Point ChatModel.MISTRAL_LARGE at mistral-large-4 and drop its deprecation, cover that model in the reasoning tests at LOW effort, and refer readers to the Mistral documentation for supported levels. Signed-off-by: Ajax-1 <85230126+Ajax-1@users.noreply.github.com>
eca652e to
db14095
Compare
Description
MistralAiApi.ChatCompletionRequest.ReasoningEffortonly hadHIGHandNONE. Mistral Large 4 acceptslow,mediumandhighand rejectsnone, so it could not be used with a lower reasoning level:spring.ai.mistralai.chat.reasoning-effort=low(ormedium) failed at property binding, and theMistralAiChatOptionsbuilder had no constant for these levels either.This adds
LOWandMEDIUM, serialized as"low"and"medium".HIGHandNONEstay as they are, so Mistral Small 4 and Mistral Medium 3.5 are unaffected.Fixes #7312
Changes
MistralAiApi: addReasoningEffort.LOWandReasoningEffort.MEDIUM, list the constants from lowest to highest, and say in the Javadoc which levels each model accepts, with a link to the Mistral reasoning docs.MistralAiChatOptions: point the field Javadoc atReasoningEffortinstead of listing onlyHIGH/NONE.mistralai-chat.adoc: list all four values forspring.ai.mistralai.chat.reasoning-effort, add Mistral Large 4 to the adjustable reasoning models, and add a short note on which levels each model accepts.MistralAiPropertiesTests:reasoning-effortset tonone/low/medium/highbinds to the matching constant and reachestoOptions()(this is the startup failure from the issue).MistralAiChatOptionsTests: every constant serializes to its lowercase API value and deserializes back.Notes
none | minimal | low | medium | high | xhighforreasoning_effort, but the reasoning docs don't name a current Mistral model that acceptsminimalorxhigh. I kept this PR to the levels from the issue; happy to add the other two if you'd rather mirror the full API enum.MistralAiApi.ChatModelhas no Mistral Large 4 constant (MISTRAL_LARGEpoints to the deprecatedmistral-large-latest). I left that out of this PR since the model can be set by name.Testing
./mvnw -pl models/spring-ai-mistral-ai,auto-configurations/models/spring-ai-autoconfigure-model-mistral-ai test: 128 tests inspring-ai-mistral-aiand 16 in the auto-configuration module, 0 failures, 0 errors (2 skipped inMistralAiRetryTests, unrelated).main, theLOWandMEDIUMcases of both new tests fail (No enum constant ...ReasoningEffort.LOW/MEDIUM); they pass with this change.spring-javaformat:validatepasses and checkstyle reports 0 violations on both modules.*IT) were not run, as they need a Mistral API key.