Spaces:
Running
Running
Update agents.py
Browse files
agents.py
CHANGED
@@ -263,7 +263,7 @@ class GeminiAgent(LLMAgentBase):
|
|
263 |
try:
|
264 |
# Configure tools using the Gemini API format
|
265 |
tools = genai.types.Tool(function_declarations=self.function_declarations)
|
266 |
-
config = genai.types.GenerateContentConfig(tools=[tools])
|
267 |
|
268 |
# Send request to the model
|
269 |
response = self.genai_client.models.generate_content(
|
@@ -271,27 +271,16 @@ class GeminiAgent(LLMAgentBase):
|
|
271 |
contents=prompt,
|
272 |
config=config
|
273 |
)
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
hasattr(response.candidates[0], 'content') and
|
280 |
-
hasattr(response.candidates[0].content, 'parts') and
|
281 |
-
response.candidates[0].content.parts and
|
282 |
-
hasattr(response.candidates[0].content.parts[0], 'function_call')):
|
283 |
-
|
284 |
-
function_call = response.candidates[0].content.parts[0].function_call
|
285 |
-
function_name = function_call.name
|
286 |
-
# Get arguments
|
287 |
-
arguments = {}
|
288 |
-
if hasattr(function_call, 'args'):
|
289 |
-
arguments = function_call.args
|
290 |
-
|
291 |
-
if function_name in self.standard_tools:
|
292 |
return {"decision": {"name": function_name, "arguments": arguments}}
|
293 |
else:
|
294 |
-
return {"error":
|
|
|
|
|
295 |
|
296 |
# No function call found
|
297 |
return {"error": "Gemini did not return a function call."}
|
|
|
263 |
try:
|
264 |
# Configure tools using the Gemini API format
|
265 |
tools = genai.types.Tool(function_declarations=self.function_declarations)
|
266 |
+
config = genai.types.GenerateContentConfig(tools=[tools],automatic_function_calling=types.AutomaticFunctionCallingConfig(disable=True))
|
267 |
|
268 |
# Send request to the model
|
269 |
response = self.genai_client.models.generate_content(
|
|
|
271 |
contents=prompt,
|
272 |
config=config
|
273 |
)
|
274 |
+
try:
|
275 |
+
function_calls = response.function_calls
|
276 |
+
if function_calls:
|
277 |
+
function_name = function_calls[0].name
|
278 |
+
arguments = function_calls[0].args
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
279 |
return {"decision": {"name": function_name, "arguments": arguments}}
|
280 |
else:
|
281 |
+
return {"error": "Gemini did not return a function call."}
|
282 |
+
except Exception as e:
|
283 |
+
return {"error": f"Model called unknown @function '{function_name}'."}
|
284 |
|
285 |
# No function call found
|
286 |
return {"error": "Gemini did not return a function call."}
|