Skip to content

Conversation

sion-codin
Copy link
Contributor

when use a deactivated account's api key to createStream

    final chatStream = OpenAI.instance.chat.createStream(
      model: "gpt-3.5-turbo",
      temperature: temperature,
      messages: messages,
    );

openai backend will return:

{
    "message":"",
    "type":"invalid_request_error",
    "param":null,
    "code":"account_deactivated"
}

Note: the message is empty.

in this lib, RequestFailedException.message will empty, the developer can only obtain the network request status code :

                if (doesErrorExists(decodedData)) {
                  final error = decodedData[OpenAIStrings.errorFieldKey]
                      as Map<String, dynamic>;
                  final message = error[OpenAIStrings.messageFieldKey];
                  final statusCode = respond.statusCode;
                  final exception = RequestFailedException(message, statusCode);

                  controller.addError(exception);
                }

This PR does the following:

final message = error[OpenAIStrings.messageFieldKey];

change to

final message = jsonEncode(error);

@anasfik
Copy link
Owner

anasfik commented May 21, 2023

Thank you for this notice, and yes this is helpful for the developer but is also a breaking change, can we make a conditional expression to check whether the message field is empty or not, if yes then we apply your implementation, otherwise we return directly that message field.

What do you think?

@sion-codin
Copy link
Contributor Author

I am a PR novice 😂.If there is anything incorrect here, please guide me. thanks

@anasfik
Copy link
Owner

anasfik commented May 29, 2023

Thank you

@anasfik anasfik merged commit 11201a1 into anasfik:main May 29, 2023
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

Successfully merging this pull request may close these issues.

2 participants