Merge pull request #148 from lollipopkit/main
[Edit] fix chat completion & opt.
This commit is contained in:
@ -71,9 +71,12 @@ class OpenAIChatCompletionChoiceMessageContentItemModel {
|
||||
other.imageUrl == imageUrl;
|
||||
}
|
||||
|
||||
//! TODO: make a dynamic toString method for different types of content items.
|
||||
@override
|
||||
String toString() {
|
||||
return 'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type, text: $text, imageUrl: $imageUrl)';
|
||||
}
|
||||
String toString() => switch (type) {
|
||||
'text' =>
|
||||
'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type, text: $text)',
|
||||
'image' =>
|
||||
'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type, imageUrl: $imageUrl)',
|
||||
_ => 'OpenAIChatCompletionChoiceMessageContentItemModel(type: $type)',
|
||||
};
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ final class OpenAIFineTuneHyperParamsModel {
|
||||
promptLossWeight.hashCode;
|
||||
}
|
||||
|
||||
/// {@template openai_fine_tune_hyper_params_model}
|
||||
/// {@macro openai_fine_tune_hyper_params_model}
|
||||
const OpenAIFineTuneHyperParamsModel({
|
||||
required this.batchSize,
|
||||
required this.learningRateMultiplier,
|
||||
@ -45,8 +45,9 @@ final class OpenAIFineTuneHyperParamsModel {
|
||||
required this.promptLossWeight,
|
||||
});
|
||||
|
||||
/// {@template openai_fine_tune_hyper_params_model}
|
||||
/// {@template openai_fine_tune_hyper_params_model_fromMap}
|
||||
/// This method is used to convert a [Map<String, dynamic>] object to a [OpenAIFineTuneHyperParamsModel] object.
|
||||
/// {@endtemplate}
|
||||
factory OpenAIFineTuneHyperParamsModel.fromMap(Map<String, dynamic> json) {
|
||||
return OpenAIFineTuneHyperParamsModel(
|
||||
batchSize: json['batch_size'],
|
||||
|
@ -569,11 +569,11 @@ abstract class OpenAINetworkingClient {
|
||||
|
||||
var resultBody;
|
||||
|
||||
resultBody = responseBody.canBeParsedToJson
|
||||
? decodeToMap(responseBody)
|
||||
: responseMapAdapter != null
|
||||
? responseMapAdapter(responseBody)
|
||||
: responseBody;
|
||||
resultBody = switch ((responseBody.canBeParsedToJson, responseMapAdapter)) {
|
||||
(true, _) => decodeToMap(responseBody),
|
||||
(_, null) => responseBody,
|
||||
(_, final func) => func!(responseBody),
|
||||
};
|
||||
|
||||
OpenAILogger.decodedSuccessfully();
|
||||
if (doesErrorExists(resultBody)) {
|
||||
|
@ -9,6 +9,9 @@ import '../constants/strings.dart';
|
||||
@immutable
|
||||
@internal
|
||||
abstract final class OpenAILogger {
|
||||
/// The valid min length of an api key.
|
||||
static const int _kValidApiKeyLength = 10;
|
||||
|
||||
/// {@template openai_logger_is_active}
|
||||
/// Wether the to show operations flow logger is active or not.
|
||||
/// {@endtemplate}
|
||||
@ -87,7 +90,7 @@ abstract final class OpenAILogger {
|
||||
static isValidApiKey(String key) {
|
||||
return key.isNotEmpty &&
|
||||
key.startsWith("sk-") &&
|
||||
key.length > 10; //magic number
|
||||
key.length > _kValidApiKeyLength;
|
||||
}
|
||||
|
||||
/// Logs that an baseUrl key is being set, if the logger is active.
|
||||
|
@ -592,9 +592,12 @@ void main() async {
|
||||
File jsonLFileExample() {
|
||||
final file = File("example.jsonl");
|
||||
file.writeAsStringSync(
|
||||
jsonEncode(
|
||||
{"prompt": "<prompt text>", "completion": "<ideal generated text>"}),
|
||||
jsonEncode({
|
||||
"prompt": "<prompt text>",
|
||||
"completion": "<ideal generated text>",
|
||||
}),
|
||||
);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
@ -606,5 +609,6 @@ Future<File> getFileFromUrl(
|
||||
final uniqueImageName = DateTime.now().microsecondsSinceEpoch;
|
||||
final file = File("$uniqueImageName.$fileExtension");
|
||||
await file.writeAsBytes(response.bodyBytes);
|
||||
|
||||
return file;
|
||||
}
|
||||
|
Reference in New Issue
Block a user