TimeoutException after 0:00:30.000000: Future not completed
jelleheijne1997 opened this issue · 4 comments
jelleheijne1997 commented
I am trying to run a chat completion with a tool. However, I get this error: TimeoutException after 0:00:30.000000: Future not completed. Even when I specify a longer timeout. Does anyone know why this is happening and how I fix it? It only happens sometimes. This is my code:
Future<Map<String, dynamic>> createWorkoutJson(messages) async {
try {
print('Sending request to OpenAI...');
OpenAIChatCompletionModel completion = await OpenAI.instance.chat
.create(
model: 'gpt-4-1106-preview',
messages: messages,
temperature: 0.7,
tools: [
get_function(training_days!.length, durations),
],
).timeout(
const Duration(seconds: 120)); // Set the timeout to 90 seconds
print('OpenAI request completed.');
final params = completion.choices[0].message.toolCalls![0].function
.arguments as Map<String, dynamic>;
print(params);
print(params.runtimeType);
return params;
} on TimeoutException catch (e) {
// Handle the timeout exception
print('Request timed out: $e');
// You can return an empty map, throw the exception, or handle it as needed
return {}; // Or handle it as per your application's needs
} catch (e) {
// Handle other exceptions
print('An error occurred: $e');
// Handle the exception appropriately
return {}; // Or handle it as per your application's needs
}
}
djbird2046 commented
same problem
lilmistake commented
The default timeout duration is set to 30 seconds. You can overwrite it like this:
OpenAI.requestsTimeOut = const Duration(seconds: 600);
djbird2046 commented
same problem
fixed.
My Problem is IDEA proxy. Added http_proxy=http://localhost:7890
and https_proxy=http://localhost:7890
(my proxy port is 7890)to Edit Configurations
-> Environment variables
.
now OK
anasfik commented
@lilmistake thanks for mentioning that.
closed.