-
Notifications
You must be signed in to change notification settings - Fork 2k
Description
Bug description
I'm using spring-ai along with local ollama. The OllamaChatModel's implementation doesn't consider external AbstractMessage implementation in method OllamaApi.ChatRequest ollamaChatRequest(Prompt prompt, boolean stream). There method body makes few class cast checks and then throws exception IllegalArgumentException with relevant message about unsupported message type. However, org.springframework.ai.chat.messages.AbstractMessage is open to extend and I can come up with my own independent implementation.
Environment
spring-ai:1.0.0
Steps to reproduce
Implement MyChatMemory with method like this
@Override
public List<Message> get(String conversationId) {
return List.of(new AbstractMessage(MessageType.ASSISTANT, "any text", Map.of()) {
});
}
Expose bean
@Bean
public ChatClient chatClient(ChatClient.Builder builder, MyChatMemory chatMemory) {
return builder.defaultAdvisors(MessageChatMemoryAdvisor.builder(chatMemory).build()).build();
}
Evoke using ChatClient
chatClient.prompt(prompt) //
.advisors(advisorSpec -> advisorSpec.param(ChatMemory.CONVERSATION_ID, id))
.stream() //
.chatResponse() //
.subscribe(response -> {
//process response
});
Expected behavior
The org.springframework.ai.ollama.OllamaChatModel#ollamaChatRequest doesn't throw exception
java.lang.IllegalArgumentException: Unsupported message type: ASSISTANT