Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not parse ChatCompletionChunk when using streamChatCompletion #3

Closed
hntan opened this issue Mar 28, 2024 · 11 comments
Closed

Can not parse ChatCompletionChunk when using streamChatCompletion #3

hntan opened this issue Mar 28, 2024 · 11 comments

Comments

@hntan
Copy link

hntan commented Mar 28, 2024

I got this error.

Can not set final java.lang.String field io.github.stefanbratanov.jvm.openai.ChatCompletionChunk$Choice.finishReason to null value (through reference chain: io.github.stefanbratanov.jvm.openai.ChatCompletionChunk["choices"]->java.util.ArrayList[0])

Debug into the code

  <T> T deserializeResponse(byte[] response, Class<T> responseClass) {
    try {
      return objectMapper.readValue(response, responseClass);
    } catch (IOException ex) {
      throw new UncheckedIOException(ex);
    }
  }

I see the response is valid.

{
  "id": "chatcmpl-xyz",
  "object": "chat.completion.chunk",
  "created": 1711604346,
  "model": "gpt-4-0613",
  "system_fingerprint": null,
  "choices": [
    {
      "index": 0,
      "delta": {
        "role": "assistant",
        "content": ""
      },
      "logprobs": null,
      "finish_reason": null
    }
  ]
}
@StefanBratanov
Copy link
Owner

Hi, which version of the library do you use? I added a test to deserialize this json as part of 2308414 and it works.

@hntan
Copy link
Author

hntan commented Mar 28, 2024

Hi, which version of the library do you use? I added a test to deserialize this json as part of 2308414 and it works.

My application uses Jackson version 2.15.2

@StefanBratanov
Copy link
Owner

I tried downgrading to this version and it still works. Are you trying to deserialize it using your own ObjectMapper or just getting this error when using the library?

@hntan
Copy link
Author

hntan commented Mar 28, 2024

I tried downgrading to this version and it still works. Are you trying to deserialize it using your own ObjectMapper or just getting this error when using the library?

No, I'm not trying to use other custom ObjectMapper, I use the library directly in my application and got the error, it's kind of strange. (Of course our application has a custom ObjectMapper instance but the OpenAIClient uses it owns instance in ObjectMapperSingleton which uses PropertyNamingStrategies.SNAKE_CASE)

Screenshot 2024-03-28 at 18 00 02

@StefanBratanov
Copy link
Owner

Hmm yes, it is strange. I can't seem to be able to reproduce with the json that you provided. Just to confirm which Java version and OS do you use?

@hntan
Copy link
Author

hntan commented Mar 28, 2024

Hmm yes, it is strange. I can't seem to be able to reproduce with the json that you provided. Just to confirm which Java version and OS do you use?

Hi @StefanBratanov , My spring boot application uses java 17 and I use MacOs

@StefanBratanov
Copy link
Owner

Thank you. Will look into it and update here.

@hntan
Copy link
Author

hntan commented Mar 28, 2024

Hi @StefanBratanov , thanks for your assistance! I suspect the issue stems from conflicting Jackson library versions in my project. It's possible that version 2.15.2 isn't being used, and 2.13.3 is interfering. I rely on several other com.fasterxml.jackson.* libraries, so I'll investigate this further.

@StefanBratanov
Copy link
Owner

Thank you. Brings an interesting point because the Jackson scope in this library is implementation and not api so it is not classified as transitive dependency by Gradle and thus lower version of Jackson could be used. I may change this to api in next release to avoid this.

@StefanBratanov
Copy link
Owner

StefanBratanov commented May 6, 2024

Hi @hntan, I have decided to keep the implementation scope, since Jackson is only used internally and I wouldn't want the dependency to be transitively exposed to consumers in case they don't use Jackson. It is a trade-off essentially. Feel free to reopen the issue if you still have issues and I can think about a solution.

@StefanBratanov
Copy link
Owner

StefanBratanov commented May 8, 2024

Hi @hntan as part of https://github.com/StefanBratanov/jvm-openai/releases/tag/v0.9.1 release, I added a workaround which should fix your record deserialization problems if you still face them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants