Skip to content

Commit

Permalink
Handling controls from Glowbom file
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed May 12, 2023
1 parent 77e07c4 commit 55584e7
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
3 changes: 2 additions & 1 deletion app/lib/ai.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Ai {
Future<List<Message>> message(
String message, {
List<Map<String, String?>> previousMessages = const [],
bool aiEnabled = true,
}) async {
List<Map<String, Object>> foundQuestions = _findMatchingQuestions(message);

Expand All @@ -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;
Expand Down
26 changes: 14 additions & 12 deletions app/lib/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -34,7 +33,6 @@ class ChatScreen extends StatefulWidget {
this._selectedLanguage,
this._systemPrompt,
this._allowEnterKey,
this._allowDataImport,
this._autonomousMode,
this._enableAi,
this._showAiSettings);
Expand Down Expand Up @@ -376,6 +374,7 @@ class _ChatScreenState extends State<ChatScreen> {
_messages,
widget._questions,
widget._name,
widget._enableAi,
onAutonomousModeMessage: (String userInput) async {
List<String> tasks = await _generateTasks(userInput);
setState(() {
Expand All @@ -390,19 +389,22 @@ class _ChatScreenState extends State<ChatScreen> {
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
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,
),
),
),
],
),
),
Expand Down
11 changes: 8 additions & 3 deletions app/lib/new_message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ class NewMessage extends StatefulWidget {
final List<Message> _messages;
final List<Map<String, Object>>? _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
Expand Down Expand Up @@ -149,8 +151,10 @@ class _NewMessageState extends State<NewMessage> {
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(),
Expand Down Expand Up @@ -238,7 +242,8 @@ class _NewMessageState extends State<NewMessage> {
});

var response = await ai.message(message,
previousMessages: formattedPreviousMessages);
previousMessages: formattedPreviousMessages,
aiEnabled: widget._enableAi == null ? true : widget._enableAi!);

if (_stopRequested) {
return;
Expand Down
18 changes: 9 additions & 9 deletions app/lib/preset_talk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ class _TalkState extends State<Talk> {
_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 {
Expand All @@ -64,8 +64,8 @@ class _TalkState extends State<Talk> {
_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();
Expand Down Expand Up @@ -174,10 +174,11 @@ class _TalkState extends State<Talk> {
),
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'
Expand All @@ -198,7 +199,6 @@ class _TalkState extends State<Talk> {
_selectedLanguage,
_systemPrompt,
_allowEnterKey,
_allowDataImport,
_autonomousMode,
_enableAi,
_showAiSettings,
Expand Down

0 comments on commit 55584e7

Please sign in to comment.