Closed KyleKun closed 7 months ago
Same issue here using the Create chat completion example https://github.com/anasfik/openai#create-chat-completion
After running on Android device get log messages;
Launching lib\main.dart on SM S901W in debug mode... Running Gradle task 'assembleDebug'... 94.2s √ Built build\app\outputs\flutter-apk\app-debug.apk. Installing build\app\outputs\flutter-apk\app-debug.apk... 8.8s I/flutter (29616): Error fetching OpenAI response: NoSuchMethodError: Class 'String' has no instance getter 'value'. I/flutter (29616): Receiver: "auto" I/flutter (29616): Tried calling: value
Edited to add: I commented out the toolChoice parameter and it successfully made the API call. Not sure what that is about but I'll take the win : )
// the actual request. OpenAIChatCompletionModel chatCompletion = await OpenAI.instance.chat.create( model: "gpt-3.5-turbo-1106", responseFormat: {"type": "json_object"}, seed: 6, messages: requestMessages, temperature: 0.2, maxTokens: 500, // toolChoice: "auto", );
it's because their docs are out of date. if you look at their source code
it shows that toolChoice is an object that has an attribute/getter of value which doesn't exist on a String.
Temporary workaround if you want to force a function call:
class _ToolChoice {
final dynamic value;
_ToolChoice(String functionName)
: value = {
"type": "function",
"function": {"name": "$functionName"}
};
}
Temporary workaround if you want to force a function call:
class _ToolChoice { final dynamic value; _ToolChoice(String functionName) : value = { "type": "function", "function": {"name": "$functionName"} }; }
This doesn't help much. Straight away you're getting another error:
Unhandled exception:
RequestFailedException(message: '$.messages[1].content' is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference., statusCode: 400)
#0 OpenAINetworkingClient.post (package:dart_openai/src/core/networking/client.dart:326:7)
<asynchronous suspension>
#1 OpenAIChat.create (package:dart_openai/src/instance/chat/chat.dart:87:12)
<asynchronous suspension>
Has this library been abandoned? It looks like there hasn't been any work on this library for two months, and nothing seems to work.
Has this library been abandoned? It looks like there hasn't been any work on this library for two months, and nothing seems to work.
You can use https://pub.dev/packages/openai_dart instead. It follows the official OpenAI OpenAPI spec, making it much easier to keep it up-to-date and preventing these kinds of issues.
same issue
This issue is resolved, let me know if there are any other issues.
Fortunately, this package is not abandoned as I do maintain it.
I am trying to create a chat completion following exactly the example and get this error:
Any ideas what it could be?