v1.0.7 openai with model name and temperature
This commit is contained in:
parent
56ada3c774
commit
cb90c3d68a
@ -1,5 +1,8 @@
|
|||||||
Workout Test and Diet 4 You Common Util Functions
|
Workout Test and Diet 4 You Common Util Functions
|
||||||
|
|
||||||
|
Version 1.0.7
|
||||||
|
openai with model name and temperature
|
||||||
|
|
||||||
Version 1.0.6
|
Version 1.0.6
|
||||||
membership, customer_membership
|
membership, customer_membership
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
class Membership {
|
class Membership {
|
||||||
late int membershipId;
|
late int membershipId;
|
||||||
late String name;
|
late String name;
|
||||||
late String description;
|
String? description;
|
||||||
late int duration;
|
late int duration;
|
||||||
late String durationType;
|
late String durationType;
|
||||||
late String durationUnit;
|
late String durationUnit;
|
||||||
@ -12,12 +12,12 @@ class Membership {
|
|||||||
Membership.fromJson(Map json) {
|
Membership.fromJson(Map json) {
|
||||||
membershipId = json['membershipId'];
|
membershipId = json['membershipId'];
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
description = json['description'];
|
description = json['description'] ?? "";
|
||||||
duration = json['duration'];
|
duration = json['duration'];
|
||||||
durationUnit = json['durationUnit'];
|
durationUnit = json['durationUnit'];
|
||||||
durationType = json['durationType'];
|
durationType = json['durationType'];
|
||||||
trainingPlanId = json['trainingPlanId'];
|
trainingPlanId = json['trainingPlanId'] ?? 0;
|
||||||
trainingPlanDayIds = json['trainingPlanDayIds'];
|
trainingPlanDayIds = json['trainingPlanDayIds'] ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, dynamic> toJson() => {
|
Map<String, dynamic> toJson() => {
|
||||||
|
22
lib/model/openai.dart
Normal file
22
lib/model/openai.dart
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
class OpenAI {
|
||||||
|
late String question;
|
||||||
|
late String modelName;
|
||||||
|
late double temperature;
|
||||||
|
|
||||||
|
OpenAI(this.question, this.modelName, this.temperature);
|
||||||
|
|
||||||
|
OpenAI.fromJson(Map json) {
|
||||||
|
question = json['question'];
|
||||||
|
modelName = json['modelName'];
|
||||||
|
temperature = json['temperature'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
"question": question,
|
||||||
|
"modelName": modelName,
|
||||||
|
"temperature": temperature,
|
||||||
|
};
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => toJson().toString();
|
||||||
|
}
|
@ -7,11 +7,11 @@ class Product {
|
|||||||
late int sort;
|
late int sort;
|
||||||
late int productSet;
|
late int productSet;
|
||||||
late DateTime validFrom;
|
late DateTime validFrom;
|
||||||
late DateTime? validTo;
|
DateTime? validTo;
|
||||||
late String? productIdIos;
|
String? productIdIos;
|
||||||
late String? productIdAndroid;
|
String? productIdAndroid;
|
||||||
late double? priceIos;
|
double? priceIos;
|
||||||
late double? priceAndroid;
|
double? priceAndroid;
|
||||||
String? localizedPrice;
|
String? localizedPrice;
|
||||||
|
|
||||||
Product.fromJson(Map json) {
|
Product.fromJson(Map json) {
|
||||||
@ -24,10 +24,10 @@ class Product {
|
|||||||
productSet = json['productSet'];
|
productSet = json['productSet'];
|
||||||
validFrom = (json['validFrom'] == null ? null : DateTime.parse(json['validFrom']))!;
|
validFrom = (json['validFrom'] == null ? null : DateTime.parse(json['validFrom']))!;
|
||||||
validTo = json['validTo'] == null ? null : DateTime.parse(json['validTo']);
|
validTo = json['validTo'] == null ? null : DateTime.parse(json['validTo']);
|
||||||
productIdIos = json['productIdIos'];
|
productIdIos = json['productIdIos'] ?? 0.0;
|
||||||
productIdAndroid = json['productIdAndroid'];
|
productIdAndroid = json['productIdAndroid'] ?? 0.0;
|
||||||
priceIos = json['priceIos'];
|
priceIos = json['priceIos'] ?? 0.0;
|
||||||
priceAndroid = json['priceAndroid'];
|
priceAndroid = json['priceAndroid'] ?? 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
class Property {
|
class Property {
|
||||||
late int propertyId;
|
late int propertyId;
|
||||||
late String propertyName;
|
late String propertyName;
|
||||||
late String propertyUnit;
|
String? propertyUnit;
|
||||||
late String propertyNameTranslation;
|
String? propertyNameTranslation;
|
||||||
int? top;
|
int? top;
|
||||||
int? left;
|
int? left;
|
||||||
double? value;
|
double? value;
|
||||||
@ -10,7 +10,7 @@ class Property {
|
|||||||
Property.fromJson(Map json) {
|
Property.fromJson(Map json) {
|
||||||
propertyId = json['propertyId'];
|
propertyId = json['propertyId'];
|
||||||
propertyName = json['propertyName'];
|
propertyName = json['propertyName'];
|
||||||
propertyUnit = json['propertyUnit'];
|
propertyUnit = json['propertyUnit'] ?? "";
|
||||||
propertyNameTranslation =
|
propertyNameTranslation =
|
||||||
json['translations'] != null && (json['translations']).length > 0
|
json['translations'] != null && (json['translations']).length > 0
|
||||||
? json['translations'][0]['propertyName']
|
? json['translations'][0]['propertyName']
|
||||||
|
@ -20,9 +20,9 @@ class TrainingPlan {
|
|||||||
TrainingPlan.fromJson(Map<String, dynamic> json) {
|
TrainingPlan.fromJson(Map<String, dynamic> json) {
|
||||||
trainingPlanId = json['trainingPlanId'];
|
trainingPlanId = json['trainingPlanId'];
|
||||||
name = json['name'];
|
name = json['name'];
|
||||||
type = json['type'];
|
type = json['type'] ?? "";
|
||||||
internalName = json['internalName'];
|
internalName = json['internalName'] ?? "";
|
||||||
description = json['description'];
|
description = json['description'] ?? "";
|
||||||
free = json['free'];
|
free = json['free'];
|
||||||
active = json['active'];
|
active = json['active'];
|
||||||
treeId = json['treeId'];
|
treeId = json['treeId'];
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:workouttest_util/model/openai.dart';
|
||||||
import 'package:workouttest_util/service/api.dart';
|
import 'package:workouttest_util/service/api.dart';
|
||||||
import 'package:workouttest_util/util/logging.dart';
|
import 'package:workouttest_util/util/logging.dart';
|
||||||
|
|
||||||
@ -19,4 +21,17 @@ class OpenAIApi with Logging {
|
|||||||
}
|
}
|
||||||
return response ?? "";
|
return response ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<String> getOpenAICompletionWithModel(OpenAI openai) async {
|
||||||
|
String? response;
|
||||||
|
try {
|
||||||
|
String body = const JsonEncoder().convert(openai.toJson());
|
||||||
|
response = await _client.post("openai/completion_with_model", body);
|
||||||
|
} on TimeoutException catch (_) {
|
||||||
|
log("Timeout from OpenAI");
|
||||||
|
} on Exception catch (e) {
|
||||||
|
log(e.toString());
|
||||||
|
}
|
||||||
|
return response ?? "";
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
name: workouttest_util
|
name: workouttest_util
|
||||||
description: Workout Test app and web functions.
|
description: Workout Test app and web functions.
|
||||||
version: 1.0.6
|
version: 1.0.7
|
||||||
homepage:
|
homepage:
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:workouttest_util/model/cache.dart';
|
import 'package:workouttest_util/model/cache.dart';
|
||||||
|
import 'package:workouttest_util/model/openai.dart';
|
||||||
import 'package:workouttest_util/service/openai_service.dart';
|
import 'package:workouttest_util/service/openai_service.dart';
|
||||||
|
|
||||||
|
|
||||||
@ -9,11 +10,18 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('openai response succesful', () async {
|
test('openai response succesful', () async {
|
||||||
|
|
||||||
|
|
||||||
var api = OpenAIApi();
|
var api = OpenAIApi();
|
||||||
String response = await api.getOpenAICompletion("Who wrote the song 'yellow submarine'?");
|
String response = await api.getOpenAICompletion("Who wrote the song 'yellow submarine'?");
|
||||||
print(response);
|
print(response);
|
||||||
expect(response, matches(RegExp(r'Beatles') ));
|
expect(response, matches(RegExp(r'Beatles') ));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('openai with model response succesful', () async {
|
||||||
|
var api = OpenAIApi();
|
||||||
|
String question = "Készíts egy heti egészséges és változatos étrendet egy új felhasználónak az alábbi adatok alapján: férfi, 51 éves. Célja: Le szeretnék fogyni, heti mozgás: Hetente 3-4 alkalom, BMI: 24.784257517393772, BMR: 1723.75. A neve Tibi. Az egyes étkezések különbözőek legyenek, és add meg hozzájuk a mennyiséget és a kalóriatartalmat is. Vedd figyelembe, hogy a napi összes kalóriaérték 200-400 kCal-val kevesebb legyen, mint 1723.75 kCal";
|
||||||
|
var openai = OpenAI(question, "text-davinci-003", 0.5);
|
||||||
|
String response = await api.getOpenAICompletionWithModel(openai);
|
||||||
|
print(response);
|
||||||
|
expect(response, matches(RegExp(r'Tibi') ));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user