Skip to content

Conversation

@nicolaskrier
Copy link
Contributor

@nicolaskrier nicolaskrier commented Sep 7, 2025

Description

Providers like Azure OpenAI already support flexible conversion of Spring AI messages to provider-specific formats, enabling custom message types.
This PR adds the same capability for Mistral AI, introducing a dedicated conversion method to ensure consistency across the project.

Key Changes

  1. New Conversion Method

    • Added createChatCompletionMessages in MistralAiChatModel to map Spring AI Message objects to Mistral AI’s ChatCompletionMessage stream, based on MessageType.
    • Follows the established pattern in Azure OpenAI’s implementation.
  2. Unit Tests

    • Added comprehensive tests for the new conversion method, covering:
      • Standard Spring AI messages.
      • Custom message types.
    • Improved existing tests by:
      • Removing redundant @SpringBootTest annotation.
      • Addressing minor code smells.
      • Aligning test class name with project conventions.
  3. Backward Compatibility

    • No breaking changes: All existing unit and integration tests pass.

Related Work

This PR aligns with #3999, which implements a similar conversion mechanism for Ollama.
The goal is to standardize message handling across all LLM providers in Spring AI.

@nicolaskrier nicolaskrier force-pushed the create-request-refactor branch from d8ccc0c to e9d3c90 Compare September 7, 2025 23:04
@ilayaperumalg
Copy link
Member

@ricken07 Could you help with the review please? Thanks!

@ricken07
Copy link
Contributor

ricken07 commented Sep 8, 2025

@ilayaperumalg All right, no problem

@nicolaskrier
Copy link
Contributor Author

Thanks @ilayaperumalg and @ricken07 for your reviews!

I have updated the PR description to add more context and clarify the intent behind these changes.

@nicolaskrier nicolaskrier force-pushed the create-request-refactor branch 2 times, most recently from a77d1e5 to 3453239 Compare September 8, 2025 19:26
@nicolaskrier nicolaskrier force-pushed the create-request-refactor branch from 3453239 to 70a54fa Compare September 8, 2025 20:38
@nicolaskrier nicolaskrier changed the title Refactor request creation of Mistral AI chat model Use message type during request creation of Mistral AI chat model Sep 9, 2025
@nicolaskrier nicolaskrier changed the title Use message type during request creation of Mistral AI chat model Use message type during message creation of Mistral AI chat model Sep 9, 2025
@nicolaskrier
Copy link
Contributor Author

Hi @ilayaperumalg and @ricken07,

I wanted to apologize for the initial state of this PR. It clearly needed more work. I’ve incorporated as much of your review feedback as possible, and I believe the remaining points are now ready for discussion, especially with the updated PR description.
I’d love to hear your thoughts on both the current implementation and my expectations regarding the described behavior. Does this align with your vision for this feature?

Thanks for your time and guidance!

@nicolaskrier
Copy link
Contributor Author

Hi @ricken07 and @ilayaperumalg, I’ve addressed all the feedback from the last review. The changes are now ready for another look. Please let me know if everything looks good or if there’s anything else to adjust. Thanks again for your time!

@ilayaperumalg
Copy link
Member

@nicolaskrier Thanks for the PR and following up with the review comments. @ricken07 Thanks for reviewing the PR. LGTM, rebased, squashed and merged as f9d87fd

@nicolaskrier nicolaskrier deleted the create-request-refactor branch September 15, 2025 17:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants