bstraehle commited on
Commit
2aa67da
·
verified ·
1 Parent(s): 9d98882

Update crew.py

Browse files
Files changed (1) hide show
  1. crew.py +0 -262
crew.py CHANGED
@@ -53,268 +53,6 @@ tracer_provider = register(
53
  class GAIACrew():
54
  agents: List[BaseAgent]
55
  tasks: List[Task]
56
-
57
- @tool("Web Search Tool")
58
- def web_search_tool(question: str) -> str:
59
- """Given a question only, search the web to answer the question.
60
-
61
- Args:
62
- question (str): Question to answer
63
-
64
- Returns:
65
- str: Answer to the question
66
-
67
- Raises:
68
- RuntimeError: If processing fails"""
69
- try:
70
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
71
-
72
- response = client.models.generate_content(
73
- model=WEB_SEARCH_MODEL,
74
- contents=question,
75
- config=types.GenerateContentConfig(
76
- tools=[types.Tool(google_search=types.GoogleSearchRetrieval())]
77
- )
78
- )
79
-
80
- return response.text
81
- except Exception as e:
82
- raise RuntimeError(f"Processing failed: {str(e)}")
83
-
84
- @tool("Image Analysis Tool")
85
- def image_analysis_tool(question: str, file_path: str) -> str:
86
- """Given a question and image file, analyze the image to answer the question.
87
-
88
- Args:
89
- question (str): Question about an image file
90
- file_path (str): The image file path
91
-
92
- Returns:
93
- str: Answer to the question about the image file
94
-
95
- Raises:
96
- RuntimeError: If processing fails"""
97
- try:
98
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
99
-
100
- file = client.files.upload(file=file_path)
101
-
102
- response = client.models.generate_content(
103
- model=IMAGE_ANALYSIS_MODEL,
104
- contents=[file, question]
105
- )
106
-
107
- return response.text
108
- except Exception as e:
109
- raise RuntimeError(f"Processing failed: {str(e)}")
110
-
111
- @tool("Audio Analysis Tool")
112
- def audio_analysis_tool(question: str, file_path: str) -> str:
113
- """Given a question and audio file, analyze the audio to answer the question.
114
-
115
- Args:
116
- question (str): Question about an audio file
117
- file_path (str): The audio file path
118
-
119
- Returns:
120
- str: Answer to the question about the audio file
121
-
122
- Raises:
123
- RuntimeError: If processing fails"""
124
- try:
125
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
126
-
127
- file = client.files.upload(file=file_path)
128
-
129
- response = client.models.generate_content(
130
- model=AUDIO_ANALYSIS_MODEL,
131
- contents=[file, question]
132
- )
133
-
134
- return response.text
135
- except Exception as e:
136
- raise RuntimeError(f"Processing failed: {str(e)}")
137
-
138
- @tool("Video Analysis Tool")
139
- def video_analysis_tool(question: str, file_path: str) -> str:
140
- """Given a question and video file, analyze the video to answer the question.
141
-
142
- Args:
143
- question (str): Question about a video file
144
- file_path (str): The video file path
145
-
146
- Returns:
147
- str: Answer to the question about the video file
148
-
149
- Raises:
150
- RuntimeError: If processing fails"""
151
- try:
152
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
153
-
154
- file = client.files.upload(file=file_path)
155
-
156
- response = client.models.generate_content(
157
- model=VIDEO_ANALYSIS_MODEL,
158
- contents=[file, question]
159
- )
160
-
161
- return response.text
162
- except Exception as e:
163
- raise RuntimeError(f"Processing failed: {str(e)}")
164
-
165
- @tool("YouTube Analysis Tool")
166
- def youtube_analysis_tool(question: str, url: str) -> str:
167
- """Given a question and YouTube URL, analyze the video to answer the question.
168
-
169
- Args:
170
- question (str): Question about a YouTube video
171
- url (str): The YouTube URL
172
-
173
- Returns:
174
- str: Answer to the question about the YouTube video
175
-
176
- Raises:
177
- RuntimeError: If processing fails"""
178
- try:
179
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
180
-
181
- return client.models.generate_content(
182
- model=YOUTUBE_ANALYSIS_MODEL,
183
- contents=types.Content(
184
- parts=[types.Part(file_data=types.FileData(file_uri=url)),
185
- types.Part(text=question)]
186
- )
187
- )
188
- except Exception as e:
189
- raise RuntimeError(f"Processing failed: {str(e)}")
190
-
191
- @tool("Document Analysis Tool")
192
- def document_analysis_tool(question: str, file_path: str) -> str:
193
- """Given a question and document file, analyze the document to answer the question.
194
-
195
- Args:
196
- question (str): Question about a document file
197
- file_path (str): The document file path
198
-
199
- Returns:
200
- str: Answer to the question about the document file
201
-
202
- Raises:
203
- RuntimeError: If processing fails"""
204
- try:
205
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
206
-
207
- contents = []
208
-
209
- if is_ext(file_path, ".docx"):
210
- text_data = read_docx_text(file_path)
211
- contents = [f"{question}\n{text_data}"]
212
- print(f"=> Text data:\n{text_data}")
213
- elif is_ext(file_path, ".pptx"):
214
- text_data = read_pptx_text(file_path)
215
- contents = [f"{question}\n{text_data}"]
216
- print(f"=> Text data:\n{text_data}")
217
- else:
218
- file = client.files.upload(file=file_path)
219
- contents = [file, question]
220
-
221
- response = client.models.generate_content(
222
- model=DOCUMENT_ANALYSIS_MODEL,
223
- contents=contents
224
- )
225
-
226
- return response.text
227
- except Exception as e:
228
- raise RuntimeError(f"Processing failed: {str(e)}")
229
-
230
- @tool("Arithmetic Tool")
231
- def arithmetic_tool(question: str, a: float, b: float) -> float:
232
- """Given a question and two numbers, perform the calculation to answer the question.
233
-
234
- Args:
235
- question (str): Question to answer
236
- a (float): First number
237
- b (float): Second number
238
-
239
- Returns:
240
- float: Result number
241
-
242
- Raises:
243
- RuntimeError: If processing fails"""
244
- try:
245
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
246
-
247
- response = client.models.generate_content(
248
- model=ARITHMETIC_MODEL,
249
- contents=question,
250
- config=types.GenerateContentConfig(
251
- tools=[add, subtract, multiply, divide, modulus]
252
- )
253
- )
254
-
255
- return response.text
256
- except Exception as e:
257
- raise RuntimeError(f"Processing failed: {str(e)}")
258
-
259
- @tool("Code Execution Tool")
260
- def code_execution_tool(question: str, file_path: str) -> str:
261
- """Given a question and Python file, execute the file to answer the question.
262
-
263
- Args:
264
- question (str): Question to answer
265
- file_path (str): The Python file path
266
-
267
- Returns:
268
- str: Answer to the question
269
-
270
- Raises:
271
- RuntimeError: If processing fails"""
272
- try:
273
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
274
-
275
- file = client.files.upload(file=file_path)
276
-
277
- response = client.models.generate_content(
278
- model=CODE_EXECUTION_MODEL,
279
- contents=[file, question],
280
- config=types.GenerateContentConfig(
281
- tools=[types.Tool(code_execution=types.ToolCodeExecution)]
282
- ),
283
- )
284
-
285
- for part in response.candidates[0].content.parts:
286
- if part.code_execution_result is not None:
287
- return part.code_execution_result.output
288
- except Exception as e:
289
- raise RuntimeError(f"Processing failed: {str(e)}")
290
-
291
- @tool("Code Generation Tool")
292
- def code_generation_tool(question: str, json_data: str) -> str:
293
- """Given a question and JSON data, generate and execute code to answer the question.
294
- Args:
295
- question (str): Question to answer
296
- file_path (str): The JSON data
297
- Returns:
298
- str: Answer to the question
299
-
300
- Raises:
301
- RuntimeError: If processing fails"""
302
- try:
303
- client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
304
-
305
- response = client.models.generate_content(
306
- model=CODE_GENERATION_MODEL,
307
- contents=[f"{question}\n{json_data}"],
308
- config=types.GenerateContentConfig(
309
- tools=[types.Tool(code_execution=types.ToolCodeExecution)]
310
- ),
311
- )
312
-
313
- for part in response.candidates[0].content.parts:
314
- if part.code_execution_result is not None:
315
- return part.code_execution_result.output
316
- except Exception as e:
317
- raise RuntimeError(f"Processing failed: {str(e)}")
318
 
319
  @agent
320
  def web_search_agent(self) -> Agent:
 
53
  class GAIACrew():
54
  agents: List[BaseAgent]
55
  tasks: List[Task]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  @agent
58
  def web_search_agent(self) -> Agent: