Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MistralAiChatModel returns an error if MessageChatMemoryAdvisor is used #2380

Open
FabioAng71 opened this issue Mar 4, 2025 · 0 comments · May be fixed by #2541
Open

MistralAiChatModel returns an error if MessageChatMemoryAdvisor is used #2380

FabioAng71 opened this issue Mar 4, 2025 · 0 comments · May be fixed by #2541

Comments

@FabioAng71
Copy link

FabioAng71 commented Mar 4, 2025

Bug description
If I use MistralAiChatModel with MessageChatMemoryAdvisor + InMemoryChatMemory, at the second iteration, I get the following erorr:
Unexpected role 'system' after role 'assistant'

At the second iteration the system role appears after the previous user role and assistant role messages and before the current user role message.

"messages": [
    {
      "content": "first user message is here",
      "role": "user"
    },
    {
      "content": "first assistant message is here",
      "role": "assistant"
    },
    {
      "content": "   You are an assistant helping people to buy tickets for trains, give the answer with the same language of the request.\n   The answer must be formated as MarkDown.\n",
      "role": "system"
    },
    {
      "content": "currentuser message is here",
      "role": "user"
    }
  ]

Environment
Spring AI 1.0.0-M6, Java version 21

Steps to reproduce
add the following fragment to the pom.xml

        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-mistral-ai-spring-boot-starter</artifactId>
        </dependency>

use the following fragment of code

ChatClient.Builder builder
        chatClient = builder
                .defaultAdvisors(new MessageChatMemoryAdvisor(new InMemoryChatMemory()))
                .build();

Expected behavior
MistralAi LLM wants the system role to be the first one and this can be a general rule for all LLM.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant