openai-java icon indicating copy to clipboard operation
openai-java copied to clipboard

ChatCompletionResult field name compliance issue

Open fhc1985 opened this issue 2 years ago • 1 comments

ChatCompletionResult.choices.ChatMessage is named to 'delta' in OpenAI's streaming response, not 'message' as the request does.

fhc1985 avatar Mar 11 '23 04:03 fhc1985

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);

fhc1985 avatar Mar 11 '23 05:03 fhc1985

This will be fixed in 0.12.0

TheoKanning avatar Apr 01 '23 18:04 TheoKanning

0.12.0 is live now :+1:

TheoKanning avatar Apr 01 '23 19:04 TheoKanning

Still not work in 0.14.0 with azure

qixiaobo avatar Jun 28 '23 02:06 qixiaobo

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)])

qixiaobo avatar Jun 28 '23 02:06 qixiaobo

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>

qixiaobo avatar Jun 28 '23 03:06 qixiaobo