Skip to content

Commit

Permalink
feat(puzzle_api): implement model info tracking and debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Dec 28, 2023
1 parent fc69b60 commit b6cc5f9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/lib/ai.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:math';

import 'package:glowby/hugging_face_api.dart';
import 'package:glowby/pulze_ai_api.dart';

import 'openai_api.dart';
import 'timestamp.dart';
Expand Down Expand Up @@ -49,7 +50,7 @@ class Ai {
: OpenAI_API.model == 'huggingface'
? HuggingFace_API.model()
: OpenAI_API.model == 'pulzeai'
? 'Powered by Pulze'
? '${PulzeAI_API.lastUsedModel()}'
: '';
return [
Message(
Expand Down
10 changes: 10 additions & 0 deletions app/lib/pulze_ai_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class PulzeAI_API {
]
''';
static String _model = 'pulze-v0';
static String _lastUsedModel = 'pulze-v0';
static String _systemMessage = '';
static bool _sendMessages = false;
static const String _apiKeyKey = 'pulze_ai_api_key';
Expand Down Expand Up @@ -84,6 +85,10 @@ class PulzeAI_API {
return _model;
}

static String lastUsedModel() {
return _lastUsedModel;
}

static void setModel(model) {
_model = model;
_secureStorage.write(key: _modelKey, value: _model);
Expand Down Expand Up @@ -141,6 +146,10 @@ class PulzeAI_API {

if (response.statusCode == 200) {
final responseBody = jsonDecode(utf8.decode(response.bodyBytes));
// Extracting the model information
String modelInfo = responseBody['metadata']['model']['model'];
_lastUsedModel = modelInfo;

String receivedResponse =
responseBody['choices'][0]['text'].toString().trim();

Expand All @@ -149,6 +158,7 @@ class PulzeAI_API {

if (kDebugMode) {
print('Generated Text: $generatedText');
print('Model Info: $modelInfo');
}

return generatedText;
Expand Down

0 comments on commit b6cc5f9

Please sign in to comment.