Hey, I am facing this issue where this program is working properly without function calling
but showing an error when using function calling.
I have attached the stack trace after the code.
import google.generativeai as genai
import google.ai.generativelanguage as glm
from dotenv import load_dotenv
from FunctionsHandler import FunctionsProcessor
import os
load_dotenv()
# def save_context(title, content):
# """ This function saves the context to the memory. """
# return FunctionsProcessor.save_context(title, content)
# def make_query(query):
# """ This function queries information from the memory. """
# return FunctionsProcessor.make_query(query)
# def service_query(query):
# """ This function queries information about the services from the memory to make it easy to use call_service. """
# return FunctionsProcessor.service_query(query)
# def call_service(service_name, task_type, extra):
# """ This function calls services as per requirements."""
# return FunctionsProcessor.call_service(service_name, task_type, extra)
def print_hello_world():
print("Hello World!")
return "Done"
genai.configure(api_key=os.getenv('GEMINI_API_KEY'))
# funcs = [save_context, make_query, call_service, service_query]
model = genai.GenerativeModel(
model_name = 'gemini-1.5-flash-latest',
tools = print_hello_world)
chat = model.start_chat(enable_automatic_function_calling = True)
response = chat.send_message("HELLLOOOOOOO!")
print(response.text)
Here’s the error:
Traceback (most recent call last):
File "/home/disguisedg/Documents/DITOS/tryingout.py", line 42, in <module>
response = chat.send_message("HELLLOOOOOOO!")
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/generativeai/generative_models.py", line 578, in send_message
response = self.model.generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/generativeai/generative_models.py", line 331, in generate_content
response = self._client.generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/ai/generativelanguage_v1beta/services/generative_service/client.py", line 827, in generate_content
response = rpc(
^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/api_core/gapic_v1/method.py", line 131, in __call__
return wrapped_func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/api_core/retry/retry_unary.py", line 293, in retry_wrapped_func
return retry_target(
^^^^^^^^^^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/api_core/retry/retry_unary.py", line 153, in retry_target
_retry_error_helper(
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/api_core/retry/retry_base.py", line 212, in _retry_error_helper
raise final_exc from source_exc
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/api_core/retry/retry_unary.py", line 144, in retry_target
result = target()
^^^^^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/api_core/timeout.py", line 120, in func_with_timeout
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/home/disguisedg/Documents/DITOS/DITOS_VENV/lib/python3.11/site-packages/google/api_core/grpc_helpers.py", line 78, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.InvalidArgument: 400 Request contains an invalid argument.