feat: tools implementation
This commit is contained in:
@@ -24,6 +24,9 @@ class ApiService {
|
||||
late final ApiAuthInterceptor _authInterceptor;
|
||||
// Removed legacy websocket/socket.io fields
|
||||
|
||||
// Public getter for dio instance
|
||||
Dio get dio => _dio;
|
||||
|
||||
// Callback to notify when auth token becomes invalid
|
||||
void Function()? onAuthTokenInvalid;
|
||||
|
||||
@@ -2415,7 +2418,7 @@ class ApiService {
|
||||
required List<Map<String, dynamic>> messages,
|
||||
required String model,
|
||||
String? conversationId,
|
||||
List<Map<String, dynamic>>? tools,
|
||||
List<String>? toolIds,
|
||||
bool enableWebSearch = false,
|
||||
Map<String, dynamic>? modelItem,
|
||||
}) {
|
||||
@@ -2500,6 +2503,12 @@ class ApiService {
|
||||
debugPrint('DEBUG: Web search enabled in SSE request');
|
||||
}
|
||||
|
||||
// Add tool_ids if provided (Open-WebUI expects tool_ids as array of strings)
|
||||
if (toolIds != null && toolIds.isNotEmpty) {
|
||||
data['tool_ids'] = toolIds;
|
||||
debugPrint('DEBUG: Including tool_ids in SSE request: $toolIds');
|
||||
}
|
||||
|
||||
// Don't add session_id or id - they break SSE streaming!
|
||||
// The server falls back to task-based async when these are present
|
||||
|
||||
|
||||
29
lib/core/services/tools_service.dart
Normal file
29
lib/core/services/tools_service.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:conduit/core/models/tool.dart';
|
||||
import 'package:conduit/core/services/api_service.dart';
|
||||
import 'package:conduit/core/error/api_error_handler.dart';
|
||||
import 'package:conduit/core/providers/app_providers.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
class ToolsService {
|
||||
final ApiService _apiService;
|
||||
|
||||
ToolsService(this._apiService);
|
||||
|
||||
Future<List<Tool>> getTools() async {
|
||||
try {
|
||||
final response = await _apiService.dio.get('/api/v1/tools/');
|
||||
return (response.data as List)
|
||||
.map((json) => Tool.fromJson(json))
|
||||
.toList();
|
||||
} on DioException catch (e) {
|
||||
throw ApiErrorHandler().transformError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final toolsServiceProvider = Provider<ToolsService?>((ref) {
|
||||
final apiService = ref.watch(apiServiceProvider);
|
||||
if (apiService == null) return null;
|
||||
return ToolsService(apiService);
|
||||
});
|
||||
Reference in New Issue
Block a user