[ Edit ] refactored completion models classes and invoked toString and equality for sub-models
This commit is contained in:
@ -1,30 +1,63 @@
|
|||||||
# This file configures the static analysis results for your project (errors,
|
|
||||||
# warnings, and lints).
|
|
||||||
#
|
|
||||||
# This enables the 'recommended' set of lints from `package:lints`.
|
|
||||||
# This set helps identify many issues that may lead to problems when running
|
|
||||||
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
|
|
||||||
# style and format.
|
|
||||||
#
|
|
||||||
# If you want a smaller set of lints you can change this to specify
|
|
||||||
# 'package:lints/core.yaml'. These are just the most critical lints
|
|
||||||
# (the recommended set includes the core lints).
|
|
||||||
# The core lints are also what is used by pub.dev for scoring packages.
|
|
||||||
|
|
||||||
include: package:lints/recommended.yaml
|
linter:
|
||||||
|
rules:
|
||||||
|
|
||||||
# Uncomment the following section to specify additional rules.
|
analyzer:
|
||||||
|
plugins:
|
||||||
|
- dart_code_metrics
|
||||||
|
|
||||||
# linter:
|
dart_code_metrics:
|
||||||
# rules:
|
extends:
|
||||||
# - camel_case_types
|
- ... # configures the list of preset configurations
|
||||||
|
metrics:
|
||||||
|
cyclomatic-complexity: 20
|
||||||
|
lines-of-code: 100
|
||||||
|
maximum-nesting-level: 4
|
||||||
|
number-of-parameters: 4
|
||||||
|
|
||||||
# analyzer:
|
rules:
|
||||||
# exclude:
|
- avoid-dynamic
|
||||||
# - path/to/excluded/files/**
|
- avoid-redundant-async
|
||||||
|
- avoid-passing-async-when-sync-expected
|
||||||
|
- avoid-redundant-async
|
||||||
|
- avoid-unnecessary-type-assertions
|
||||||
|
- avoid-unnecessary-type-casts
|
||||||
|
- avoid-unrelated-type-assertions
|
||||||
|
- avoid-unused-parameters
|
||||||
|
- avoid-nested-conditional-expressions
|
||||||
|
- newline-before-return
|
||||||
|
- no-boolean-literal-compare
|
||||||
|
- no-empty-block
|
||||||
|
- prefer-trailing-comma
|
||||||
|
- prefer-conditional-expressions
|
||||||
|
- no-equal-then-else
|
||||||
|
- prefer-moving-to-variable
|
||||||
|
- avoid-duplicate-exports
|
||||||
|
- avoid-dynamic
|
||||||
|
- avoid-late-keyword
|
||||||
|
- avoid-nested-conditional-expressions
|
||||||
|
- avoid-unnecessary-type-assertions
|
||||||
|
- avoid-unnecessary-type-casts
|
||||||
|
- member-ordering
|
||||||
|
- no-magic-number
|
||||||
|
- prefer-trailing-comma
|
||||||
|
- always-remove-listener
|
||||||
|
- avoid-border-all
|
||||||
|
- avoid-expanded-as-spacer
|
||||||
|
- avoid-wrapping-in-padding
|
||||||
|
- prefer-const-border-radius
|
||||||
|
- prefer-correct-edge-insets-constructor
|
||||||
|
- prefer-single-widget-per-file
|
||||||
|
|
||||||
# For more information about the core and recommended set of lints, see
|
# - arguments-ordering:
|
||||||
# https://dart.dev/go/core-lints
|
# child-last: true
|
||||||
|
# - prefer-match-file-name rules-exclude:
|
||||||
|
# - ... # configures the list of files that should be ignored by rules
|
||||||
|
# anti-patterns:
|
||||||
|
# - ... # configures the list of anti-patterns
|
||||||
|
|
||||||
# For additional information about configuring this file, see
|
exclude:
|
||||||
# https://dart.dev/guides/language/analysis-options
|
- "example/**"
|
||||||
|
- "build/**"
|
||||||
|
- "**/*.g.dart"
|
||||||
|
- "**/*.freezed.dart"
|
@ -1,4 +1,6 @@
|
|||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
import "package:meta/meta.dart";
|
||||||
|
|
||||||
import 'sub_models/choice.dart';
|
import 'sub_models/choice.dart';
|
||||||
import 'sub_models/usage.dart';
|
import 'sub_models/usage.dart';
|
||||||
|
|
||||||
@ -6,6 +8,7 @@ export 'sub_models/choice.dart';
|
|||||||
export 'sub_models/usage.dart';
|
export 'sub_models/usage.dart';
|
||||||
export 'stream/completion.dart';
|
export 'stream/completion.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
class OpenAICompletionModel {
|
class OpenAICompletionModel {
|
||||||
/// The ID of the completion.
|
/// The ID of the completion.
|
||||||
final String id;
|
final String id;
|
||||||
@ -22,8 +25,13 @@ class OpenAICompletionModel {
|
|||||||
/// The usage of the completion, if any.
|
/// The usage of the completion, if any.
|
||||||
final OpenAICompletionModelUsage? usage;
|
final OpenAICompletionModelUsage? usage;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return id.hashCode ^ created.hashCode ^ model.hashCode ^ choices.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
/// This class is used to represent an OpenAI completion.
|
/// This class is used to represent an OpenAI completion.
|
||||||
OpenAICompletionModel({
|
const OpenAICompletionModel({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.created,
|
required this.created,
|
||||||
required this.model,
|
required this.model,
|
||||||
@ -37,7 +45,7 @@ class OpenAICompletionModel {
|
|||||||
id: json['id'],
|
id: json['id'],
|
||||||
created: DateTime.fromMillisecondsSinceEpoch(json['created'] * 1000),
|
created: DateTime.fromMillisecondsSinceEpoch(json['created'] * 1000),
|
||||||
model: json['model'],
|
model: json['model'],
|
||||||
choices: (json['choices'] as List<dynamic>)
|
choices: (json['choices'] as List)
|
||||||
.map((i) => OpenAICompletionModelChoice.fromJson(i))
|
.map((i) => OpenAICompletionModelChoice.fromJson(i))
|
||||||
.toList(),
|
.toList(),
|
||||||
usage: OpenAICompletionModelUsage.fromJson(json['usage']),
|
usage: OpenAICompletionModelUsage.fromJson(json['usage']),
|
||||||
@ -59,9 +67,4 @@ class OpenAICompletionModel {
|
|||||||
other.model == model &&
|
other.model == model &&
|
||||||
listEquals(other.choices, choices);
|
listEquals(other.choices, choices);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode {
|
|
||||||
return id.hashCode ^ created.hashCode ^ model.hashCode ^ choices.hashCode;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
import 'sub_models/choices.dart';
|
import 'sub_models/choices.dart';
|
||||||
|
|
||||||
export 'sub_models/choices.dart';
|
export 'sub_models/choices.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
class OpenAIStreamCompletionModel {
|
class OpenAIStreamCompletionModel {
|
||||||
/// The ID of the completion.
|
/// The ID of the completion.
|
||||||
final String id;
|
final String id;
|
||||||
@ -15,8 +19,13 @@ class OpenAIStreamCompletionModel {
|
|||||||
/// The model used to generate the completion.
|
/// The model used to generate the completion.
|
||||||
final String model;
|
final String model;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return id.hashCode ^ created.hashCode ^ choices.hashCode ^ model.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
/// This class is used to represent an OpenAI stream completion.
|
/// This class is used to represent an OpenAI stream completion.
|
||||||
OpenAIStreamCompletionModel({
|
const OpenAIStreamCompletionModel({
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.created,
|
required this.created,
|
||||||
required this.choices,
|
required this.choices,
|
||||||
@ -34,4 +43,20 @@ class OpenAIStreamCompletionModel {
|
|||||||
model: json['model'],
|
model: json['model'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(covariant OpenAIStreamCompletionModel other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
final listEquals = const DeepCollectionEquality().equals;
|
||||||
|
|
||||||
|
return other.id == id &&
|
||||||
|
other.created == created &&
|
||||||
|
listEquals(other.choices, choices) &&
|
||||||
|
other.model == model;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'OpenAIStreamCompletionModel(id: $id, created: $created, choices: $choices, model: $model)';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import "package:meta/meta.dart";
|
||||||
|
|
||||||
|
@immutable
|
||||||
class OpenAIStreamCompletionModelChoice {
|
class OpenAIStreamCompletionModelChoice {
|
||||||
/// The text generated by the completion.
|
/// The text generated by the completion.
|
||||||
final String text;
|
final String text;
|
||||||
@ -9,10 +12,18 @@ class OpenAIStreamCompletionModelChoice {
|
|||||||
final int? logprobs;
|
final int? logprobs;
|
||||||
|
|
||||||
/// The reason the completion finished.
|
/// The reason the completion finished.
|
||||||
final dynamic finishReason;
|
final finishReason;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return text.hashCode ^
|
||||||
|
index.hashCode ^
|
||||||
|
logprobs.hashCode ^
|
||||||
|
finishReason.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
/// This class is used to represent a choice generated by an OpenAI stream completion.
|
/// This class is used to represent a choice generated by an OpenAI stream completion.
|
||||||
OpenAIStreamCompletionModelChoice({
|
const OpenAIStreamCompletionModelChoice({
|
||||||
required this.text,
|
required this.text,
|
||||||
required this.index,
|
required this.index,
|
||||||
required this.logprobs,
|
required this.logprobs,
|
||||||
@ -21,7 +32,8 @@ class OpenAIStreamCompletionModelChoice {
|
|||||||
|
|
||||||
/// This method is used to convert a [Map<String, dynamic>] object to a [OpenAIStreamCompletionModelChoice] object.
|
/// This method is used to convert a [Map<String, dynamic>] object to a [OpenAIStreamCompletionModelChoice] object.
|
||||||
factory OpenAIStreamCompletionModelChoice.fromJson(
|
factory OpenAIStreamCompletionModelChoice.fromJson(
|
||||||
Map<String, dynamic> json) {
|
Map<String, dynamic> json,
|
||||||
|
) {
|
||||||
return OpenAIStreamCompletionModelChoice(
|
return OpenAIStreamCompletionModelChoice(
|
||||||
text: json['text'],
|
text: json['text'],
|
||||||
index: json['index'],
|
index: json['index'],
|
||||||
@ -29,4 +41,19 @@ class OpenAIStreamCompletionModelChoice {
|
|||||||
finishReason: json['finishReason'],
|
finishReason: json['finishReason'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'OpenAIStreamCompletionModelChoice(text: $text, index: $index, logprobs: $logprobs, finishReason: $finishReason)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(covariant OpenAIStreamCompletionModelChoice other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other.text == text &&
|
||||||
|
other.index == index &&
|
||||||
|
other.logprobs == logprobs &&
|
||||||
|
other.finishReason == finishReason;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
class OpenAICompletionModelChoice {
|
class OpenAICompletionModelChoice {
|
||||||
/// The text generated by the completion.
|
/// The text generated by the completion.
|
||||||
final String text;
|
final String text;
|
||||||
@ -11,8 +14,16 @@ class OpenAICompletionModelChoice {
|
|||||||
/// The reason the completion finished.
|
/// The reason the completion finished.
|
||||||
final String? finishReason;
|
final String? finishReason;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return text.hashCode ^
|
||||||
|
index.hashCode ^
|
||||||
|
logprobs.hashCode ^
|
||||||
|
finishReason.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
/// This class is used to represent a choice generated by an OpenAI completion.
|
/// This class is used to represent a choice generated by an OpenAI completion.
|
||||||
OpenAICompletionModelChoice({
|
const OpenAICompletionModelChoice({
|
||||||
required this.text,
|
required this.text,
|
||||||
required this.index,
|
required this.index,
|
||||||
required this.logprobs,
|
required this.logprobs,
|
||||||
@ -39,14 +50,6 @@ class OpenAICompletionModelChoice {
|
|||||||
other.finishReason == finishReason;
|
other.finishReason == finishReason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode {
|
|
||||||
return text.hashCode ^
|
|
||||||
index.hashCode ^
|
|
||||||
logprobs.hashCode ^
|
|
||||||
finishReason.hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'OpenAICompletionModelChoice(text: $text, index: $index, logprobs: $logprobs, finishReason: $finishReason)';
|
return 'OpenAICompletionModelChoice(text: $text, index: $index, logprobs: $logprobs, finishReason: $finishReason)';
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
import 'package:meta/meta.dart';
|
||||||
|
|
||||||
|
@immutable
|
||||||
class OpenAICompletionModelUsage {
|
class OpenAICompletionModelUsage {
|
||||||
/// The number of tokens in the prompt.
|
/// The number of tokens in the prompt.
|
||||||
final int? promptTokens;
|
final int? promptTokens;
|
||||||
@ -8,8 +11,12 @@ class OpenAICompletionModelUsage {
|
|||||||
/// The total number of tokens in the prompt and completion.
|
/// The total number of tokens in the prompt and completion.
|
||||||
final int? totalTokens;
|
final int? totalTokens;
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode =>
|
||||||
|
promptTokens.hashCode ^ completionTokens.hashCode ^ totalTokens.hashCode;
|
||||||
|
|
||||||
/// This class is used to represent the usage of an OpenAI completion.
|
/// This class is used to represent the usage of an OpenAI completion.
|
||||||
OpenAICompletionModelUsage({
|
const OpenAICompletionModelUsage({
|
||||||
required this.promptTokens,
|
required this.promptTokens,
|
||||||
required this.completionTokens,
|
required this.completionTokens,
|
||||||
required this.totalTokens,
|
required this.totalTokens,
|
||||||
@ -33,10 +40,6 @@ class OpenAICompletionModelUsage {
|
|||||||
other.totalTokens == totalTokens;
|
other.totalTokens == totalTokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
|
||||||
int get hashCode =>
|
|
||||||
promptTokens.hashCode ^ completionTokens.hashCode ^ totalTokens.hashCode;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() =>
|
String toString() =>
|
||||||
'OpenAICompletionModelUsage(promptTokens: $promptTokens, completionTokens: $completionTokens, totalTokens: $totalTokens)';
|
'OpenAICompletionModelUsage(promptTokens: $promptTokens, completionTokens: $completionTokens, totalTokens: $totalTokens)';
|
||||||
|
91
pubspec.lock
91
pubspec.lock
@ -15,6 +15,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.4.0"
|
version: "5.4.0"
|
||||||
|
analyzer_plugin:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: analyzer_plugin
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.11.2"
|
||||||
|
ansicolor:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: ansicolor
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.1"
|
||||||
args:
|
args:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -64,6 +78,34 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.2"
|
version: "3.0.2"
|
||||||
|
csslib:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: csslib
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.17.2"
|
||||||
|
dart_code_metrics:
|
||||||
|
dependency: "direct dev"
|
||||||
|
description:
|
||||||
|
name: dart_code_metrics
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "5.6.0"
|
||||||
|
dart_code_metrics_presets:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: dart_code_metrics_presets
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "1.2.0"
|
||||||
|
dart_style:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: dart_style
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.2.4"
|
||||||
file:
|
file:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -85,6 +127,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.1"
|
version: "2.1.1"
|
||||||
|
html:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: html
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.15.1"
|
||||||
http:
|
http:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
@ -120,6 +169,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.6.5"
|
version: "0.6.5"
|
||||||
|
json_annotation:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: json_annotation
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.8.0"
|
||||||
lints:
|
lints:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -176,6 +232,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.8.3"
|
version: "1.8.3"
|
||||||
|
petitparser:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: petitparser
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "5.1.0"
|
||||||
|
platform:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: platform
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "3.1.0"
|
||||||
pool:
|
pool:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -183,6 +253,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.5.1"
|
version: "1.5.1"
|
||||||
|
process:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: process
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "4.2.4"
|
||||||
pub_semver:
|
pub_semver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -190,6 +267,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.3"
|
version: "2.1.3"
|
||||||
|
pub_updater:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: pub_updater
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.4"
|
||||||
shelf:
|
shelf:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -323,6 +407,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.2.0"
|
version: "1.2.0"
|
||||||
|
xml:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: xml
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "6.2.2"
|
||||||
yaml:
|
yaml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -9,6 +9,7 @@ environment:
|
|||||||
sdk: ">=2.18.5 <3.0.0"
|
sdk: ">=2.18.5 <3.0.0"
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
dart_code_metrics: ^5.6.0
|
||||||
lints: ^2.0.0
|
lints: ^2.0.0
|
||||||
test: ^1.16.0
|
test: ^1.16.0
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user