Skip to content

Commit

Permalink
Store the machine response in the history as well #7
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCsabaToth committed Aug 9, 2024
1 parent be3bf39 commit b68a17e
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/ai/cubit/ai_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@ class AiCubit extends Cubit<int> with ToolsMixin {
final history = await database?.limitedHistoryString(100) ?? '';
final resolved =
await resolvePromptToStandAlone(prompt, history, preferencesState);
final embedding = await obtainEmbedding(resolved, preferencesState);
final userEmbedding = await obtainEmbedding(resolved, preferencesState);
database?.addUpdateHistory(
History(
'user',
prompt,
PreferencesState.inputLocaleDefault,
resolved,
embedding,
userEmbedding,
),
);
final stuffedPrompt = StringBuffer();
final nearestHistory = await database?.getNearestHistory(embedding);
final nearestHistory = await database?.getNearestHistory(userEmbedding);
if (nearestHistory != null && nearestHistory.isNotEmpty) {
stuffedPrompt
..writeln(conversationStuffing)
Expand All @@ -71,7 +71,7 @@ class AiCubit extends Cubit<int> with ToolsMixin {
}

final nearestPersonalization =
await database?.getNearestPersonalization(embedding);
await database?.getNearestPersonalization(userEmbedding);
if (nearestPersonalization != null && nearestPersonalization.isNotEmpty) {
stuffedPrompt
..writeln(personalizationStuffing)
Expand Down Expand Up @@ -116,7 +116,17 @@ class AiCubit extends Cubit<int> with ToolsMixin {
response = await chat!.sendMessage(content);
}

// TODO(MrCsabaToth): Store in history
final modelEmbedding =
await obtainEmbedding(response.text ?? '', preferencesState);
database?.addUpdateHistory(
History(
'model',
response.text ?? '',
PreferencesState.inputLocaleDefault,
'',
modelEmbedding,
),
);

return response;
}
Expand Down

0 comments on commit b68a17e

Please sign in to comment.