-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Open
Description
Bug description
Content in OllamaApi.Message.thinking and OllamaApi.Message.toolName is lost in OllamaApiHelper.merge since these new attributes were missing in the merge-method in the PR adding them in the code base and in the issue backporting them to ver 1.0.2.
Environment
Spring AI: 1.0.2
Java: 21
Steps to reproduce
Create two OllamaApi.Message
objects with toolName
and thinking
having non-null values. Call OllamaApi.Message.merge(msg1, msg2)
. The method will return a new OllamaApi.Message
with both attributes set to null
.
Expected behavior
The content of the two fields should be retained and properly merged.
Minimal Complete Reproducible example
@Test
void testMessageMerge(){
var cr1 = new ChatResponse(null, null,
new Message(ASSISTANT, null, null, null, "not-null", "think 1"),
null, false, 0L, 0L, 0, 0L, 0, 0L);
var cr2 = new ChatResponse(null, null,
new Message(ASSISTANT, null, null, null, "not-null", " and think 2"),
null, false, 0L, 0L, 0, 0L, 0, 0L);
var expected = new ChatResponse(null, null,
new Message(ASSISTANT, null, null, null, "not-null", "think 1 and think 2"),
null, false, 0L, 0L, 0, 0L, 0, 0L);
var result = OllamaApiHelper.merge(cr1, cr2);
assertEquals(expected, result);
// org.opentest4j.AssertionFailedError: Merged chat response should combine message contents correctly ==>
// Expected :ChatResponse[model=null, createdAt=null, message=Message[role=ASSISTANT, content=null, images=null, toolCalls=null, toolName=not-null, thinking=think 1 and think 2], doneReason=null, done=false, totalDuration=0, loadDuration=0, promptEvalCount=0, pro ...
//
// Actual :ChatResponse[model=null, createdAt=null, message=Message[role=ASSISTANT, content=null, images=null, toolCalls=null, toolName=null, thinking=null], doneReason=null, done=false, totalDuration=0, loadDuration=0, promptEvalCount=0, promptEvalDuration=0, ...
}