Skip to content

Conversation

toshiossada
Copy link
Contributor

@toshiossada toshiossada commented Apr 30, 2025

When request was finished it's not possible to trigger a callback, with this fix it's possible to give a callback onFunctionCalls geting the list of FunctionCall

Example how to use

  late final _provider = GeminiProvider(
    model: gemini,
    chatGenerationConfig: GenerationConfig(),
    chatSafetySettings: [],
    onFunctionCalls: (functionCalls) {
      for (var function in functionCalls) {
        final result =
            GeminiTools().handleFunctionCall(function.name, function.args);

        if (!result.success) {
          ScaffoldMessenger.of(context).showSnackBar(
            SnackBar(
              content: Text('Erro: ${result.reason}'),
              backgroundColor: Colors.red,
            ),
          );
        } else {
          model = result;
        }
        setState(() {});
      }
    },
  );

#98

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read the [Flutter Style Guide] recently, and have followed its advice.
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on [Discord].

@csells
Copy link
Contributor

csells commented Apr 30, 2025

@toshiossada that's pretty great. a couple of changes I'd like to see made:

  1. this should be added to the vertex provider as well
  2. I'm not quite on board with onDone -- I'm thinking something like onFunctionCall or onToolCall.

@toshiossada
Copy link
Contributor Author

2. I'm not quite on board with onDone

I used 'onDone' because this is a callback will be triggered when request finish, don't necessarily for functionCall ou ToolCall

@csells
Copy link
Contributor

csells commented Apr 30, 2025

I know. It should be. Otherwise why are you passing back only the last chunk response object?

@toshiossada
Copy link
Contributor Author

Whats do you sugest?

@csells
Copy link
Contributor

csells commented May 1, 2025

I'm thinking something like onFunctionCalls or onToolCalls

@toshiossada
Copy link
Contributor Author

toshiossada commented May 1, 2025

I'm thinking something like onFunctionCalls or onToolCalls

ok, DONE!

@toshiossada
Copy link
Contributor Author

@csells anything else?

@toshiossada toshiossada changed the title Creating onDone Callback Creating onFunctionCalls Callback May 2, 2025
@csells csells self-assigned this May 12, 2025
@csells csells merged commit a96a0fe into flutter:main May 12, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants