@@ -651,33 +651,30 @@ steps:
651651 +import 'gemini_tools.dart';
652652
653653 part 'gemini_chat_service.g.dart';
654-
655- @@ -33,6 +34,30 @@ class GeminiChatService {
654+
655+ @@ -33,6 +34,27 @@ class GeminiChatService {
656656 logStateNotifier.logLlmText(responseText);
657657 chatStateNotifier.appendToMessage(llmMessage.id, responseText);
658658 }
659659 +
660660 + if (response.functionCalls.isNotEmpty) {
661661 + final geminiTools = ref.read(geminiToolsProvider);
662- + final results = <(String, Map<String, Object?>)>[];
663- + for (final functionCall in response.functionCalls) {
664- + results.add((
665- + functionCall.name,
666- + geminiTools.handleFunctionCall(
667- + functionCall.name,
668- + functionCall.args,
669- + ),
670- + ));
671- + final response = await chatSession.sendMessage(
672- + Content.functionResponses(
673- + results.map((result) => FunctionResponse(result.$1, result.$2)),
674- + ),
675- + );
676- + final responseText = response.text;
677- + if (responseText != null) {
678- + logStateNotifier.logLlmText(responseText);
679- + chatStateNotifier.appendToMessage(llmMessage.id, responseText);
680- + }
662+ + final functionResultResponse = await chatSession.sendMessage(
663+ + Content.functionResponses([
664+ + for (final functionCall in response.functionCalls)
665+ + FunctionResponse(
666+ + functionCall.name,
667+ + geminiTools.handleFunctionCall(
668+ + functionCall.name,
669+ + functionCall.args,
670+ + ),
671+ + ),
672+ + ]),
673+ + );
674+ + final responseText = functionResultResponse.text;
675+ + if (responseText != null) {
676+ + logStateNotifier.logLlmText(responseText);
677+ + chatStateNotifier.appendToMessage(llmMessage.id, responseText);
681678 + }
682679 + }
683680 } catch (e, st) {
@@ -762,8 +759,8 @@ steps:
762759 patch-u : |
763760 --- b/colorist/step_06/lib/services/gemini_chat_service.dart
764761 +++ a/colorist/step_06/lib/services/gemini_chat_service.dart
765- @@ -14,49 +14,41 @@ import 'gemini_tools.dart';
766-
762+ @@ -14,46 +14,41 @@ import 'gemini_tools.dart';
763+
767764 part 'gemini_chat_service.g.dart';
768765
769766 +final conversationStateProvider = StateProvider(
@@ -806,25 +803,22 @@ steps:
806803 -
807804 - if (response.functionCalls.isNotEmpty) {
808805 - final geminiTools = ref.read(geminiToolsProvider);
809- - final results = <(String, Map<String, Object?>)>[];
810- - for (final functionCall in response.functionCalls) {
811- - results.add((
812- - functionCall.name,
813- - geminiTools.handleFunctionCall(
814- - functionCall.name,
815- - functionCall.args,
816- - ),
817- - ));
818- - final response = await chatSession.sendMessage(
819- - Content.functionResponses(
820- - results.map((result) => FunctionResponse(result.$1, result.$2)),
821- - ),
822- - );
823- - final responseText = response.text;
824- - if (responseText != null) {
825- - logStateNotifier.logLlmText(responseText);
826- - chatStateNotifier.appendToMessage(llmMessage.id, responseText);
827- - }
806+ - final functionResultResponse = await chatSession.sendMessage(
807+ - Content.functionResponses([
808+ - for (final functionCall in response.functionCalls)
809+ - FunctionResponse(
810+ - functionCall.name,
811+ - geminiTools.handleFunctionCall(
812+ - functionCall.name,
813+ - functionCall.args,
814+ - ),
815+ - ),
816+ - ]),
817+ - );
818+ - final responseText = functionResultResponse.text;
819+ - if (responseText != null) {
820+ - logStateNotifier.logLlmText(responseText);
821+ - chatStateNotifier.appendToMessage(llmMessage.id, responseText);
828822 - }
829823 + final responseStream = chatSession.sendMessageStream(
830824 + Content.text(message),
@@ -834,7 +828,7 @@ steps:
834828 }
835829 } catch (e, st) {
836830 logStateNotifier.logError(e, st: st);
837- @@ -66 ,6 +58,45 @@ class GeminiChatService {
831+ @@ -63 ,6 +58,45 @@ class GeminiChatService {
838832 );
839833 } finally {
840834 chatStateNotifier.finalizeMessage(llmMessage.id);
@@ -858,17 +852,17 @@ steps:
858852 +
859853 + if (block.functionCalls.isNotEmpty) {
860854 + final geminiTools = ref.read(geminiToolsProvider);
861- + final results = <(String, Map<String, Object?>)>[];
862- + for (final functionCall in block.functionCalls) {
863- + results.add((
864- + functionCall.name,
865- + geminiTools.handleFunctionCall(functionCall.name, functionCall.args),
866- + ));
867- + }
868855 + final responseStream = chatSession.sendMessageStream(
869- + Content.functionResponses(
870- + results.map((result) => FunctionResponse(result.$1, result.$2)),
871- + ),
856+ + Content.functionResponses([
857+ + for (final functionCall in block.functionCalls)
858+ + FunctionResponse(
859+ + functionCall.name,
860+ + geminiTools.handleFunctionCall(
861+ + functionCall.name,
862+ + functionCall.args,
863+ + ),
864+ + ),
865+ + ]),
872866 + );
873867 + await for (final response in responseStream) {
874868 + final responseText = response.text;
0 commit comments