anasfik / openai

Dart/Flutter SDK for ChatGPT and all OpenAI APIs (GPT, Dall-e..)
https://pub.dev/packages/dart_openai
MIT License
593 stars 186 forks source link

fix: `/chat` body compatibility #178

Open lollipopkit opened 6 months ago

lollipopkit commented 6 months ago

As the OpenAI API ref, the body of /chat/completions can be:

{
  "model": "gpt-4o",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Hello!"
    }
  ]
}

In this example, the messages[0].content is String, not {"type": text, "content": ""}.

Some third-party API forward provider (such as deepseek) use this example struct as the only correct struct, without supporting the struct now implemented in this package.

I have made a change as follow: If messages[INDEX].content only has one child of type text, then the content will set as a string.

Thanks for your review. :)