Skip to content

Improve MistralAiApi Jackson mapping for message content#5585

Closed
nicolaskrier wants to merge 1 commit into
spring-projects:mainfrom
nicolaskrier:mistral-ai-api
Closed

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

Conversation

@nicolaskrier
Copy link
Copy Markdown
Contributor

@nicolaskrier nicolaskrier commented Mar 10, 2026

Description

  • Define different type of chunk instead of media content,
  • Verify that new chunks allow reasoning models support,
  • Introduce reasoning_effort request parameter for reasoning models,
  • Introduce reference_content, reference_thinking_content and thinking_content metadata in MistralAiChatModel,
  • Remove unnecessary null checks in MistralAiChatModel,
  • 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 reasoning on demand feature for Mistral Small 4 and Mistral Medium 3.5 models is also added in order to cover all Mistral reasoning models.

Proposed milestone

2.0.0-M6

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 reasoning_effort parameter support for Mistral Small 4 and Mistral Medium 3.5,
  • MistralAiChatOptions reasoning_effort parameter support,
  • MistralAiApi integration tests demonstrating Mistral Small 4 and Mistral Medium 3.5 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
@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 7 times, most recently from 6cd972a to 2dfbc35 Compare March 24, 2026 21:15
@nicolaskrier nicolaskrier marked this pull request as ready for review March 24, 2026 21:19
@ilayaperumalg ilayaperumalg added this to the 2.0.0-RC1 milestone May 8, 2026
@nicolaskrier nicolaskrier force-pushed the mistral-ai-api branch 4 times, most recently from ddc0909 to 7423a7e Compare May 14, 2026 15:32
@sdeleuze sdeleuze modified the milestones: 2.0.0-M7, 2.0.0-RC1 May 19, 2026
@nicolaskrier nicolaskrier force-pushed the mistral-ai-api branch 2 times, most recently from 1e8f523 to 0207947 Compare May 23, 2026 12:00
@nicolaskrier
Copy link
Copy Markdown
Contributor Author

Hi Sébastien,

I wanted to give you a quick heads-up here: I am currently reworking the solution. I have implemented four different methods at the MistralAiApi.ChatCompletionMessage level:

  • extractTextContent: currently used by MistralAiChatModel to fill the AssistantMessage content,
  • extractReferenceContent: not yet used but intended to be used by MistralAiChatModel to fill a dedicated reference entry in the AssistantMessage properties,
  • extractThinkingTextContent: not yet used but intended to be used by MistralAiChatModel to fill a dedicated thinking entry in the properties,
  • extractThinkingReferenceContent: not yet used but intended to be used by MistralAiChatModel to fill a dedicated thinking reference entry in the properties.

I plan to finish this by the end of the long weekend. Feel free to ping me if you think this approach is not suitable.

@nicolaskrier nicolaskrier force-pushed the mistral-ai-api branch 3 times, most recently from e702b7a to fc85886 Compare May 24, 2026 19:43
@sdeleuze
Copy link
Copy Markdown
Contributor

@nicolaskrier Is this PR ready for a new review?

@nicolaskrier
Copy link
Copy Markdown
Contributor Author

@sdeleuze: I am currently working on a last integration test verifying that reference content metadata is properly filled and then it will be over.

@nicolaskrier
Copy link
Copy Markdown
Contributor Author

nicolaskrier commented May 25, 2026

@sdeleuze: I have slightly modified the proposed solution to use a list of integers for the reference_content and reference_thinking_content metadata.

It is ready to be reviewed now.

@sdeleuze sdeleuze modified the milestones: 2.0.0-RC1, 2.0.0-M8 May 26, 2026
@nicolaskrier
Copy link
Copy Markdown
Contributor Author

@sdeleuze: I have resolved the conflicts with the recent changes introduced in #6135 and also slightly modified MistralAiStreamFunctionCallingHelper to use the raw content of the message instead of calling the extractTextContent method.

- Define different type of chunk instead of media content
- Verify that new chunks allow reasoning models support
- Introduce reasoning_effort request parameter for reasoning models
- Introduce reference_content, reference_thinking_content and thinking_content metadata in MistralAiChatModel
- Remove unnecessary null checks in MistralAiChatModel
- Improve existing Javadoc
- Polish integration tests and unit tests

Signed-off-by: Nicolas Krier <7557886+nicolaskrier@users.noreply.github.com>
@sdeleuze
Copy link
Copy Markdown
Contributor

Merged with additional documentation and configuration property, let's polish in RC1 if needed.

@nicolaskrier Does #5020 still make sense of should we close it?

@nicolaskrier
Copy link
Copy Markdown
Contributor Author

@sdeleuze: I think that you can close the other PR and the associated issue.

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.

3 participants