Update crew.py
Browse files
crew.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
import os
|
2 |
from crewai import Agent, Crew, Process, Task
|
3 |
from crewai.tools import tool
|
4 |
-
from crewai_tools import (
|
5 |
-
SerperDevTool,
|
6 |
-
WebsiteSearchTool
|
7 |
-
)
|
8 |
from google import genai
|
9 |
from google.genai import types
|
10 |
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
@@ -13,17 +13,19 @@ from util import get_final_answer
|
|
13 |
|
14 |
## LLMs
|
15 |
|
16 |
-
MANAGER_MODEL
|
17 |
-
AGENT_MODEL
|
18 |
|
19 |
-
FINAL_ANSWER_MODEL
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
|
|
|
|
27 |
|
28 |
# LLM evaluation
|
29 |
|
@@ -42,8 +44,45 @@ CrewAIInstrumentor().instrument(tracer_provider=tracer_provider)
|
|
42 |
def run_crew(question, file_path):
|
43 |
# Tools
|
44 |
|
45 |
-
web_search_tool = SerperDevTool()
|
46 |
-
web_rag_tool = WebsiteSearchTool()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
@tool("Image Analysis Tool")
|
49 |
def image_analysis_tool(question: str, file_path: str) -> str:
|
@@ -64,7 +103,7 @@ def run_crew(question, file_path):
|
|
64 |
file = client.files.upload(file=file_path)
|
65 |
|
66 |
response = client.models.generate_content(
|
67 |
-
model=
|
68 |
contents=[file, question]
|
69 |
)
|
70 |
|
@@ -91,7 +130,7 @@ def run_crew(question, file_path):
|
|
91 |
file = client.files.upload(file=file_path)
|
92 |
|
93 |
response = client.models.generate_content(
|
94 |
-
model=
|
95 |
contents=[file, question]
|
96 |
)
|
97 |
|
@@ -118,7 +157,7 @@ def run_crew(question, file_path):
|
|
118 |
file = client.files.upload(file=file_path)
|
119 |
|
120 |
response = client.models.generate_content(
|
121 |
-
model=
|
122 |
contents=[file, question]
|
123 |
)
|
124 |
|
@@ -143,7 +182,7 @@ def run_crew(question, file_path):
|
|
143 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
144 |
|
145 |
return client.models.generate_content(
|
146 |
-
model=
|
147 |
contents=types.Content(
|
148 |
parts=[types.Part(file_data=types.FileData(file_uri=url)),
|
149 |
types.Part(text=question)]
|
@@ -172,7 +211,7 @@ def run_crew(question, file_path):
|
|
172 |
file = client.files.upload(file=file_path)
|
173 |
|
174 |
response = client.models.generate_content(
|
175 |
-
model=
|
176 |
contents=[file, question]
|
177 |
)
|
178 |
|
@@ -198,7 +237,7 @@ def run_crew(question, file_path):
|
|
198 |
file = client.files.upload(file=file_path)
|
199 |
|
200 |
response = client.models.generate_content(
|
201 |
-
model=
|
202 |
contents=[question],
|
203 |
config=types.GenerateContentConfig(
|
204 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
@@ -230,7 +269,7 @@ def run_crew(question, file_path):
|
|
230 |
file = client.files.upload(file=file_path)
|
231 |
|
232 |
response = client.models.generate_content(
|
233 |
-
model=
|
234 |
contents=[file, question],
|
235 |
config=types.GenerateContentConfig(
|
236 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
@@ -247,12 +286,12 @@ def run_crew(question, file_path):
|
|
247 |
|
248 |
web_search_agent = Agent(
|
249 |
role="Web Search Agent",
|
250 |
-
goal="Search the web to help answer question \"{question}\"
|
251 |
backstory="As an expert web search assistant, you search the web to help answer the question.",
|
252 |
allow_delegation=False,
|
253 |
llm=AGENT_MODEL,
|
254 |
max_iter=2,
|
255 |
-
tools=[web_search_tool
|
256 |
verbose=False
|
257 |
)
|
258 |
|
|
|
1 |
import os
|
2 |
from crewai import Agent, Crew, Process, Task
|
3 |
from crewai.tools import tool
|
4 |
+
#from crewai_tools import (
|
5 |
+
# SerperDevTool,
|
6 |
+
# WebsiteSearchTool
|
7 |
+
#)
|
8 |
from google import genai
|
9 |
from google.genai import types
|
10 |
from openinference.instrumentation.crewai import CrewAIInstrumentor
|
|
|
13 |
|
14 |
## LLMs
|
15 |
|
16 |
+
MANAGER_MODEL = "gpt-4.1-mini"
|
17 |
+
AGENT_MODEL = "gpt-4.1-mini"
|
18 |
|
19 |
+
FINAL_ANSWER_MODEL = "gemini-2.5-flash-preview-04-17"
|
20 |
|
21 |
+
WEB_SEARCH_MODEL = "gemini-2.5-flash-preview-04-17"
|
22 |
+
IMAGE_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
23 |
+
AUDIO_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
24 |
+
VIDEO_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
25 |
+
YOUTUBE_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
26 |
+
DOCUMENT_ANALYSIS_MODEL = "gemini-2.5-flash-preview-04-17"
|
27 |
+
CODE_GENERATION_MODEL = "gemini-2.5-flash-preview-04-17"
|
28 |
+
CODE_EXECUTION_MODEL = "gemini-2.5-flash-preview-04-17"
|
29 |
|
30 |
# LLM evaluation
|
31 |
|
|
|
44 |
def run_crew(question, file_path):
|
45 |
# Tools
|
46 |
|
47 |
+
#web_search_tool = SerperDevTool()
|
48 |
+
#web_rag_tool = WebsiteSearchTool()
|
49 |
+
|
50 |
+
@tool("Web Search Tool")
|
51 |
+
def web_search_tool(question: str) -> str:
|
52 |
+
"""Search the web to answer a question.
|
53 |
+
|
54 |
+
Args:
|
55 |
+
question (str): Question to answer
|
56 |
+
|
57 |
+
Returns:
|
58 |
+
str: Answer to the question
|
59 |
+
|
60 |
+
Raises:
|
61 |
+
RuntimeError: If processing fails"""
|
62 |
+
try:
|
63 |
+
#client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
64 |
+
|
65 |
+
#response = client.models.generate_content(
|
66 |
+
# model=IMAGE_MODEL,
|
67 |
+
# contents=[file, question]
|
68 |
+
#)
|
69 |
+
|
70 |
+
#return response.text
|
71 |
+
###
|
72 |
+
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
73 |
+
|
74 |
+
response = client.models.generate_content(
|
75 |
+
model=WEB_SEARCH_MODEL,
|
76 |
+
contents=question,
|
77 |
+
config=types.GenerateContentConfig(
|
78 |
+
tools=[types.Tool(google_search_retrieval=types.GoogleSearchRetrieval())]
|
79 |
+
)
|
80 |
+
)
|
81 |
+
|
82 |
+
return response.text
|
83 |
+
###
|
84 |
+
except Exception as e:
|
85 |
+
raise RuntimeError(f"Processing failed: {str(e)}")
|
86 |
|
87 |
@tool("Image Analysis Tool")
|
88 |
def image_analysis_tool(question: str, file_path: str) -> str:
|
|
|
103 |
file = client.files.upload(file=file_path)
|
104 |
|
105 |
response = client.models.generate_content(
|
106 |
+
model=IMAGE_ANALYSIS_MODEL,
|
107 |
contents=[file, question]
|
108 |
)
|
109 |
|
|
|
130 |
file = client.files.upload(file=file_path)
|
131 |
|
132 |
response = client.models.generate_content(
|
133 |
+
model=AUDIO_ANALYSIS_MODEL,
|
134 |
contents=[file, question]
|
135 |
)
|
136 |
|
|
|
157 |
file = client.files.upload(file=file_path)
|
158 |
|
159 |
response = client.models.generate_content(
|
160 |
+
model=VIDEO_ANALYSIS_MODEL,
|
161 |
contents=[file, question]
|
162 |
)
|
163 |
|
|
|
182 |
client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
|
183 |
|
184 |
return client.models.generate_content(
|
185 |
+
model=YOUTUBE_ANALYSIS_MODEL,
|
186 |
contents=types.Content(
|
187 |
parts=[types.Part(file_data=types.FileData(file_uri=url)),
|
188 |
types.Part(text=question)]
|
|
|
211 |
file = client.files.upload(file=file_path)
|
212 |
|
213 |
response = client.models.generate_content(
|
214 |
+
model=DOCUMENT_ANALYSIS_MODEL,
|
215 |
contents=[file, question]
|
216 |
)
|
217 |
|
|
|
237 |
file = client.files.upload(file=file_path)
|
238 |
|
239 |
response = client.models.generate_content(
|
240 |
+
model=CODE_GENERATION_MODEL,
|
241 |
contents=[question],
|
242 |
config=types.GenerateContentConfig(
|
243 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
|
|
269 |
file = client.files.upload(file=file_path)
|
270 |
|
271 |
response = client.models.generate_content(
|
272 |
+
model=CODE_EXECUTION_MODEL,
|
273 |
contents=[file, question],
|
274 |
config=types.GenerateContentConfig(
|
275 |
tools=[types.Tool(code_execution=types.ToolCodeExecution)]
|
|
|
286 |
|
287 |
web_search_agent = Agent(
|
288 |
role="Web Search Agent",
|
289 |
+
goal="Search the web to help answer question \"{question}\"",
|
290 |
backstory="As an expert web search assistant, you search the web to help answer the question.",
|
291 |
allow_delegation=False,
|
292 |
llm=AGENT_MODEL,
|
293 |
max_iter=2,
|
294 |
+
tools=[web_search_tool],
|
295 |
verbose=False
|
296 |
)
|
297 |
|