Skip to content

Commit

Permalink
Integrated continuousModeSteps from SettingsViewModel into ChatViewModel
Browse files Browse the repository at this point in the history
Refactored the ChatViewModel's sendChatMessage method to utilize the continuousModeSteps setting from the SettingsViewModel. This allows the continuous chat mode to honor the user's preference from the settings. Also introduced an optional currentStep parameter with a default value, enabling better control over the progression of continuous mode.
  • Loading branch information
hunteraraujo committed Sep 25, 2023
1 parent 9463fbb commit ffa76c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 10 additions & 2 deletions frontend/lib/viewmodels/chat_viewmodel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class ChatViewModel with ChangeNotifier {
}

/// Sends a chat message for a specific task.
void sendChatMessage(String? message) async {
void sendChatMessage(String? message,
{required int continuousModeSteps, int currentStep = 1}) async {
if (_currentTaskId == null) {
print("Error: Task ID is not set.");
return;
Expand Down Expand Up @@ -147,7 +148,14 @@ class ChatViewModel with ChangeNotifier {
notifyListeners();

if (_isContinuousMode) {
sendChatMessage(null);
print("Continuous Mode: Step $currentStep of $continuousModeSteps");
if (currentStep < continuousModeSteps) {
sendChatMessage(null,
continuousModeSteps: continuousModeSteps,
currentStep: currentStep + 1);
} else {
_isContinuousMode = false;
}
}

print("Chats added for task ID: $_currentTaskId");
Expand Down
15 changes: 11 additions & 4 deletions frontend/lib/views/chat/chat_view.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:auto_gpt_flutter_client/models/message_type.dart';
import 'package:auto_gpt_flutter_client/viewmodels/settings_viewmodel.dart';
import 'package:auto_gpt_flutter_client/viewmodels/task_viewmodel.dart';
import 'package:auto_gpt_flutter_client/views/chat/agent_message_tile.dart';
import 'package:auto_gpt_flutter_client/views/chat/chat_input_field.dart';
Expand Down Expand Up @@ -94,13 +95,19 @@ class _ChatViewState extends State<ChatView> {
child: ChatInputField(
onSendPressed: (message) async {
if (widget.viewModel.currentTaskId != null) {
widget.viewModel
.sendChatMessage((message == "") ? null : message);
widget.viewModel.sendChatMessage(
(message == "") ? null : message,
continuousModeSteps:
Provider.of<SettingsViewModel>(context, listen: false)
.continuousModeSteps);
} else {
String newTaskId = await taskViewModel.createTask(message);
widget.viewModel.setCurrentTaskId(newTaskId);
widget.viewModel
.sendChatMessage((message == "") ? null : message);
widget.viewModel.sendChatMessage(
(message == "") ? null : message,
continuousModeSteps:
Provider.of<SettingsViewModel>(context, listen: false)
.continuousModeSteps);
}
},
onContinuousModePressed: () {
Expand Down

0 comments on commit ffa76c3

Please sign in to comment.