I want to build a django application that uses Google Gemini API at the backend. The challenge I have is that , the function call parameters change ( though very rarely ) based on a database entry. consider I have an enum as input arg to the function and whenever a new row is created I want to add new enum to this function definition. so this change take place quickly. but unfortunately this doesn’t happen, instead the Gemini responds with response that looks it doesn’t know about the change.
Note
- I have configured the the flow to call genai.GenerativeModel for every new request and verified that self.function_collection.getdef() returns the updated function definition when I update the a row.
self.model = genai.GenerativeModel(
model_name=config('GEMINI_MODEL_NAME'),
generation_config={
"temperature":config('TEMPERATURE',cast=float),
"top_p": config('TOP_P',cast=int),
"top_k": config('TOP_K',cast=int),
"max_output_tokens": config('MAX_OUTPUT_TOKENS',cast=int),
"response_mime_type": "text/plain",
},
tools=[{
'function_declarations': self.function_collection.getdef(),
}],
)
-
If I restart django development server this change will be quickly considered. but I can’t do this in production.
-
Also I have verified this change is available to the model using the following
chat_session = self.model.start_chat(history=self.history)
print("tools avaialbe",self.model._tools.to_proto())
print("function def",self.function_collection.getdef())
print("tools avaialbe in session before ",chat_session.model._tools.to_proto())
response = chat_session.send_message(query)
print("tools avaialbe in session after ",chat_session.model._tools.to_proto())
I verified that the updated function declaration is available in both
print("tools avaialbe in session before ",chat_session.model._tools.to_proto())
and
print("tools avaialbe in session after ",chat_session.model._tools.to_proto())
Can someone help me fix this issue. I want the change to take place quickly.