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
+15 -7
View File
@@ -119,6 +119,8 @@ class Cache with Logging {
static String baseUrlLive = 'https://api.workouttest.org/api/';
static String baseUrlTest = 'https://apitest.workouttest.org/api/';
static String baseUrlDiet = 'https://api.diet4you.eu/api/';
static String baseUrlDietTest = 'https://apitest.diet4you.eu/api/';
static String baseUrlLocal = 'http://localhost:8443/api/';
late String baseUrl;
static const String mediaUrl = 'https://admin.workouttest.org/media/';
@@ -200,7 +202,7 @@ class Cache with Logging {
if (testEnv == "1") {
baseUrl = baseUrlTest;
liveServer = false;
} else if ( testEnv == "2") {
} else if (testEnv == "2") {
baseUrl = baseUrlLocal;
liveServer = false;
}
@@ -214,9 +216,17 @@ class Cache with Logging {
baseUrl = baseUrlTest;
}
void setDietTestBaseUrl() {
baseUrl = baseUrlDietTest;
}
void setDietBaseUrl() {
baseUrl = baseUrlDiet;
}
void setLocalBaseUrl() {
baseUrl = baseUrlLocal;
}
}
String getAuthToken() {
return authToken;
@@ -374,7 +384,7 @@ class Cache with Logging {
baseUrl = baseUrlTest;
log("TestEnv $baseUrl");
return;
} else if ( testEnvironment == "2") {
} else if (testEnvironment == "2") {
baseUrl = baseUrlLocal;
log("TestEnv $baseUrl");
return;
@@ -563,8 +573,7 @@ class Cache with Logging {
ExercisePlan? getMyExercisePlan() => _myExercisePlan;
void setMyExercisePlanDetails(LinkedHashMap<int, ExercisePlanDetail> listExercisePlanDetail) =>
_myExercisesPlanDetails = listExercisePlanDetail;
void setMyExercisePlanDetails(LinkedHashMap<int, ExercisePlanDetail> listExercisePlanDetail) => _myExercisesPlanDetails = listExercisePlanDetail;
void addToMyExercisePlanDetails(ExercisePlanDetail detail) => _myExercisesPlanDetails[detail.exerciseTypeId] = detail;
@@ -578,8 +587,7 @@ class Cache with Logging {
void deleteMyExercisePlanDetail(ExercisePlanDetail detail) => deleteMyExercisePlanDetailByExerciseTypeId(detail.exerciseTypeId);
void deletedMyExercisePlanDetail(ExercisePlanDetail detail) =>
_myExercisesPlanDetails[detail.exerciseTypeId]!.change = ModelChange.deleted;
void deletedMyExercisePlanDetail(ExercisePlanDetail detail) => _myExercisesPlanDetails[detail.exerciseTypeId]!.change = ModelChange.deleted;
void deleteMyExercisePlanDetailByExerciseTypeId(int exerciseTypeId) {
_myExercisesPlanDetails[exerciseTypeId]!.change = ModelChange.delete;
+25
View File
@@ -0,0 +1,25 @@
class OpenAIChat {
int id = 0;
late String messages; // JSON of ChatMessage
String modelName = "gpt-3.5-turbo";
double temperature = 0.1;
OpenAIChat(this.messages, {String? modelName, double? temperature});
OpenAIChat.fromJson(Map json) {
id = json["id"];
messages = json['messages'];
modelName = json['modelName'];
temperature = json['temperature'];
}
Map<String, dynamic> toJson() => {
"id": id,
"messages": messages,
"modelName": modelName,
"temperature": temperature,
};
@override
String toString() => toJson().toString();
}
+41
View File
@@ -0,0 +1,41 @@
enum ChatRole { user, assistant, system }
extension ChatRoleExt on ChatRole {
String enumToStr() => toString().split(".").last;
bool equalsTo(ChatRole role) => toString() == role.toString();
bool equalsStringTo(String role) => enumToStr() == role;
}
class OpenAIChatMessage {
late ChatRole role; // JSON of ChatMessage
late String content;
String? name;
OpenAIChatMessage(this.role, this.content, {String? name});
OpenAIChatMessage.fromJson(Map json) {
role = toChatRole(json['role']);
content = json['content'];
name = json['name'] ?? "";
}
ChatRole toChatRole(String strRole) {
ChatRole role = ChatRole.user;
for (ChatRole chatRole in ChatRole.values) {
if (chatRole.equalsStringTo(strRole)) {
role = chatRole;
break;
}
}
return role;
}
Map<String, dynamic> toJson() => {
"role": role.enumToStr(),
"content": content,
"name": name,
};
@override
String toString() => toJson().toString();
}