feat(api): pass userSettings respect function_calling preference in

This commit is contained in:
cogwheel0
2025-10-26 23:00:01 +05:30
parent ae48fcc035
commit 5ab3b9c4e0
2 changed files with 18 additions and 8 deletions

View File

@@ -3093,6 +3093,7 @@ class ApiService {
List<Map<String, dynamic>>? toolServers, List<Map<String, dynamic>>? toolServers,
Map<String, dynamic>? backgroundTasks, Map<String, dynamic>? backgroundTasks,
String? responseMessageId, String? responseMessageId,
Map<String, dynamic>? userSettings,
}) { }) {
final streamController = StreamController<String>(); final streamController = StreamController<String>();
@@ -3199,16 +3200,23 @@ class ApiService {
data['tool_ids'] = toolIds; data['tool_ids'] = toolIds;
_traceApi('Including tool_ids in streaming request: $toolIds'); _traceApi('Including tool_ids in streaming request: $toolIds');
// Hint server to use native function calling when tools are selected // Respect user's function_calling preference from backend settings
// This enables provider-native tool execution paths and consistent UI events // If not set, backend will default to 'default' mode (safer, more compatible)
try { try {
final params = final userParams = userSettings?['params'] as Map<String, dynamic>?;
(data['params'] as Map<String, dynamic>?) ?? <String, dynamic>{}; final functionCallingMode = userParams?['function_calling'] as String?;
params['function_calling'] = 'native';
data['params'] = params; if (functionCallingMode != null) {
_traceApi('Set params.function_calling = native'); final params =
(data['params'] as Map<String, dynamic>?) ?? <String, dynamic>{};
params['function_calling'] = functionCallingMode;
data['params'] = params;
_traceApi('Set params.function_calling = $functionCallingMode (from user settings)');
} else {
_traceApi('No function_calling preference in user settings, backend will use default mode');
}
} catch (_) { } catch (_) {
// Non-fatal; continue without forcing native mode // Non-fatal; continue without setting function_calling mode
} }
} }

View File

@@ -1414,6 +1414,7 @@ Future<void> regenerateMessage(
toolServers: toolServers, toolServers: toolServers,
backgroundTasks: bgTasks, backgroundTasks: bgTasks,
responseMessageId: assistantMessageId, responseMessageId: assistantMessageId,
userSettings: userSettingsData,
); );
final stream = response.stream; final stream = response.stream;
@@ -1959,6 +1960,7 @@ Future<void> _sendMessageInternal(
toolServers: toolServers, toolServers: toolServers,
backgroundTasks: bgTasks, backgroundTasks: bgTasks,
responseMessageId: assistantMessageId, responseMessageId: assistantMessageId,
userSettings: userSettingsData,
); );
final stream = response.stream; final stream = response.stream;