ChatCompletionResult field name compliance issue
ChatCompletionResult.choices.ChatMessage is named to 'delta' in OpenAI's streaming response, not 'message' as the request does.
we can use ObjectMapper's mixin to solve this problem, but expecting one official solution. thanks. The sample code is: // First, define one mixin class class ChatCompletionChoiceMixIn { @JsonProperty("message") @JsonAlias(value = {"delta"}) ChatMessage message; }
// And then mix in it into the ChatCompletionChoice class. ObjectMapper mapper = new ObjectMapper(); ... mapper.addMixIn(ChatCompletionChoice.class, ChatCompletionChoiceMixIn.class);
This will be fixed in 0.12.0
0.12.0 is live now :+1:
Still not work in 0.14.0 with azure
Still not work in 0.14.0 with azure {"id":"chatcmpl-7WFFdZ6QGiK1jOLJTlQzBAz7XO5AX","object":"chat.completion.chunk","created":1687919477,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"奔"}}],"usage":null}
ChatCompletionChunk(id=chatcmpl-7WFFdZ6QGiK1jOLJTlQzBAz7XO5AX, object=chat.completion.chunk, created=1687919477, model=gpt-35-turbo, choices=[ChatCompletionChoice(index=0, message=null, finishReason=null)])
Still not work in 0.14.0 with azure {"id":"chatcmpl-7WFFdZ6QGiK1jOLJTlQzBAz7XO5AX","object":"chat.completion.chunk","created":1687919477,"model":"gpt-35-turbo","choices":[{"index":0,"finish_reason":null,"delta":{"content":"奔"}}],"usage":null}
ChatCompletionChunk(id=chatcmpl-7WFFdZ6QGiK1jOLJTlQzBAz7XO5AX, object=chat.completion.chunk, created=1687919477, model=gpt-35-turbo, choices=[ChatCompletionChoice(index=0, message=null, finishReason=null)])
Sorry for this , I found because I use springboot 1.5.10 release , this version provide jackson 2.8.0 version. So we should use version larger than 2.9.0 because jsonAlias was introudeced in 2.9.0 。 I just need to add this in pom.xml
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.2</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.14.2</version>
</dependency>