Skip to content

Creating onFunctionCalls Callback #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

toshiossada
Copy link

@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
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
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
Author

toshiossada commented May 1, 2025

I'm thinking something like onFunctionCalls or onToolCalls

ok, DONE!

@toshiossada
Copy link
Author

@csells anything else?

@toshiossada toshiossada changed the title Creating onDone Callback Creating onFunctionCalls Callback May 2, 2025
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