diff --git a/frontend/lib/utils/rest_api_utility.dart b/frontend/lib/utils/rest_api_utility.dart index 6884f80600e2..bf1a4d7b7b97 100644 --- a/frontend/lib/utils/rest_api_utility.dart +++ b/frontend/lib/utils/rest_api_utility.dart @@ -1,18 +1,26 @@ import 'dart:convert'; import 'dart:typed_data'; +import 'package:auto_gpt_flutter_client/models/benchmark_service/api_type.dart'; import 'package:http/http.dart' as http; class RestApiUtility { - String _baseUrl; + String _agentBaseUrl; + final String _benchmarkBaseUrl = "http://127.0.0.1:8080"; - RestApiUtility(this._baseUrl); + RestApiUtility(this._agentBaseUrl); void updateBaseURL(String newBaseURL) { - _baseUrl = newBaseURL; + _agentBaseUrl = newBaseURL; } - Future> get(String endpoint) async { - final response = await http.get(Uri.parse('$_baseUrl/$endpoint')); + String _getEffectiveBaseUrl(ApiType apiType) { + return apiType == ApiType.agent ? _agentBaseUrl : _benchmarkBaseUrl; + } + + Future> get(String endpoint, + {ApiType apiType = ApiType.agent}) async { + final effectiveBaseUrl = _getEffectiveBaseUrl(apiType); + final response = await http.get(Uri.parse('$effectiveBaseUrl/$endpoint')); if (response.statusCode == 200) { return json.decode(response.body); } else { @@ -21,9 +29,11 @@ class RestApiUtility { } Future> post( - String endpoint, Map payload) async { + String endpoint, Map payload, + {ApiType apiType = ApiType.agent}) async { + final effectiveBaseUrl = _getEffectiveBaseUrl(apiType); final response = await http.post( - Uri.parse('$_baseUrl/$endpoint'), + Uri.parse('$effectiveBaseUrl/$endpoint'), body: json.encode(payload), headers: {"Content-Type": "application/json"}, ); @@ -34,9 +44,11 @@ class RestApiUtility { } } - Future getBinary(String endpoint) async { + Future getBinary(String endpoint, + {ApiType apiType = ApiType.agent}) async { + final effectiveBaseUrl = _getEffectiveBaseUrl(apiType); final response = await http.get( - Uri.parse('$_baseUrl/$endpoint'), + Uri.parse('$effectiveBaseUrl/$endpoint'), headers: {"Content-Type": "application/octet-stream"}, );