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

Is Function Calling possible? #81

Open
jaydanurwin opened this issue Feb 19, 2024 · 15 comments
Open

Is Function Calling possible? #81

jaydanurwin opened this issue Feb 19, 2024 · 15 comments

Comments

@jaydanurwin
Copy link

I've looked into the samples a bit and the available params but I'm not seeing anything about function calling/tools. Is this already possible and I'm missing it or is it planned to be supported? It would be awesome to be able to call local Dart functions through Gemini similar to how it appears to be possible with Python or a REST API

@MrCsabaToth
Copy link

Badly needed

@davidmigloz
Copy link
Contributor

It's already supported.
https://ai.google.dev/gemini-api/docs/function-calling/tutorial?lang=dart

@MrCsabaToth
Copy link

That'd be dope! I'll try that next week!

@adamglin0
Copy link

adamglin0 commented Jun 17, 2024

It's already supported. https://ai.google.dev/gemini-api/docs/function-calling/tutorial?lang=dart

I try function call by this post, but is not works.
Gemini return this:

I need to access a live exchange rate API to answer your question. I do not have access to real-time information, including currency exchange rates.  Therefore, I cannot provide you with the current exchange rate for US dollars to Swedish krona. 

To get the most up-to-date information, I recommend checking a reliable online converter or your bank's website. 

@MrCsabaToth
Copy link

I try function call by this post, but is not works. Gemini return this:

I need to access a live exchange rate API to answer your question. I do not have access to real-time information, including currency exchange rates.  Therefore, I cannot provide you with the current exchange rate for US dollars to Swedish krona. 

To get the most up-to-date information, I recommend checking a reliable online converter or your bank's website. 

What's the code you are configuring the function / tool with, and then calling Gemini?

@adamglin0
Copy link

@MrCsabaToth

Sorry, if I set model as 'gemini-1.5-flash' it works!

@MrCsabaToth
Copy link

@MrCsabaToth

Sorry, if I set model as 'gemini-1.5-flash' it works!

No problem but I'm still highly interested in the source code

@MrCsabaToth
Copy link

MrCsabaToth commented Jul 12, 2024

Actually now I'm at the point that I'm trying function calling and it doesn't seem to be working. I was providing a function to retrieve weather data. I tried both gemini-1.5-flash-latest and gemini-1.5-pro-latest with the prompt "What is the weather today?", and I got back I am sorry, I cannot provide you with the weather information. I do not have access to real-time data like weather conditions.. Note that I also provide a tool to retrieve the location.

@adamglin0
Copy link

Actually now I'm at the point that I'm trying function calling and it doesn't seem to be working. I was providing a function to retrieve weather data. I tried both gemini-flash-lates and gemini-pro-latest with the prompt "What is the weather today?", and I got back I am sorry, I cannot provide you with the weather information. I do not have access to real-time data like weather conditions.. Note that I also provide a tool to retrieve the location.

Do you add function_calling_config parameter? Try to delete this.

@MrCsabaToth
Copy link

Actually now I'm at the point that I'm trying function calling and it doesn't seem to be working. I was providing a function to retrieve weather data. I tried both gemini-flash-lates and gemini-pro-latest with the prompt "What is the weather today?", and I got back I am sorry, I cannot provide you with the weather information. I do not have access to real-time data like weather conditions.. Note that I also provide a tool to retrieve the location.

Do you add function_calling_config parameter? Try to delete this.

No, do you have some code by any chance?
function_calling_config seems to be Pythonic, we are in Dart land here. However the Dart API also has a FunctionCallingMode. It has modes: auto, any, and none. any forces a function call, auto supposed to be the default. I'll try to add a toolConfig: ToolConfig(functionCallingConfig: FunctionCallingConfig(mode: FunctionCallingMode.auto)) during model instantiation. Unlike the Python and some other language APIs the chat instantiation doesn't have a parameter like start_chat(enable_automatic_function_calling=True) in Python. The Dart startChat only has history, safetySettings, and generationCOnfig. This latter doesn't have function call related settings in it.

@adamglin0 How did you solve the problem?

@MrCsabaToth
Copy link

I tested explicitly specifying toolConfig: ToolConfig(functionCallingConfig: FunctionCallingConfig(mode: FunctionCallingMode.auto)) and it didn't help.
My source code: https://github.com/CsabaConsulting/InspectorGadgetApp/blob/21cfcc45436dd1c155c703183d22c0239376ee56/lib/interaction/view/interaction_page.dart#L257

@adamglin0
Copy link

Actually now I'm at the point that I'm trying function calling and it doesn't seem to be working. I was providing a function to retrieve weather data. I tried both gemini-flash-lates and gemini-pro-latest with the prompt "What is the weather today?", and I got back I am sorry, I cannot provide you with the weather information. I do not have access to real-time data like weather conditions.. Note that I also provide a tool to retrieve the location.

Do you add function_calling_config parameter? Try to delete this.

No, do you have some code by any chance? function_calling_config seems to be Pythonic, we are in Dart land here. However the Dart API also has a FunctionCallingMode. It has modes: auto, any, and none. any forces a function call, auto supposed to be the default. I'll try to add a toolConfig: ToolConfig(functionCallingConfig: FunctionCallingConfig(mode: FunctionCallingMode.auto)) during model instantiation. Unlike the Python and some other language APIs the chat instantiation doesn't have a parameter like start_chat(enable_automatic_function_calling=True) in Python. The Dart startChat only has history, safetySettings, and generationCOnfig. This latter doesn't have function call related settings in it.

@adamglin0 How did you solve the problem?

Let me find my old code, this will take some time.

@adamglin0
Copy link

@MrCsabaToth I can no longer reproduce the issue. But I can tell you how I resolved it.

  1. After I found the same error, I tried this document.

But still not successful.

  1. Then I found that my GenerativeModel section seemed different from the one in the document, so I copied part of the model and it worked. https://ai.google.dev/gemini-api/docs/function-calling/tutorial?hl=zh-cn&lang=dart

  2. Later, after leaving a message on this issue, I modified the value of the model, but then realized that I wrote toolConfig in GenerativeModel (it seems like this because there is no git record).

  3. Now I cannot reproduce it anymore, sorry for that

@MrCsabaToth
Copy link

Reporting back about what I've found out: @adamglin0 was exactly right here #81 (comment)

If I go with gemini-1.5-flash or gemini-1.5-pro instead of gemini-1.5-flash-latest or gemini-1.5-pro-latest (so not using the -latest model name prefix) the tool functionality seems to be waking up. Now I'm getting I need to know your location to get the weather forecast. Can you tell me your latitude and longitude?. So it is probably seeing my weather function, however it misses the location function which would exactly provide the lat / long.

Since https://github.com/google-gemini/generative-ai-dart/blob/main/samples/dart/bin/function_calling.dart demonstrates a function call chain possibility, I expect the model to figure out the two step of first calling the location function for the lat long GPS, and then use those as parameters to call the weather function.

@MrCsabaToth
Copy link

I'm dealing with a problem with multiple tools: #194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants