File size: 4,271 Bytes
fb293f8 59f5166 00aced7 ee397c8 1c7a0a7 15b8627 1c7a0a7 eea8c7f fe0c112 1c7a0a7 f06be5d 230d96d d1de168 ce7387d ae4b74c 86f2a58 230d96d df58f18 230d96d 3bd69bd 5028b6b 7ddb52b f407c48 7bc23ab e026826 7da0809 eea8c7f 35828ac 1c7a0a7 35828ac 7da0809 eea8c7f 1c7a0a7 eea8c7f 6245998 eea8c7f 35828ac 13c2cf4 35828ac 6bf14de 86f2a58 35828ac 1c7a0a7 7f78cfc 35828ac b0b7841 35828ac 86f2a58 b0b7841 35828ac 7da0809 eea8c7f 35828ac eea8c7f 35828ac 13c2cf4 b0b7841 13c2cf4 eea8c7f 35828ac b0b7841 35828ac 7da0809 35828ac 0b498b7 eea8c7f b0b7841 c0f1279 eea8c7f 7311d82 ab1c2b7 d3c5ea2 7d6d333 d3c5ea2 fe96564 1312508 fe96564 1312508 0b498b7 1312508 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
import os
from crewai import Agent, Crew, Process, Task
from crewai.tools import tool
from crewai_tools import (
CodeInterpreterTool,
SerperDevTool,
VisionTool,
WebsiteSearchTool,
YoutubeVideoSearchTool
)
from openinference.instrumentation.crewai import CrewAIInstrumentor
from phoenix.otel import register
from util import get_final_answer
PLANNING_MODEL = "gpt-4.5-preview"
PHOENIX_API_KEY = os.environ["PHOENIX_API_KEY"]
os.environ["PHOENIX_CLIENT_HEADERS"] = f"api_key={PHOENIX_API_KEY}"
os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "https://app.phoenix.arize.com"
tracer_provider = register(
auto_instrument=True,
project_name="gaia"
)
CrewAIInstrumentor().instrument(tracer_provider=tracer_provider)
def run_crew(question, file_name):
# Tools
python_coding_tool = CodeInterpreterTool()
image_search_tool = VisionTool()
web_search_tool = SerperDevTool()
web_rag_tool = WebsiteSearchTool()
youtube_search_tool = YoutubeVideoSearchTool()
# Agents
image_search_agent = Agent(
role="Image Search Agent",
goal="Search an image for question \"{topic}\".",
backstory="As an expert image search assistant, you search an image for the question.",
allow_delegation=False,
max_iter=1,
tools=[image_search_tool],
verbose=True
)
python_coding_agent = Agent(
role="Python Coding Agent",
goal="Write and execute Python code to solve question \"{topic}\".",
backstory="As an expert Python coding assistant, you write and execute Python for the question.",
allow_delegation=False,
max_iter=1,
tools=[python_coding_tool],
verbose=True,
)
web_search_agent = Agent(
role="Web Search Agent",
goal="Search the web for question \"{topic}\" and scrape the most relevant web page.",
backstory="As an expert web search assistant, you search the web for the question and scrape the most relevant web page.",
allow_delegation=False,
max_iter=1,
tools=[web_search_tool, web_rag_tool],
verbose=True
)
youtube_search_agent = Agent(
role="YouTube Search Agent",
goal="Search a YouTube video for question \"{topic}\".",
backstory="As an expert YouTube search assistant, you search a YouTube video for the question.",
allow_delegation=False,
max_iter=1,
tools=[youtube_search_tool],
verbose=True
)
# Tasks
image_search_task = Task(
agent=image_search_agent,
description="Search an image for question \"{topic}\"",
expected_output="Content to help answer the image related question."
)
python_coding_task = Task(
agent=python_coding_agent,
description="Write and execute Python code to solve question \"{topic}\".",
expected_output="Content to help answer the Phyton coding related question."
)
web_search_task = Task(
agent=web_search_agent,
description="Search the web for question \"{topic}\" and scrape the most relevant web page.",
expected_output="Content to help answer the web related question."
)
youtube_search_task = Task(
agent=youtube_search_agent,
description="Search a YouTube video for question \"{topic}\"",
expected_output="Content to help answer the YouTube related question."
)
# Crew
crew = Crew(
agents=[image_search_agent, python_coding_agent, web_search_agent, youtube_search_agent],
#planning=True,
#planning_llm=PLANNING_MODEL,
process=Process.sequential,
tasks=[image_search_task, python_coding_task, web_search_task, youtube_search_task],
verbose=True
)
if file_name:
question = f"{question} File name: data/{file_name}."
print("###")
print(f"Question: {question}")
print("###")
initial_answer = crew.kickoff(inputs={"topic": question})
print("###")
print(f"Initial answer: {initial_answer}")
print("###")
final_answer = get_final_answer(question, str(initial_answer))
print("###")
print(f"Final answer: {final_answer}")
print("###")
return final_answer |