64bit / async-openai

Rust library for OpenAI
https://docs.rs/async-openai
MIT License
1.09k stars 161 forks source link

Chat types - Manage empty string in finish_reason property #225

Closed ziggornif closed 3 months ago

ziggornif commented 3 months ago

This pull request allows to manage empty string in finish_reason property

I encountered this case with the OpenAI API of Ollama in version 1.35.

Before that the API returned a null value for this field.

Before :

{
  "id": "chatcmpl-351",
  "object": "chat.completion.chunk",
  "created": 1715436723,
  "model": "llama3",
  "system_fingerprint": "fp_ollama",
  "choices": [
    {
      "index": 0,
      "delta": {
        "role": "assistant",
        "content": "Je"
      },
      "finish_reason": null
    }
  ]
}

After :

{
  "id": "chatcmpl-351",
  "object": "chat.completion.chunk",
  "created": 1715436723,
  "model": "llama3",
  "system_fingerprint": "fp_ollama",
  "choices": [
    {
      "index": 0,
      "delta": {
        "role": "assistant",
        "content": "Je"
      },
      "finish_reason": ""
    }
  ]
}

I have not seen unit tests on the typing part of the library, if you ever accept the modification, tell me if I have to add some somewhere.

I tested the modification with the Ollama API in version 1.35 and 1.36, the PR solve the problem.

ziggornif commented 3 months ago

I close this PR, the issue will be solved in ollama project : https://github.com/ollama/ollama/issues/4357