From 6651151fa229f0f4caed195365ce87a9f57a8736 Mon Sep 17 00:00:00 2001 From: MrCsabaToth Date: Sun, 29 Sep 2024 22:03:34 -0700 Subject: [PATCH] Solving the "Please ensure that function call turn comes immediately after a user turn or after a function response turn." problem #53 #56 --- lib/ai/service/ai_service.dart | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lib/ai/service/ai_service.dart b/lib/ai/service/ai_service.dart index 654f19f..06bfbb8 100644 --- a/lib/ai/service/ai_service.dart +++ b/lib/ai/service/ai_service.dart @@ -260,7 +260,6 @@ class AiService with FirebaseMixin, ToolsMixin { } List functionCalls; - var content = Content.text(''); while ((functionCalls = response.functionCalls.toList()).isNotEmpty) { final responses = []; for (final functionCall in functionCalls) { @@ -281,11 +280,10 @@ class AiService with FirebaseMixin, ToolsMixin { } } - content = response.candidates.first.content; - content.parts.addAll(responses); + message.parts.addAll(responses); // TODO(MrCsabaToth): Store in history? try { - response = await chat.sendMessage(content); + response = await chat.sendMessage(message); } catch (e) { log('Exception during function iteration chat.sendMessage: $e'); return null;