v1.0.13 openai chat completion

This commit is contained in:
Tibor Bossanyi
2023-03-12 21:48:03 +01:00
parent f34a57e931
commit bed94e572e
7 changed files with 153 additions and 32 deletions
+18 -5
View File
@@ -2,10 +2,10 @@ import 'dart:async';
import 'dart:convert';
import 'package:workouttest_util/model/openai.dart';
import 'package:workouttest_util/model/openai_chat.dart';
import 'package:workouttest_util/service/api.dart';
import 'package:workouttest_util/util/logging.dart';
class OpenAIApi with Logging {
final APIClient _client = APIClient();
@@ -13,12 +13,12 @@ class OpenAIApi with Logging {
String? response;
try {
final body = await _client.post("openai/completion", question);
response = body;
response = body;
} on TimeoutException catch (_) {
log("Timeout from OpenAI");
} on Exception catch (e) {
log(e.toString());
}
}
return response ?? "";
}
@@ -31,7 +31,20 @@ class OpenAIApi with Logging {
log("Timeout from OpenAI");
} on Exception catch (e) {
log(e.toString());
}
}
return response ?? "";
}
}
Future<String> getOpenAIChatCompletion(OpenAIChat openai) async {
String? response;
try {
String body = const JsonEncoder().convert(openai.toJson());
response = await _client.post("openai/chat_completion", body);
} on TimeoutException catch (_) {
log("Timeout from OpenAI");
} on Exception catch (e) {
log(e.toString());
}
return response ?? "";
}
}