Lasdw commited on
Commit
d50f45c
·
1 Parent(s): 30e5ecf

updated api key

Browse files
Files changed (3) hide show
  1. agent.py +1 -5
  2. requirements.txt +4 -0
  3. tools.py +24 -5
agent.py CHANGED
@@ -1109,11 +1109,7 @@ class TurboNerd:
1109
  # Example usage:
1110
  if __name__ == "__main__":
1111
  agent = TurboNerd(max_iterations=25)
1112
- response = agent("""I'm making a grocery list for my mom, but she's a professor of botany and she's a real stickler when it comes to categorizing things. I need to add different foods to different categories on the grocery list, but if I make a mistake, she won't buy anything inserted in the wrong category. Here's the list I have so far:
1113
-
1114
- milk, eggs, flour, whole bean coffee, Oreos, sweet potatoes, fresh basil, plums, green beans, rice, corn, bell pepper, whole allspice, acorns, broccoli, celery, zucchini, lettuce, peanuts
1115
-
1116
- I need to make headings for the fruits and vegetables. Could you please create a list of just the vegetables from my list? If you could do that, then I can figure out how to categorize the rest of the list into the appropriate categories. But remember that my mom is a real stickler, so make sure that no botanical fruits end up on the vegetable list, or she won't get them when she's at the store. Please alphabetize the list of vegetables, and place each item in a comma separated list.""")
1117
  print("\nFinal Response:")
1118
  print(response)
1119
 
 
1109
  # Example usage:
1110
  if __name__ == "__main__":
1111
  agent = TurboNerd(max_iterations=25)
1112
+ response = agent("""Who did the actor who played Ray in the Polish-language version of Everybody Loves Raymond play in Magda M.? Give only the first name.""")
 
 
 
 
1113
  print("\nFinal Response:")
1114
  print(response)
1115
 
requirements.txt CHANGED
@@ -16,3 +16,7 @@ youtube-transcript-api
16
  python-dotenv
17
  whisper
18
  yt_dlp
 
 
 
 
 
16
  python-dotenv
17
  whisper
18
  yt_dlp
19
+ wikipedia
20
+ arxiv
21
+ tavily
22
+ openai
tools.py CHANGED
@@ -354,7 +354,15 @@ def tavily_search(query: str, search_depth: str = "basic") -> str:
354
  search = TavilySearchResults(api_key=tavily_api_key)
355
 
356
  # Execute the search
357
- results = search.invoke({"query": query, "search_depth": search_depth})
 
 
 
 
 
 
 
 
358
 
359
  if not results:
360
  return f"No Tavily search results found for '{query}'. Try refining your search."
@@ -362,14 +370,25 @@ def tavily_search(query: str, search_depth: str = "basic") -> str:
362
  # Format the results
363
  formatted_results = f"Tavily search results for '{query}':\n\n"
364
 
365
- for i, result in enumerate(results, 1):
366
- formatted_results += f"{i}. {result.get('title', 'No title')}\n"
367
- formatted_results += f" URL: {result.get('url', 'No URL')}\n"
368
- formatted_results += f" {result.get('content', 'No content')}\n\n"
 
 
 
 
 
 
 
 
369
 
370
  return formatted_results
371
 
372
  except Exception as e:
 
 
 
373
  return f"Error searching with Tavily: {str(e)}"
374
 
375
  def arxiv_search(query: str, max_results: int = 5) -> str:
 
354
  search = TavilySearchResults(api_key=tavily_api_key)
355
 
356
  # Execute the search
357
+ try:
358
+ results = search.invoke({"query": query, "search_depth": search_depth})
359
+ except requests.exceptions.HTTPError as http_err:
360
+ # Check for the specific 432 error code
361
+ if '432 Client Error' in str(http_err):
362
+ return "Error: Invalid Tavily API key or API key has expired. Please check your API key and update it if necessary."
363
+ else:
364
+ # Re-raise to be caught by the outer try-except
365
+ raise
366
 
367
  if not results:
368
  return f"No Tavily search results found for '{query}'. Try refining your search."
 
370
  # Format the results
371
  formatted_results = f"Tavily search results for '{query}':\n\n"
372
 
373
+ # Check if results is a list of dictionaries (expected structure)
374
+ if isinstance(results, list) and all(isinstance(item, dict) for item in results):
375
+ for i, result in enumerate(results, 1):
376
+ formatted_results += f"{i}. {result.get('title', 'No title')}\n"
377
+ formatted_results += f" URL: {result.get('url', 'No URL')}\n"
378
+ formatted_results += f" {result.get('content', 'No content')}\n\n"
379
+ # Check if results is a string
380
+ elif isinstance(results, str):
381
+ formatted_results += results
382
+ # Otherwise, just convert to string representation
383
+ else:
384
+ formatted_results += str(results)
385
 
386
  return formatted_results
387
 
388
  except Exception as e:
389
+ # Check if the exception string contains the 432 error
390
+ if '432 Client Error' in str(e):
391
+ return "Error: Invalid Tavily API key or API key has expired. Please check your API key and update it if necessary."
392
  return f"Error searching with Tavily: {str(e)}"
393
 
394
  def arxiv_search(query: str, max_results: int = 5) -> str: