mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-28 03:14:32 +01:00
Introduce ChatService Class for Chat Operations
This commit adds a new ChatService class to handle all chat-related operations, including steps and artifacts. - Implemented methods for executing a step within a task (executeStep). - Added functionality to retrieve details for a specific step (getStepDetails). - Enabled listing all steps for a specific task with optional pagination (listTaskSteps). - Laid groundwork for artifact uploading (uploadArtifact) and downloading (downloadArtifact), though these are not implemented yet. By encapsulating these operations within the ChatService class, this commit provides a clean and centralized way to interact with the backend for chat functionalities, making the application more maintainable and easier to extend.
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
import 'dart:io';
|
||||
import 'package:auto_gpt_flutter_client/models/step_request_body.dart';
|
||||
import 'package:auto_gpt_flutter_client/utils/rest_api_utility.dart';
|
||||
|
||||
/// Service class for performing chat-related operations.
|
||||
class ChatService {
|
||||
final RestApiUtility api;
|
||||
|
||||
ChatService(this.api);
|
||||
|
||||
/// Executes a step in a specific task.
|
||||
///
|
||||
/// [taskId] is the ID of the task.
|
||||
/// [stepRequestBody] is a Map representing the request body for executing a step.
|
||||
Future<Map<String, dynamic>> executeStep(
|
||||
String taskId, StepRequestBody stepRequestBody) async {
|
||||
try {
|
||||
return await api.post(
|
||||
'agent/tasks/$taskId/steps', stepRequestBody.toJson());
|
||||
} catch (e) {
|
||||
throw Exception('Failed to execute step: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets details about a specific task step.
|
||||
///
|
||||
/// [taskId] is the ID of the task.
|
||||
/// [stepId] is the ID of the step.
|
||||
Future<Map<String, dynamic>> getStepDetails(
|
||||
String taskId, String stepId) async {
|
||||
try {
|
||||
return await api.get('agent/tasks/$taskId/steps/$stepId');
|
||||
} catch (e) {
|
||||
throw Exception('Failed to get step details: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Lists all steps for a specific task.
|
||||
///
|
||||
/// [taskId] is the ID of the task.
|
||||
/// [currentPage] and [pageSize] are optional pagination parameters.
|
||||
Future<List<dynamic>> listTaskSteps(String taskId,
|
||||
{int currentPage = 1, int pageSize = 10}) async {
|
||||
try {
|
||||
return await api.getList(
|
||||
'agent/tasks/$taskId/steps?current_page=$currentPage&page_size=$pageSize');
|
||||
} catch (e) {
|
||||
throw Exception('Failed to list task steps: $e');
|
||||
}
|
||||
}
|
||||
|
||||
/// Uploads an artifact for a specific task.
|
||||
///
|
||||
/// [taskId] is the ID of the task.
|
||||
/// [artifactFile] is the File to be uploaded.
|
||||
/// [uri] is the URI of the artifact.
|
||||
Future<Map<String, dynamic>> uploadArtifact(
|
||||
String taskId, File artifactFile, String uri) async {
|
||||
return Future.value({'status': 'Not implemented yet'});
|
||||
}
|
||||
|
||||
/// Downloads a specific artifact.
|
||||
///
|
||||
/// [taskId] is the ID of the task.
|
||||
/// [artifactId] is the ID of the artifact.
|
||||
Future<Map<String, dynamic>> downloadArtifact(
|
||||
String taskId, String artifactId) async {
|
||||
return Future.value({'status': 'Not implemented yet'});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user