Handle OpenAiChatModel NPE for partially compatible OpneAI API such as the NVIDIA API

This commit is contained in:
Christian Tzolov
2024-07-03 16:14:35 +02:00
parent 4ff2f1fc06
commit f171b0fa5e

View File

@@ -162,8 +162,13 @@ public class OpenAiChatModel extends
}
List<Generation> generations = choices.stream().map(choice -> {
return new Generation(choice.message().content(), toMap(chatCompletion.id(), choice))
.withGenerationMetadata(ChatGenerationMetadata.from(choice.finishReason().name(), null));
var generation = new Generation(choice.message().content(), toMap(chatCompletion.id(), choice));
if (choice.finishReason() != null) {
generation = generation
.withGenerationMetadata(ChatGenerationMetadata.from(choice.finishReason().name(), null));
}
return generation;
}).toList();
return new ChatResponse(generations,