Spaces:
Configuration error
Configuration error
Update crew.py
Browse files
crew.py
CHANGED
|
@@ -11,6 +11,7 @@ from google import genai
|
|
| 11 |
from google.genai import types
|
| 12 |
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
| 13 |
from phoenix.otel import register
|
|
|
|
| 14 |
from utils import read_file_json, read_docx_text, read_pptx_text, is_ext
|
| 15 |
|
| 16 |
## LLMs
|
|
@@ -219,6 +220,36 @@ def run_crew(question, file_path):
|
|
| 219 |
except Exception as e:
|
| 220 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
@tool("Code Generation Tool")
|
| 223 |
def code_generation_tool(question: str, json_data: str) -> str:
|
| 224 |
"""Given a question and json data, generate and execute code to answer the question.
|
|
@@ -348,6 +379,17 @@ def run_crew(question, file_path):
|
|
| 348 |
tools=[document_analysis_tool],
|
| 349 |
verbose=True
|
| 350 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 351 |
|
| 352 |
code_generation_agent = Agent(
|
| 353 |
role="Code Generation Agent",
|
|
@@ -391,6 +433,7 @@ def run_crew(question, file_path):
|
|
| 391 |
"- Audio Analysis Agent requires a question and **.wav, .mp3, .aiff, .aac, .ogg, or .flac audio file**.\n"
|
| 392 |
"- Video Analysis Agent requires a question and **.mp4, .mpeg, .mov, .avi, .x-flv, .mpg, .webm, .wmv, or .3gpp video file**.\n"
|
| 393 |
"- Document Analysis Agent requires a question and **.docx, .pptx, .pdf, .txt, .html, css, .js, .md, .xml, or .rtf document file**.\n"
|
|
|
|
| 394 |
"- YouTube Analysis Agent requires a question and **YouTube URL**.\n"
|
| 395 |
"- Code Generation Agent requires a question and **JSON data**.\n"
|
| 396 |
"- Code Execution Agent requires a question and **Python file**.\n"
|
|
@@ -407,6 +450,7 @@ def run_crew(question, file_path):
|
|
| 407 |
video_analysis_agent,
|
| 408 |
youtube_analysis_agent,
|
| 409 |
document_analysis_agent,
|
|
|
|
| 410 |
code_generation_agent,
|
| 411 |
code_execution_agent],
|
| 412 |
manager_agent=manager_agent,
|
|
|
|
| 11 |
from google.genai import types
|
| 12 |
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
| 13 |
from phoenix.otel import register
|
| 14 |
+
from tools import add, subtract, multiply, divide, modulus
|
| 15 |
from utils import read_file_json, read_docx_text, read_pptx_text, is_ext
|
| 16 |
|
| 17 |
## LLMs
|
|
|
|
| 220 |
except Exception as e:
|
| 221 |
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 222 |
|
| 223 |
+
@tool("Math Tool")
|
| 224 |
+
def math_tool(question: str, a: float, b: float) -> float:
|
| 225 |
+
"""Given a question and two numbers, perform the calculation to answer the question.
|
| 226 |
+
|
| 227 |
+
Args:
|
| 228 |
+
question (str): Question to answer
|
| 229 |
+
a (float): Float a
|
| 230 |
+
b (float): Float b
|
| 231 |
+
|
| 232 |
+
Returns:
|
| 233 |
+
float: Result float
|
| 234 |
+
|
| 235 |
+
Raises:
|
| 236 |
+
RuntimeError: If processing fails"""
|
| 237 |
+
try:
|
| 238 |
+
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
| 239 |
+
|
| 240 |
+
response = client.models.generate_content(
|
| 241 |
+
model=WEB_SEARCH_MODEL,
|
| 242 |
+
contents=question,
|
| 243 |
+
config=types.GenerateContentConfig(
|
| 244 |
+
tools=[add, subtract, multiply, divide, modulus]
|
| 245 |
+
)
|
| 246 |
+
)
|
| 247 |
+
|
| 248 |
+
return response.text
|
| 249 |
+
except Exception as e:
|
| 250 |
+
raise RuntimeError(f"Processing failed: {str(e)}")
|
| 251 |
+
###
|
| 252 |
+
|
| 253 |
@tool("Code Generation Tool")
|
| 254 |
def code_generation_tool(question: str, json_data: str) -> str:
|
| 255 |
"""Given a question and json data, generate and execute code to answer the question.
|
|
|
|
| 379 |
tools=[document_analysis_tool],
|
| 380 |
verbose=True
|
| 381 |
)
|
| 382 |
+
|
| 383 |
+
math_agent = Agent(
|
| 384 |
+
role="Math Agent",
|
| 385 |
+
goal="Given a question and two numbers, perform the calculation and answer the question: {question}",
|
| 386 |
+
backstory="As an expert math assistant, you perform the calculation to answer the question.",
|
| 387 |
+
allow_delegation=False,
|
| 388 |
+
llm=AGENT_MODEL,
|
| 389 |
+
max_iter=2,
|
| 390 |
+
tools=[math_tool],
|
| 391 |
+
verbose=True
|
| 392 |
+
)
|
| 393 |
|
| 394 |
code_generation_agent = Agent(
|
| 395 |
role="Code Generation Agent",
|
|
|
|
| 433 |
"- Audio Analysis Agent requires a question and **.wav, .mp3, .aiff, .aac, .ogg, or .flac audio file**.\n"
|
| 434 |
"- Video Analysis Agent requires a question and **.mp4, .mpeg, .mov, .avi, .x-flv, .mpg, .webm, .wmv, or .3gpp video file**.\n"
|
| 435 |
"- Document Analysis Agent requires a question and **.docx, .pptx, .pdf, .txt, .html, css, .js, .md, .xml, or .rtf document file**.\n"
|
| 436 |
+
"- Math Agent requires a question and **two numbers to add, subtract, multiply, divide, or get modulus**.\n"
|
| 437 |
"- YouTube Analysis Agent requires a question and **YouTube URL**.\n"
|
| 438 |
"- Code Generation Agent requires a question and **JSON data**.\n"
|
| 439 |
"- Code Execution Agent requires a question and **Python file**.\n"
|
|
|
|
| 450 |
video_analysis_agent,
|
| 451 |
youtube_analysis_agent,
|
| 452 |
document_analysis_agent,
|
| 453 |
+
#math_agent,
|
| 454 |
code_generation_agent,
|
| 455 |
code_execution_agent],
|
| 456 |
manager_agent=manager_agent,
|