Skip to content

Improve MistralAiApi Jackson mapping for message content#5585

Draft
nicolaskrier wants to merge 1 commit intospring-projects:mainfrom
nicolaskrier:mistral-ai-api
Draft

Improve MistralAiApi Jackson mapping for message content#5585
nicolaskrier wants to merge 1 commit intospring-projects:mainfrom
nicolaskrier:mistral-ai-api

Conversation

@nicolaskrier
Copy link
Contributor

@nicolaskrier nicolaskrier commented Mar 10, 2026

Description

  • Define different type of chunk instead of media content,
  • Introduce think chunk required by Magistral models and Mistral Small 4,
  • Introduce prompt_mode request parameter for Magistral models,
  • Introduce reasoning_effort request parameter for Mistral Small 4,
  • Improve existing Javadoc,
  • Polish integration tests and unit tests.

Explanations

This PR aligns the Jackson mapping with the content types defined in the Mistral AI OpenAPI Specifications. The changes ensure null safety matches the OpenAPI Specifications requirements and introduce support for new content types used by Magistral 1.2 models. New Mistral Small 4 model reasoning on demand feature is also added in order to cover all Mistral reasoning models at MistralAiApi level.

Targeted milestone

2.0.0-M4

Related work

Remaining tasks

  • MistralAiApi.ChatCompletionMessage unit tests demonstrating content attribute serialization and deserialization,
  • MistralAiApi.ChatCompletionMessage.ContentSerializer unit tests,
  • MistralAiApi.ChatCompletionMessage.ContentDeserializer unit tests,
  • MistralAiApi.ChatCompletionMessage.extractContent unit tests,
  • MistralAiApi.ChatCompletionMessage.extractThinkingContent unit tests,
  • MistralAiApi prompt_mode parameter support indicating reasoning for Magistral models,
  • MistralAiApi reasoning_effort parameter support for Mistral Small 4,
  • MistralAiApi integration tests demonstrating Mistral Small 4 reasoning on demand feature,
  • MistralAiApi integration test including MistralAiApi.ChatCompletionMessage.ImageUrlChunk,
  • MistralAiApi integration test including MistralAiApi.ChatCompletionMessage.ReferenceChunk.

@nicolaskrier nicolaskrier force-pushed the mistral-ai-api branch 5 times, most recently from c8aa779 to 220088c Compare March 14, 2026 16:50
@sdeleuze sdeleuze self-assigned this Mar 16, 2026
@sdeleuze sdeleuze added enhancement New feature or request mistral labels Mar 16, 2026
@sdeleuze sdeleuze added this to the 2.0.0-M4 milestone Mar 16, 2026
@nicolaskrier nicolaskrier force-pushed the mistral-ai-api branch 6 times, most recently from 6563ab1 to 830333d Compare March 20, 2026 20:54
// "message":"A valid Content-Length header is required",
// "request_id":"5108031f4a1e0d3e6d66204d56b2ac60"
// }
// TODO: Discuss with Sébastien Deleuze the opportunity to add this class into Spring Framework if this solution is satisfying.
Copy link
Contributor Author

@nicolaskrier nicolaskrier Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @sdeleuze, could you have a look at this error and my corresponding fix proposal? Please note that this error is also affecting Spring AI 1.1.2. I have checked with my Spring AI Examples project that used to work well for all examples, except for the chat client example with Mistral AI, and now even the simplest example with Mistral AI API is broken due to this error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up: this error has been reported on Mistral AI Discord, so let's wait for their response.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum, the error doesn't occur anymore so I have removed the class.

@nicolaskrier nicolaskrier force-pushed the mistral-ai-api branch 5 times, most recently from c5c1c6c to 9a30eae Compare March 21, 2026 18:20
@nicolaskrier nicolaskrier changed the title Improve MistralAiApi Jackson mapping Improve MistralAiApi Jackson mapping for message content Mar 21, 2026
@nicolaskrier nicolaskrier force-pushed the mistral-ai-api branch 3 times, most recently from 7bf07e6 to 7ad3557 Compare March 22, 2026 23:19
- Define different type of chunk instead of media content
- Introduce think chunk required by Magistral models and Mistral Small 4
- Introduce prompt_mode request parameter for Magistral models
- Introduce reasoning_effort request parameter for Mistral Small 4
- Improve existing Javadoc
- Polish integration tests and unit tests

Signed-off-by: Nicolas Krier <7557886+nicolaskrier@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request mistral

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants