From 55584e70d67dc55553475b68654bd574e6a505d7 Mon Sep 17 00:00:00 2001 From: Jacob Date: Thu, 11 May 2023 23:39:38 -0700 Subject: [PATCH] Handling controls from Glowbom file --- app/lib/ai.dart | 3 ++- app/lib/chat_screen.dart | 26 ++++++++++++++------------ app/lib/new_message.dart | 11 ++++++++--- app/lib/preset_talk.dart | 18 +++++++++--------- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/app/lib/ai.dart b/app/lib/ai.dart index 8c4f3f5..9c037d6 100644 --- a/app/lib/ai.dart +++ b/app/lib/ai.dart @@ -25,6 +25,7 @@ class Ai { Future> message( String message, { List> previousMessages = const [], + bool aiEnabled = true, }) async { List> foundQuestions = _findMatchingQuestions(message); @@ -33,7 +34,7 @@ class Ai { } // Call the OpenAI API if no matching questions are found locally - if (OpenAI_API.oat().isNotEmpty) { + if (aiEnabled && OpenAI_API.oat().isNotEmpty) { newtworkOperation = await OpenAI_API.getResponseFromOpenAI(message, previousMessages: previousMessages); String response = await newtworkOperation!.value; diff --git a/app/lib/chat_screen.dart b/app/lib/chat_screen.dart index cbd1e72..65cd86e 100644 --- a/app/lib/chat_screen.dart +++ b/app/lib/chat_screen.dart @@ -21,7 +21,6 @@ class ChatScreen extends StatefulWidget { final String? _selectedLanguage; final String? _systemPrompt; final bool? _allowEnterKey; - final bool? _allowDataImport; final bool? _autonomousMode; final bool? _enableAi; final bool? _showAiSettings; @@ -34,7 +33,6 @@ class ChatScreen extends StatefulWidget { this._selectedLanguage, this._systemPrompt, this._allowEnterKey, - this._allowDataImport, this._autonomousMode, this._enableAi, this._showAiSettings); @@ -376,6 +374,7 @@ class _ChatScreenState extends State { _messages, widget._questions, widget._name, + widget._enableAi, onAutonomousModeMessage: (String userInput) async { List tasks = await _generateTasks(userInput); setState(() { @@ -390,19 +389,22 @@ class _ChatScreenState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - ElevatedButton( - child: Text('Enter API Key'), - onPressed: _showApiKeyDialog, - ), + if (widget._allowEnterKey != null && widget._allowEnterKey!) + ElevatedButton( + child: Text('Enter API Key'), + onPressed: _showApiKeyDialog, + ), // Add the AI Settings button conditionally if (OpenAI_API.oat().isNotEmpty) - Padding( - padding: const EdgeInsets.only(left: 8.0), - child: ElevatedButton( - child: Text('AI Settings'), - onPressed: _showAiSettingsDialog, + if (widget._showAiSettings != null && + widget._showAiSettings!) + Padding( + padding: const EdgeInsets.only(left: 8.0), + child: ElevatedButton( + child: Text('AI Settings'), + onPressed: _showAiSettingsDialog, + ), ), - ), ], ), ), diff --git a/app/lib/new_message.dart b/app/lib/new_message.dart index 44395e7..7d985bc 100644 --- a/app/lib/new_message.dart +++ b/app/lib/new_message.dart @@ -38,9 +38,11 @@ class NewMessage extends StatefulWidget { final List _messages; final List>? _questions; final String? _name; + final bool? _enableAi; final Function(String) onAutonomousModeMessage; NewMessage(this._refresh, this._messages, this._questions, this._name, + this._enableAi, {required this.onAutonomousModeMessage}); @override @@ -149,8 +151,10 @@ class _NewMessageState extends State { final description = pattern != null ? message.replaceAll(RegExp(pattern, caseSensitive: false), '').trim() : ''; - print('description: $description'); - if (description.isNotEmpty) { + //print('description: $description'); + //print('enableAi: ${widget._enableAi}'); + if (description.isNotEmpty && + (widget._enableAi == null || widget._enableAi!)) { Message drawingMessage = Message( text: Utils.getRandomImageGenerationFunnyMessage(), createdAt: Timestamp.now(), @@ -238,7 +242,8 @@ class _NewMessageState extends State { }); var response = await ai.message(message, - previousMessages: formattedPreviousMessages); + previousMessages: formattedPreviousMessages, + aiEnabled: widget._enableAi == null ? true : widget._enableAi!); if (_stopRequested) { return; diff --git a/app/lib/preset_talk.dart b/app/lib/preset_talk.dart index ebbdbb7..24ec59c 100644 --- a/app/lib/preset_talk.dart +++ b/app/lib/preset_talk.dart @@ -48,8 +48,8 @@ class _TalkState extends State { _allowEnterKey = _content['ai_allow_enter_key'] ?? true; _allowDataImport = _content['ai_allow_data_import'] ?? true; _autonomousMode = _content['ai_autonomous_mode'] ?? false; - _enableAi = _content['ai_enable'] ?? true; - _showAiSettings = _content['ai_show_settings'] ?? true; + _enableAi = _content['ai_enable_ai'] ?? true; + _showAiSettings = _content['ai_show_ai_settings'] ?? true; _pressed100(); } else { @@ -64,8 +64,8 @@ class _TalkState extends State { _allowEnterKey = _content['ai_allow_enter_key'] ?? true; _allowDataImport = _content['ai_allow_data_import'] ?? true; _autonomousMode = _content['ai_autonomous_mode'] ?? false; - _enableAi = _content['ai_enable'] ?? true; - _showAiSettings = _content['ai_show_settings'] ?? true; + _enableAi = _content['ai_enable_ai'] ?? true; + _showAiSettings = _content['ai_show_ai_settings'] ?? true; _questions = buildQuestions(_content['questions']); _pressed100(); @@ -174,10 +174,11 @@ class _TalkState extends State { ), centerTitle: true, actions: [ - IconButton( - icon: Icon(Icons.file_upload), - onPressed: _startFilePicker, - ), + if (_allowDataImport != null && _allowDataImport == true) + IconButton( + icon: Icon(Icons.file_upload), + onPressed: _startFilePicker, + ), ], ), body: _appScreen == 'Loading' @@ -198,7 +199,6 @@ class _TalkState extends State { _selectedLanguage, _systemPrompt, _allowEnterKey, - _allowDataImport, _autonomousMode, _enableAi, _showAiSettings,