From 5ab3b9c4e0137ba4357683709e39171be41385b3 Mon Sep 17 00:00:00 2001 From: cogwheel0 <172976095+cogwheel0@users.noreply.github.com> Date: Sun, 26 Oct 2025 23:00:01 +0530 Subject: [PATCH] feat(api): pass userSettings respect function_calling preference in --- lib/core/services/api_service.dart | 24 ++++++++++++------- .../chat/providers/chat_providers.dart | 2 ++ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/core/services/api_service.dart b/lib/core/services/api_service.dart index 34e9152..e42649f 100644 --- a/lib/core/services/api_service.dart +++ b/lib/core/services/api_service.dart @@ -3093,6 +3093,7 @@ class ApiService { List>? toolServers, Map? backgroundTasks, String? responseMessageId, + Map? userSettings, }) { final streamController = StreamController(); @@ -3199,16 +3200,23 @@ class ApiService { data['tool_ids'] = toolIds; _traceApi('Including tool_ids in streaming request: $toolIds'); - // Hint server to use native function calling when tools are selected - // This enables provider-native tool execution paths and consistent UI events + // Respect user's function_calling preference from backend settings + // If not set, backend will default to 'default' mode (safer, more compatible) try { - final params = - (data['params'] as Map?) ?? {}; - params['function_calling'] = 'native'; - data['params'] = params; - _traceApi('Set params.function_calling = native'); + final userParams = userSettings?['params'] as Map?; + final functionCallingMode = userParams?['function_calling'] as String?; + + if (functionCallingMode != null) { + final params = + (data['params'] as Map?) ?? {}; + 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 (_) { - // Non-fatal; continue without forcing native mode + // Non-fatal; continue without setting function_calling mode } } diff --git a/lib/features/chat/providers/chat_providers.dart b/lib/features/chat/providers/chat_providers.dart index 31a691f..aa19ad8 100644 --- a/lib/features/chat/providers/chat_providers.dart +++ b/lib/features/chat/providers/chat_providers.dart @@ -1414,6 +1414,7 @@ Future regenerateMessage( toolServers: toolServers, backgroundTasks: bgTasks, responseMessageId: assistantMessageId, + userSettings: userSettingsData, ); final stream = response.stream; @@ -1959,6 +1960,7 @@ Future _sendMessageInternal( toolServers: toolServers, backgroundTasks: bgTasks, responseMessageId: assistantMessageId, + userSettings: userSettingsData, ); final stream = response.stream;