Skip to content
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

Feature suggestion: create a Tool object from a C# method #23

Open
doggy8088 opened this issue Mar 30, 2024 · 4 comments
Open

Feature suggestion: create a Tool object from a C# method #23

doggy8088 opened this issue Mar 30, 2024 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@doggy8088
Copy link
Contributor

When using function calling feature for Gemini API, the Tool must be used.

Here is a thought of mine. Is it possible just simple pass a C# method or lambda or it's method type to the GenerateContent method's tools argument. Your library might be able to convert the method into a Tool object. That will be extremely useful.

Furthermore, it's possibly call that method directly when the Gemini API response with that method calls.

@jochenkirstaetter jochenkirstaetter added enhancement New feature or request help wanted Extra attention is needed labels Mar 30, 2024
@jochenkirstaetter
Copy link
Contributor

Hi @doggy8088
That sounds like a great idea. I've seen something like this in one of the other .NET-based SDKs where the developer used one or more Attribute marker to handle function calling. I'll put it in the backlog.

Thanks for the suggestion.

@fobos531
Copy link

Hey @jochenkirstaetter - just wanted to check, what are your current plans regarding this? I'd love to use function calling with this library.

@jochenkirstaetter
Copy link
Contributor

Hi @fobos531

Thanks for using the SDK.
The issue has been tagged with help wanted. I'd really love to improve the handling. Right now, one has to provide the function declarations, parameters, etc as pure Javascript objects in order to get it to work.

Similar to the recent changes regarding JSON response schema I'd like to implement some functionality, maybe using an attribute to mark methods, that generates the tool definitions.

Any hints are most welcome and appreciated.

@jochenkirstaetter
Copy link
Contributor

Hi @doggy8088 and @fobos531

Making progress on this task. I wrote a new custom JSON converter to generate the FunctionDeclarations. There is still some work to do, like i.e. switching to chat session and actually invoking the detected function call.

However, it's going to look similar to this.

var prompt = "It is too bright. Change it.";
var googleAi = new GoogleAI(apiKey: fixture.ApiKey);
var model = googleAi.GenerativeModel(model: _model);
var tools = new Tools();
tools.AddFunction(ToggleDarkMode);

var response = await model.GenerateContent(prompt, tools: tools);

Currently, serialization works as expected and Gemini API returns the function_call based on the generated declarations.

I'm hoping to complete this by the beginning of the coming week.

Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants