Hello, I’m trying to use Assistant API in Flutter.
Below me is the code for the Chatcompletion I want. I first had a message interruption because of the time was the short. That’s why I tried to change connectionTimeOut to a minute. But I still get an error that it wont work. Visible under the code.
import 'package:chat_gpt_sdk/chat_gpt_sdk.dart';
Future<void> getChatCompletion() async {
const String token = 'API-KEY';
final openAI = OpenAI.instance.build(
token: token,
baseOption: HttpSetup(
receiveTimeout: const Duration(seconds: 5),
connectTimeout: const Duration(seconds: 60)),
enableLog: true);
const String assistantId = "ASSISTANT-ID";
final request = CreateThreadAndRun(assistantId: assistantId, thread: {
"messages": [
{"role": "user", "content": "$_linesText"}
],
});
// Create the thread and run
final response =
await openAI.threads.runs.createThreadAndRun(request: request);
// Extract threadId from the response
final threadId = response.threadId;
// Retrieve messages
final mMessage = await openAI.threads.messages.retrieveMessage(
threadId: threadId,
messageId: '',
);
print("Response: ${mMessage.content[0].text?.value}");
}
[OpenAI] starting request https://api.openai.com/v1/threads/runs
[OpenAI] request body :{assistant_id: asst_k66DjzXXXXXXXmqJTbe3, thread: {messages: [{role: user, content: [VUILZAK GROEN 50L, 20 MARLBORO RED, 20 MARLBORO RED, B.MASSARD BRUT, SUPER PAPRIKA LAYS, 4X20CLFEVERTREEMED, 10M DDL BAKPAPIER, 10C MANO PUISS BIO, 180G TONY CHOCOLAD, 6X1.5L COKE ZER0]}]}}
E/flutter (22020): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: status code :500 message :{message: null, code: null, type: null}
E/flutter (22020):
E/flutter (22020): #0 OpenAIClient.post (package:chat_gpt_sdk/src/client/openai_client.dart:229:7)
E/flutter (22020): <asynchronous suspension>
E/flutter (22020): #1 _ScannerState.getChatCompletion (package:smartberging/pages/Scanner.dart:334:9)
E/flutter (22020): <asynchronous suspension>
E/flutter (22020):
[OpenAI] error code: null, message :The connection errored: Failed host lookup: 'api.openai.com' This indicates an error which most likely cannot be solved by the library. data:null