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

Compatibility with Older APIs (with String content) #189

Open
EluvK opened this issue Aug 21, 2024 · 1 comment
Open

Compatibility with Older APIs (with String content) #189

EluvK opened this issue Aug 21, 2024 · 1 comment

Comments

@EluvK
Copy link

EluvK commented Aug 21, 2024

Description

In the recent update to the dart_openai library (version 5.0.0), the content field in the request body has been changed from String to List<Object>. While this change aligns with OpenAI's latest API updates, it causes compatibility issues with other large model APIs that still expect content to be a String.

Impact

This change prevents users from easily migrating to or using other large model APIs that follow the original OpenAI API format. As a result, users who rely on these APIs are facing difficulties in integrating with the updated dart_openai library. Specifically, the following error is encountered:

Failed to deserialize the JSON body into the target type: messages[1]: invalid type: sequence, expected a string at line 6 column 9

Suggested Solution

To maintain compatibility and ease of migration, I suggest the following:

  1. Provide an option to use either String field.
  2. Introduce a compatibility mode or a configuration setting that allows users to specify the format of the content field.

Example Code

Here is an example of how the library could support both formats: (something like this, I'm a newbie in Dart)

final dynamic content; // Can be either String or List<Object>

// When sending the request
if (content is List<Object>) {
  // Handle List<Object> format
} else if (content is String) {
  // Handle String format
}

This approach would ensure that users can continue to use the library with other large model APIs without any issues.

Additional Context

  • The latest version of dart_openai is 5.0.0.
  • The last version that used String was 4.1.2, and the commit.

I sinicerely hope you can consider this suggestion.

Thank you!

@franboladoruiz
Copy link

openai_dart supports both:

String:

ChatCompletionMessage.user(
  content: ChatCompletionUserMessageContent.string('Hello!'),
),

Or parts for multi-modal:

ChatCompletionMessage.user(
  content: ChatCompletionUserMessageContent.parts(
    [
      ChatCompletionMessageContentPart.text(
        text: 'What fruit is this?',
      ),
      ChatCompletionMessageContentPart.image(
        imageUrl: ChatCompletionMessageImageUrl(
          url: 'https://upload.wikimedia.org/wikipedia/commons/9/92/95apple.jpeg',
        ),
      ),
    ],
  ),
),

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