mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-01-08 08:44:23 +01:00
Update ViewModel classes for Chat and Task to handle structured responses
This commit updates the ViewModel classes for both Chat and Task to accommodate the new structured responses received from the API. These changes are essential for the correct functioning of the application as they deal with the new TaskResponse and Step objects. Updates in ChatViewModel: - Modified `fetchChatsForTask` to handle structured step data - Updated how steps are retrieved and processed Updates in TaskViewModel: - Updated `fetchTasks` to use the new TaskResponse object - Refactored task fetching and selection logic These updates ensure that the ViewModel classes are aligned with the new structured API responses, improving data handling and UI updates.
This commit is contained in:
@@ -38,9 +38,12 @@ class ChatViewModel with ChangeNotifier {
|
||||
}
|
||||
try {
|
||||
// Fetch task steps from the data source
|
||||
final List<dynamic> stepsJsonList =
|
||||
final Map<String, dynamic> stepsResponse =
|
||||
await _chatService.listTaskSteps(_currentTaskId!);
|
||||
|
||||
// Extract steps from the response
|
||||
final List<dynamic> stepsJsonList = stepsResponse['steps'] ?? [];
|
||||
|
||||
// Convert each map into a Step object
|
||||
List<Step> steps =
|
||||
stepsJsonList.map((stepMap) => Step.fromMap(stepMap)).toList();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:auto_gpt_flutter_client/models/task.dart';
|
||||
import 'package:auto_gpt_flutter_client/models/task_response.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:auto_gpt_flutter_client/services/task_service.dart';
|
||||
@@ -45,13 +46,9 @@ class TaskViewModel with ChangeNotifier {
|
||||
/// Fetches tasks from the data source.
|
||||
void fetchTasks() async {
|
||||
try {
|
||||
final fetchedTasks = await _taskService.listAllTasks();
|
||||
_tasks = fetchedTasks.map((taskMap) {
|
||||
return Task(
|
||||
id: taskMap['task_id'].toString(),
|
||||
title: taskMap['output'].toString(),
|
||||
);
|
||||
}).toList();
|
||||
final TaskResponse tasksResponse = await _taskService.listAllTasks();
|
||||
_tasks = tasksResponse.tasks;
|
||||
|
||||
notifyListeners();
|
||||
print("Tasks fetched successfully!");
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user