createSession method
Future<String>
createSession({
- String? systemInstruction,
- List<
OnDeviceAiTool> ? tools, - GenerationConfig? config,
override
Creates a conversation and returns its id.
tools is non-null only when the backend reported native tool calling.
Implementation
@override
Future<String> createSession({
String? systemInstruction,
List<OnDeviceAiTool>? tools,
GenerationConfig? config,
}) async {
final id = _newSessionId();
if (tools != null && tools.isNotEmpty) {
_toolsBySession[id] = {for (final t in tools) t.name: t};
}
try {
await _invoke<void>('createSession', {
'sessionId': id,
'systemInstruction': ?systemInstruction,
'tools': ?tools?.map((t) => t.toMap()).toList(),
'config': ?config?.toMap(),
});
} catch (_) {
_toolsBySession.remove(id);
rethrow;
}
return id;
}