committed by
Mark Pollack
parent
6e62ff7d83
commit
2090826656
@@ -211,13 +211,18 @@ public class OllamaChatModel extends AbstractToolCallSupport implements ChatMode
|
||||
|
||||
Flux<ChatResponse> chatResponse = ollamaResponse.map(chunk -> {
|
||||
String content = (chunk.message() != null) ? chunk.message().content() : "";
|
||||
List<AssistantMessage.ToolCall> toolCalls = chunk.message().toolCalls() == null ? List.of()
|
||||
: chunk.message()
|
||||
.toolCalls()
|
||||
.stream()
|
||||
.map(toolCall -> new AssistantMessage.ToolCall("", "function", toolCall.function().name(),
|
||||
ModelOptionsUtils.toJsonString(toolCall.function().arguments())))
|
||||
.toList();
|
||||
|
||||
List<AssistantMessage.ToolCall> toolCalls = List.of();
|
||||
|
||||
// Added null checks to prevent NPE when accessing tool calls
|
||||
if (chunk.message() != null && chunk.message().toolCalls() != null) {
|
||||
toolCalls = chunk.message()
|
||||
.toolCalls()
|
||||
.stream()
|
||||
.map(toolCall -> new AssistantMessage.ToolCall("", "function", toolCall.function().name(),
|
||||
ModelOptionsUtils.toJsonString(toolCall.function().arguments())))
|
||||
.toList();
|
||||
}
|
||||
|
||||
var assistantMessage = new AssistantMessage(content, Map.of(), toolCalls);
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
@SpringBootTest
|
||||
@Testcontainers
|
||||
@@ -67,6 +68,18 @@ class OllamaChatModelMultimodalIT extends BaseOllamaIT {
|
||||
@Autowired
|
||||
private OllamaChatModel chatModel;
|
||||
|
||||
@Test
|
||||
void unsupportedMediaType() throws IOException {
|
||||
|
||||
var imageData = new ClassPathResource("/norway.webp");
|
||||
|
||||
var userMessage = new UserMessage("Explain what do you see on this picture?",
|
||||
List.of(new Media(MimeTypeUtils.IMAGE_PNG, imageData)));
|
||||
|
||||
assertThrows(RuntimeException.class, () -> chatModel.call(new Prompt(List.of(userMessage))));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void multiModalityTest() throws IOException {
|
||||
|
||||
|
||||
BIN
models/spring-ai-ollama/src/test/resources/norway.webp
Normal file
BIN
models/spring-ai-ollama/src/test/resources/norway.webp
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 10 KiB |
Reference in New Issue
Block a user