I know that Function calling is still beta or testing.
I have tried to test it with streaming:
from google.generativeai.types import GenerationConfig
from dotenv import load_dotenv
import google.generativeai as genai
import os
load_dotenv()
GOOGLE_API_KEY = os.getenv("API_KEY")
genai.configure(api_key=GOOGLE_API_KEY)
def add(a: float, b: float):
"""returns a + b."""
return a + b
model = genai.GenerativeModel(model_name="gemini-1.5-flash")
response = model.generate_content(
"What is 4 + 3?",
stream=True,
tools=[add],
generation_config=GenerationConfig(stop_sequences=["Anything"]),
)
for chunk in response:
print(chunk.parts)
print("_" * 80)
Results:
[text: “print(default_api.add(a = 4, b = 3))”]
Which is a text response and not a function response. We can see this by switching stream=False,
Run it again and you get a proper function response.
[function_call {
name: "add"
args {
fields {
key: "b"
value {
number_value: 3
}
}
fields {
key: "a"
value {
number_value: 4
}
}
}
}
]
________________________________________________________________________________
#justcurous if its even supported at this point.