-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Front end now uses new inference endpoint. Add multi-model mode.
- Loading branch information
Showing
12 changed files
with
1,416 additions
and
423 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,59 @@ | ||
|
||
enum ChatMessageSource { client, provider, system, internal } | ||
|
||
class ChatMessage { | ||
final ChatMessageSource source; | ||
final String sourceName; | ||
final String msg; | ||
final Map<String, dynamic>? metadata; | ||
final String? modelId; | ||
final String? modelName; | ||
|
||
ChatMessage( | ||
this.source, | ||
this.msg, { | ||
this.metadata, | ||
this.sourceName = '', | ||
this.modelId, | ||
this.modelName, | ||
}); | ||
|
||
String get message => msg; | ||
|
||
String? get displayName { | ||
print('Getting displayName. source: $source, modelName: $modelName, sourceName: $sourceName'); // Debug what we have | ||
if (source == ChatMessageSource.provider && modelName != null) { | ||
return modelName; | ||
} | ||
if (sourceName.isNotEmpty) { | ||
return sourceName; | ||
} | ||
print('Returning null displayName'); // See when we hit this case | ||
return null; | ||
} | ||
|
||
ChatMessage(this.source, this.msg, {this.metadata, this.sourceName = ''}); | ||
String formatUsage() { | ||
if (metadata == null || !metadata!.containsKey('usage')) { | ||
return ''; | ||
} | ||
|
||
final usage = metadata!['usage']; | ||
if (usage == null) { | ||
return ''; | ||
} | ||
|
||
final prompt = usage['prompt_tokens'] ?? 0; | ||
final completion = usage['completion_tokens'] ?? 0; | ||
|
||
if (prompt == 0 && completion == 0) { | ||
return ''; | ||
} | ||
|
||
return 'tokens: $prompt in, $completion out'; | ||
} | ||
|
||
String get message { | ||
return msg; | ||
@override | ||
String toString() { | ||
return 'ChatMessage(source: $source, model: $modelName, msg: ${msg.substring(0, msg.length.clamp(0, 50))}...)'; | ||
} | ||
} | ||
|
Oops, something went wrong.