From b6cc5f9968a1a9b84087c6c3766a90018b55c5cd Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 27 Dec 2023 16:24:52 -0800 Subject: [PATCH] feat(puzzle_api): implement model info tracking and debug logging --- app/lib/ai.dart | 3 ++- app/lib/pulze_ai_api.dart | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/lib/ai.dart b/app/lib/ai.dart index 6deb588..a0d908a 100644 --- a/app/lib/ai.dart +++ b/app/lib/ai.dart @@ -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'; @@ -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( diff --git a/app/lib/pulze_ai_api.dart b/app/lib/pulze_ai_api.dart index ba21985..97ae2d7 100644 --- a/app/lib/pulze_ai_api.dart +++ b/app/lib/pulze_ai_api.dart @@ -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'; @@ -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); @@ -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(); @@ -149,6 +158,7 @@ class PulzeAI_API { if (kDebugMode) { print('Generated Text: $generatedText'); + print('Model Info: $modelInfo'); } return generatedText;