diff --git a/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java b/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java index de3460d31..87ac0e214 100644 --- a/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java +++ b/spring-ai-openai/src/main/java/org/springframework/ai/openai/api/OpenAiApi.java @@ -528,12 +528,63 @@ public class OpenAiApi { * @param finishReason The reason the model stopped generating tokens. * @param index The index of the choice in the list of choices. * @param delta A chat completion delta generated by streamed model responses. + * @param logprobs Log probability information for the choice. */ @JsonInclude(Include.NON_NULL) public record ChunkChoice( @JsonProperty("finish_reason") ChatCompletionFinishReason finishReason, @JsonProperty("index") Integer index, - @JsonProperty("delta") ChatCompletionMessage delta) { + @JsonProperty("delta") ChatCompletionMessage delta, + @JsonProperty("logprobs") LogProbs logprobs) { + } + + /** + * Log probability information for the choice. + * + * @param content A list of message content tokens with log probability information. + */ + @JsonInclude(Include.NON_NULL) + public record LogProbs( + @JsonProperty("content") List content) { + + /** + * Message content tokens with log probability information. + * + * @param token The token. + * @param logprob The log probability of the token. + * @param probBytes A list of integers representing the UTF-8 bytes representation + * of the token. Useful in instances where characters are represented by multiple + * tokens and their byte representations must be combined to generate the correct + * text representation. Can be null if there is no bytes representation for the token. + * @param topLogprobs List of the most likely tokens and their log probability, + * at this token position. In rare cases, there may be fewer than the number of + * requested top_logprobs returned. + */ + @JsonInclude(Include.NON_NULL) + public record Content( + @JsonProperty("token") String token, + @JsonProperty("logprob") Float logprob, + @JsonProperty("bytes") List probBytes, + @JsonProperty("top_logprobs") List topLogprobs + ) { + + /** + * The most likely tokens and their log probability, at this token position. + * + * @param token The token. + * @param logprob The log probability of the token. + * @param probBytes A list of integers representing the UTF-8 bytes representation + * of the token. Useful in instances where characters are represented by multiple + * tokens and their byte representations must be combined to generate the correct + * text representation. Can be null if there is no bytes representation for the token. + */ + @JsonInclude(Include.NON_NULL) + public record TopLogProbs( + @JsonProperty("token") String token, + @JsonProperty("logprob") Float logprob, + @JsonProperty("bytes") List probBytes) { + } + } } } diff --git a/spring-ai-vertex-ai/src/test/java/org/springframework/ai/vertex/api/VertexAiApiIT.java b/spring-ai-vertex-ai/src/test/java/org/springframework/ai/vertex/api/VertexAiApiIT.java index 533d810a4..44ec7c59c 100644 --- a/spring-ai-vertex-ai/src/test/java/org/springframework/ai/vertex/api/VertexAiApiIT.java +++ b/spring-ai-vertex-ai/src/test/java/org/springframework/ai/vertex/api/VertexAiApiIT.java @@ -119,7 +119,7 @@ public class VertexAiApiIT { System.out.println(model); assertThat(model).isNotNull(); - assertThat(model.displayName()).isEqualTo("Chat Bison"); + assertThat(model.displayName()).isEqualTo("PaLM 2 Chat (Legacy)"); } }