bstraehle commited on
Commit
1d64dcf
·
verified ·
1 Parent(s): 9960513

Update agents/tools/ai_tools.py

Browse files
Files changed (1) hide show
  1. agents/tools/ai_tools.py +36 -0
agents/tools/ai_tools.py CHANGED
@@ -384,6 +384,42 @@ class AITools():
384
  Returns:
385
  str: Answer to the question
386
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
387
  Raises:
388
  RuntimeError: If processing fails
389
  """
 
384
  Returns:
385
  str: Answer to the question
386
 
387
+ Raises:
388
+ RuntimeError: If processing fails
389
+ """
390
+ try:
391
+ client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
392
+
393
+ file = client.files.upload(file=file_path)
394
+
395
+ response = client.models.generate_content(
396
+ model=LLM_CODE_EXECUTION,
397
+ contents=[file, question],
398
+ config=types.GenerateContentConfig(
399
+ tools=[types.Tool(code_execution=types.ToolCodeExecution)],
400
+ thinking_config=types.ThinkingConfig(
401
+ thinking_level=THINKING_LEVEL_TOOLS
402
+ )
403
+ ),
404
+ )
405
+
406
+ for part in response.candidates[0].content.parts:
407
+ if part.code_execution_result is not None:
408
+ return part.code_execution_result.output
409
+ except Exception as e:
410
+ raise RuntimeError(f"Processing failed: {str(e)}")
411
+
412
+ @tool("Final Answer Tool")
413
+ def final_answer_tool(question: str, answer: str) -> str:
414
+ """Given a question and initial answer, generate the final answer.
415
+
416
+ Args:
417
+ question (str): Question to answer
418
+ answer (str): The initial answer
419
+
420
+ Returns:
421
+ str: Final answer to the question
422
+
423
  Raises:
424
  RuntimeError: If processing fails
425
  """