feat(api): pass userSettings respect function_calling preference in
This commit is contained in:
@@ -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 userParams = userSettings?['params'] as Map<String, dynamic>?;
|
||||||
|
final functionCallingMode = userParams?['function_calling'] as String?;
|
||||||
|
|
||||||
|
if (functionCallingMode != null) {
|
||||||
final params =
|
final params =
|
||||||
(data['params'] as Map<String, dynamic>?) ?? <String, dynamic>{};
|
(data['params'] as Map<String, dynamic>?) ?? <String, dynamic>{};
|
||||||
params['function_calling'] = 'native';
|
params['function_calling'] = functionCallingMode;
|
||||||
data['params'] = params;
|
data['params'] = params;
|
||||||
_traceApi('Set params.function_calling = native');
|
_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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user