[ Edit, Add ] edited and updated docs of completion model directory files code

This commit is contained in:
Anas Fikhi
2023-11-22 03:24:03 +01:00
parent 37f613abaf
commit e02a50ffce
6 changed files with 54 additions and 24 deletions

View File

@ -47,7 +47,8 @@ final class OpenAIStreamChatCompletionChoiceDeltaModel {
: null,
content: json['content'] != null
? OpenAIMessageDynamicContentFromFieldAdapter.dynamicContentFromField(
json['content'])
json['content'],
)
: null,
toolCalls: json['tool_calls'] != null
? (json['tool_calls'] as List)

View File

@ -9,34 +9,45 @@ export 'sub_models/usage.dart';
export 'stream/completion.dart';
/// {@template openai_completion_model}
/// This represents the response from a completion request.
/// This represents the response from a completion request by the [OpenAICompletion] methods.
/// {@endtemplate}
@immutable
final class OpenAICompletionModel {
/// The ID of the completion.
/// The [id]entifier of the completion.
final String id;
/// The date the completion was created.
/// The date the completion was [created].
final DateTime created;
/// The model used to generate the completion.
/// The [model] used to generate the completion.
final String model;
/// The choices generated by the completion.
/// The [choices] generated by the completion.
final List<OpenAICompletionModelChoice> choices;
/// The usage of the completion, if any.
/// The [usage] of the completion, if any.
final OpenAICompletionModelUsage? usage;
///
/// The [systemFingerprint] of the completion, if any.
final String? systemFingerprint;
/// Weither the completion have at least one choice in [choices].
bool get haveChoices => choices.isNotEmpty;
/// Weither the completion have system fingerprint.
bool get haveSystemFingerprint => systemFingerprint != null;
/// Weither the completion have usage information.
bool get haveUsage => usage != null;
@override
int get hashCode {
return id.hashCode ^ created.hashCode ^ model.hashCode ^ choices.hashCode;
return id.hashCode ^
created.hashCode ^
model.hashCode ^
choices.hashCode ^
usage.hashCode ^
systemFingerprint.hashCode;
}
/// {@macro openai_completion_model}
@ -68,7 +79,7 @@ final class OpenAICompletionModel {
@override
String toString() {
return 'OpenAICompletionModel(id: $id, created: $created, model: $model, choices: $choices)';
return 'OpenAICompletionModel(id: $id, created: $created, model: $model, choices: $choices, usage: $usage, systemFingerprint: $systemFingerprint)';
}
@override
@ -79,6 +90,8 @@ final class OpenAICompletionModel {
return other.id == id &&
other.created == created &&
other.model == model &&
listEquals(other.choices, choices);
listEquals(other.choices, choices) &&
other.usage == usage &&
other.systemFingerprint == systemFingerprint;
}
}

View File

@ -10,24 +10,27 @@ export 'sub_models/choices.dart';
/// {@endtemplate}
@immutable
final class OpenAIStreamCompletionModel {
/// The ID of the completion.
/// The [id]entifier of the completion.
final String id;
/// The date the completion was created.
/// The date the completion was [created].
final DateTime created;
/// The choices generated by the completion.
/// The [choices] generated by the completion.
final List<OpenAIStreamCompletionModelChoice> choices;
/// The model used to generate the completion.
/// The [model] used to generate the completion.
final String model;
///
/// The system fingerprint of the completion.
final String? systemFingerprint;
/// Weither the chat completion have at least one choice in [choices].
/// Weither the completion have at least one choice in [choices].
bool get haveChoices => choices.isNotEmpty;
/// Weither the completion have a system fingerprint.
bool get haveSystemFingerprint => systemFingerprint != null;
@override
int get hashCode {
return id.hashCode ^ created.hashCode ^ choices.hashCode ^ model.hashCode;
@ -64,11 +67,12 @@ final class OpenAIStreamCompletionModel {
return other.id == id &&
other.created == created &&
listEquals(other.choices, choices) &&
other.model == model;
other.model == model &&
other.systemFingerprint == systemFingerprint;
}
@override
String toString() {
return 'OpenAIStreamCompletionModel(id: $id, created: $created, choices: $choices, model: $model)';
return 'OpenAIStreamCompletionModel(id: $id, created: $created, choices: $choices, model: $model, systemFingerprint: $systemFingerprint)';
}
}

View File

@ -17,6 +17,12 @@ final class OpenAIStreamCompletionModelChoice {
/// The reason the completion finished.
final String? finishReason;
/// Weither the choice have log probabilities.
bool get haveLogprobs => logprobs != null;
/// Weither the choice have a finish reason.
bool get haveFinishReason => finishReason != null;
@override
int get hashCode {
return text.hashCode ^

View File

@ -1,6 +1,6 @@
import 'package:meta/meta.dart';
/// {@template openai_completion_model_choice}
/// {@template openai_completion_model_choice_model}
/// This class is used to represent a choice generated by a completion request.
/// {@endtemplate}
@immutable
@ -17,6 +17,12 @@ final class OpenAICompletionModelChoice {
/// The reason the completion finished.
final String? finishReason;
/// Weither the choice have log probabilities.
bool get haveLogprobs => logprobs != null;
/// Weither the choice have a finish reason.
bool get haveFinishReason => finishReason != null;
@override
int get hashCode {
return text.hashCode ^
@ -25,7 +31,7 @@ final class OpenAICompletionModelChoice {
finishReason.hashCode;
}
/// {@macro openai_completion_model_choice}
/// {@macro openai_completion_model_choice_model}
const OpenAICompletionModelChoice({
required this.text,
required this.index,

View File

@ -6,13 +6,13 @@ import 'package:meta/meta.dart';
@immutable
final class OpenAICompletionModelUsage {
/// The number of tokens in the prompt.
final int? promptTokens;
final int promptTokens;
/// The number of tokens in the completion.
final int? completionTokens;
final int completionTokens;
/// The total number of tokens in the prompt and completion.
final int? totalTokens;
final int totalTokens;
@override
int get hashCode =>