Skip to content

Commit

Permalink
refactor example app
Browse files Browse the repository at this point in the history
  • Loading branch information
redevrx committed Jun 26, 2023
1 parent e9e5cfe commit 2ede47a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
14 changes: 7 additions & 7 deletions example_app/openai_app/lib/bloc/openai/openai_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ class OpenAIBloc extends Cubit<OpenAIState> {
.transform(StreamTransformer.fromHandlers(handleError: handleError))
.listen((it) {
Message? message;
for (final m in list) {
if (m.id == '${it.id}') {
message = m;
list.remove(m);
break;
list.removeWhere((element){
if(element.id == '${it.id}'){
message = element;
return true;
}
}
return false;
});

///+= message
message?.message =
'${message.message ?? ""}${it.choices.last.message?.content ?? ""}';
'${message?.message ?? ""}${it.choices.last.message?.content ?? ""}';
list.add(Message(isBot: true, id: '${it.id}', message: message?.message));
emit(ChatCompletionState(
isBot: true, messages: list, showStopButton: true));
Expand Down
14 changes: 6 additions & 8 deletions lib/src/model/complete_text/response/usage.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
class Usage {
final int promptTokens;
final int completionTokens;
final int totalTokens;
final int? promptTokens;
final int? completionTokens;
final int? totalTokens;
final String id = "${DateTime.now().millisecondsSinceEpoch}";

Usage(this.promptTokens, this.completionTokens, this.totalTokens);

factory Usage.fromJson(Map<String, dynamic> json) => Usage(
json['prompt_tokens'] as int,
json['completion_tokens'] == null
? 0
: json['completion_tokens'] as int,
json['total_tokens'] as int,
json['prompt_tokens'],
json['completion_tokens'],
json['total_tokens'],
);
Map<String, dynamic> toJson() => usageToJson(this);

Expand Down

0 comments on commit 2ede47a

Please sign in to comment.