bstraehle commited on
Commit
6ec5ba5
Β·
verified Β·
1 Parent(s): 29fc519

Update agents/tools/ai_tools.py

Browse files
Files changed (1) hide show
  1. agents/tools/ai_tools.py +47 -26
agents/tools/ai_tools.py CHANGED
@@ -1,7 +1,6 @@
1
  # References:
2
 
3
- # # https://docs.crewai.com/introduction
4
- # https://docs.crewai.com/en/tools/web-scraping/stagehandtool
5
  # https://ai.google.dev/gemini-api/docs
6
 
7
  import base64, chess, os
@@ -108,11 +107,14 @@ class AITools():
108
  wait_for_captcha_solves=True,
109
  verbose=3
110
  ) as stagehand_tool:
111
- return stagehand_tool.run(
112
  instruction=question,
113
  url=url_str,
114
  command_type="act" # TODO: act, extract, observe
115
  )
 
 
 
116
  except Exception as e:
117
  raise RuntimeError(f"Processing failed: {str(e)}")
118
 
@@ -146,8 +148,10 @@ class AITools():
146
  )
147
  )
148
  )
149
-
150
- return response.text.strip()
 
 
151
  except Exception as e:
152
  raise RuntimeError(f"Processing failed: {str(e)}")
153
 
@@ -181,8 +185,10 @@ class AITools():
181
  )
182
  )
183
  )
184
-
185
- return response.text.strip()
 
 
186
  except Exception as e:
187
  raise RuntimeError(f"Processing failed: {str(e)}")
188
 
@@ -216,8 +222,10 @@ class AITools():
216
  )
217
  )
218
  )
219
-
220
- return response.text.strip()
 
 
221
  except Exception as e:
222
  raise RuntimeError(f"Processing failed: {str(e)}")
223
 
@@ -240,7 +248,7 @@ class AITools():
240
  try:
241
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
242
 
243
- return client.models.generate_content(
244
  model=LLM_YOUTUBE_ANALYSIS,
245
  contents=types.Content(
246
  parts=[types.Part(file_data=types.FileData(file_uri=url)),
@@ -252,6 +260,9 @@ class AITools():
252
  )
253
  )
254
  )
 
 
 
255
  except Exception as e:
256
  raise RuntimeError(f"Processing failed: {str(e)}")
257
 
@@ -298,7 +309,9 @@ class AITools():
298
  )
299
  )
300
 
301
- return response.text.strip()
 
 
302
  except Exception as e:
303
  raise RuntimeError(f"Processing failed: {str(e)}")
304
 
@@ -333,7 +346,11 @@ class AITools():
333
 
334
  for part in response.candidates[0].content.parts:
335
  if part.code_execution_result is not None:
336
- return part.code_execution_result.output
 
 
 
 
337
  except Exception as e:
338
  raise RuntimeError(f"Processing failed: {str(e)}")
339
 
@@ -371,7 +388,11 @@ class AITools():
371
 
372
  for part in response.candidates[0].content.parts:
373
  if part.code_execution_result is not None:
374
- return part.code_execution_result.output
 
 
 
 
375
  except Exception as e:
376
  raise RuntimeError(f"Processing failed: {str(e)}")
377
 
@@ -421,19 +442,18 @@ class AITools():
421
  )
422
  )
423
  )
424
-
425
- fen = None
426
-
427
  for part in response.parts:
428
  if part.text is not None:
429
- fen = part.text.strip()
430
  break
431
 
432
- board = chess.Board(fen) # FEN validation
433
 
434
- print(f"πŸ€– FEN: {fen}")
435
-
436
- return fen;
437
  except Exception as e:
438
  raise RuntimeError(f"Processing failed: {str(e)}")
439
 
@@ -490,9 +510,8 @@ class AITools():
490
  result = part.text.strip()
491
  break
492
 
493
- print(f"πŸ€– Algebraic notation: {result}")
494
-
495
- return result;
496
  except Exception as e:
497
  raise RuntimeError(f"Processing failed: {str(e)}")
498
 
@@ -512,5 +531,7 @@ class AITools():
512
  )
513
  )
514
  )
515
-
516
- return response.text
 
 
 
1
  # References:
2
 
3
+ # https://docs.crewai.com/introduction
 
4
  # https://ai.google.dev/gemini-api/docs
5
 
6
  import base64, chess, os
 
107
  wait_for_captcha_solves=True,
108
  verbose=3
109
  ) as stagehand_tool:
110
+ result = stagehand_tool.run(
111
  instruction=question,
112
  url=url_str,
113
  command_type="act" # TODO: act, extract, observe
114
  )
115
+
116
+ print(f"πŸ€– Result: {result}")
117
+ return result
118
  except Exception as e:
119
  raise RuntimeError(f"Processing failed: {str(e)}")
120
 
 
148
  )
149
  )
150
  )
151
+
152
+ result = response.text.strip()
153
+ print(f"πŸ€– Result: {result}")
154
+ return result
155
  except Exception as e:
156
  raise RuntimeError(f"Processing failed: {str(e)}")
157
 
 
185
  )
186
  )
187
  )
188
+
189
+ result = response.text.strip()
190
+ print(f"πŸ€– Result: {result}")
191
+ return result
192
  except Exception as e:
193
  raise RuntimeError(f"Processing failed: {str(e)}")
194
 
 
222
  )
223
  )
224
  )
225
+
226
+ result = response.text.strip()
227
+ print(f"πŸ€– Result: {result}")
228
+ return result
229
  except Exception as e:
230
  raise RuntimeError(f"Processing failed: {str(e)}")
231
 
 
248
  try:
249
  client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
250
 
251
+ result = client.models.generate_content(
252
  model=LLM_YOUTUBE_ANALYSIS,
253
  contents=types.Content(
254
  parts=[types.Part(file_data=types.FileData(file_uri=url)),
 
260
  )
261
  )
262
  )
263
+
264
+ print(f"πŸ€– Result: {result}")
265
+ return result
266
  except Exception as e:
267
  raise RuntimeError(f"Processing failed: {str(e)}")
268
 
 
309
  )
310
  )
311
 
312
+ result = response.text.strip()
313
+ print(f"πŸ€– Result: {result}")
314
+ return result
315
  except Exception as e:
316
  raise RuntimeError(f"Processing failed: {str(e)}")
317
 
 
346
 
347
  for part in response.candidates[0].content.parts:
348
  if part.code_execution_result is not None:
349
+ result part.code_execution_result.output
350
+ break
351
+
352
+ print(f"πŸ€– Result: {result}")
353
+ return result
354
  except Exception as e:
355
  raise RuntimeError(f"Processing failed: {str(e)}")
356
 
 
388
 
389
  for part in response.candidates[0].content.parts:
390
  if part.code_execution_result is not None:
391
+ result = part.code_execution_result.output
392
+ break
393
+
394
+ print(f"πŸ€– Result: {result}")
395
+ return result
396
  except Exception as e:
397
  raise RuntimeError(f"Processing failed: {str(e)}")
398
 
 
442
  )
443
  )
444
  )
445
+
446
+ result = None
447
+
448
  for part in response.parts:
449
  if part.text is not None:
450
+ result = part.text.strip()
451
  break
452
 
453
+ board = chess.Board(result) # FEN validation
454
 
455
+ print(f"πŸ€– Result: {result}")
456
+ return result
 
457
  except Exception as e:
458
  raise RuntimeError(f"Processing failed: {str(e)}")
459
 
 
510
  result = part.text.strip()
511
  break
512
 
513
+ print(f"πŸ€– Result: {result}")
514
+ return result
 
515
  except Exception as e:
516
  raise RuntimeError(f"Processing failed: {str(e)}")
517
 
 
531
  )
532
  )
533
  )
534
+
535
+ result = response.text.strip()
536
+ print(f"πŸ€– Result: {result}")
537
+ return result