|
1 | 1 | /*
|
2 |
| - * Copyright 2023-2024 the original author or authors. |
| 2 | + * Copyright 2023-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
112 | 112 | * @author Jihoon Kim
|
113 | 113 | * @author Ilayaperumal Gopinathan
|
114 | 114 | * @author Alexandros Pappas
|
| 115 | + * @author Berjan Jonker |
115 | 116 | * @see ChatModel
|
116 | 117 | * @see com.azure.ai.openai.OpenAIClient
|
117 | 118 | * @since 1.0.0
|
@@ -462,16 +463,19 @@ private Generation buildGeneration(ChatChoice choice, Map<String, Object> metada
|
462 | 463 |
|
463 | 464 | var responseMessage = Optional.ofNullable(choice.getMessage()).orElse(choice.getDelta());
|
464 | 465 |
|
465 |
| - List<AssistantMessage.ToolCall> toolCalls = responseMessage.getToolCalls() == null ? List.of() |
466 |
| - : responseMessage.getToolCalls().stream().map(toolCall -> { |
467 |
| - final var tc1 = (ChatCompletionsFunctionToolCall) toolCall; |
468 |
| - String id = tc1.getId(); |
469 |
| - String name = tc1.getFunction().getName(); |
470 |
| - String arguments = tc1.getFunction().getArguments(); |
471 |
| - return new AssistantMessage.ToolCall(id, "function", name, arguments); |
472 |
| - }).toList(); |
| 466 | + List<AssistantMessage.ToolCall> toolCalls = List.of(); |
| 467 | + if (responseMessage != null && responseMessage.getToolCalls() != null) { |
| 468 | + toolCalls = responseMessage.getToolCalls().stream().map(toolCall -> { |
| 469 | + final var tc1 = (ChatCompletionsFunctionToolCall) toolCall; |
| 470 | + String id = tc1.getId(); |
| 471 | + String name = tc1.getFunction().getName(); |
| 472 | + String arguments = tc1.getFunction().getArguments(); |
| 473 | + return new AssistantMessage.ToolCall(id, "function", name, arguments); |
| 474 | + }).toList(); |
| 475 | + } |
473 | 476 |
|
474 |
| - var assistantMessage = new AssistantMessage(responseMessage.getContent(), metadata, toolCalls); |
| 477 | + var content = responseMessage == null ? "" : responseMessage.getContent(); |
| 478 | + var assistantMessage = new AssistantMessage(content, metadata, toolCalls); |
475 | 479 | var generationMetadata = generateChoiceMetadata(choice);
|
476 | 480 |
|
477 | 481 | return new Generation(assistantMessage, generationMetadata);
|
|
0 commit comments