mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-31 04:44:33 +01:00
Refactor service classes to use api.get and handle structured responses
This commit updates the ChatService and TaskService classes to use the api.get method instead of the previous api.getList. This change allows us to handle structured API responses more effectively, particularly those containing pagination information and detailed task and step data. - Update ChatService methods to use api.get - Update TaskService methods to use api.get - Handle structured TaskResponse in TaskService.listAllTasks
This commit is contained in:
@@ -39,10 +39,10 @@ class ChatService {
|
||||
///
|
||||
/// [taskId] is the ID of the task.
|
||||
/// [currentPage] and [pageSize] are optional pagination parameters.
|
||||
Future<List<dynamic>> listTaskSteps(String taskId,
|
||||
Future<Map<String, dynamic>> listTaskSteps(String taskId,
|
||||
{int currentPage = 1, int pageSize = 10}) async {
|
||||
try {
|
||||
return await api.getList(
|
||||
return await api.get(
|
||||
'agent/tasks/$taskId/steps?current_page=$currentPage&page_size=$pageSize');
|
||||
} catch (e) {
|
||||
throw Exception('Failed to list task steps: $e');
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:auto_gpt_flutter_client/models/task_request_body.dart';
|
||||
import 'package:auto_gpt_flutter_client/models/task_response.dart';
|
||||
import 'package:auto_gpt_flutter_client/utils/rest_api_utility.dart';
|
||||
|
||||
/// Service class for performing task-related operations.
|
||||
@@ -23,11 +24,12 @@ class TaskService {
|
||||
///
|
||||
/// [currentPage] and [pageSize] are optional pagination parameters.
|
||||
///
|
||||
Future<List<dynamic>> listAllTasks(
|
||||
Future<TaskResponse> listAllTasks(
|
||||
{int currentPage = 1, int pageSize = 10}) async {
|
||||
try {
|
||||
return await api
|
||||
.getList('agent/tasks?current_page=$currentPage&page_size=$pageSize');
|
||||
final response = await api
|
||||
.get('agent/tasks?current_page=$currentPage&page_size=$pageSize');
|
||||
return TaskResponse.fromJson(response);
|
||||
} catch (e) {
|
||||
throw Exception('Failed to list all tasks: $e');
|
||||
}
|
||||
@@ -48,10 +50,10 @@ class TaskService {
|
||||
///
|
||||
/// [taskId] is the ID of the task.
|
||||
/// [currentPage] and [pageSize] are optional pagination parameters.
|
||||
Future<List<dynamic>> listTaskArtifacts(String taskId,
|
||||
Future<Map<String, dynamic>> listTaskArtifacts(String taskId,
|
||||
{int currentPage = 1, int pageSize = 10}) async {
|
||||
try {
|
||||
return await api.getList(
|
||||
return await api.get(
|
||||
'agent/tasks/$taskId/artifacts?current_page=$currentPage&page_size=$pageSize');
|
||||
} catch (e) {
|
||||
throw Exception('Failed to list task artifacts: $e');
|
||||
|
||||
Reference in New Issue
Block a user