Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,13 +39,26 @@ class BasicAgent:
|
|
| 39 |
|
| 40 |
def process_question(self, question:str) -> str:
|
| 41 |
try:
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
except Exception as e:
|
| 50 |
if "too many requests" in str(e).lower():
|
| 51 |
time.sleep(2)
|
|
|
|
| 39 |
|
| 40 |
def process_question(self, question:str) -> str:
|
| 41 |
try:
|
| 42 |
+
# Check if this is a request about a YouTube video
|
| 43 |
+
youtube_patterns = ["youtube.com", "youtu.be", "watch youtube", "youtube video"]
|
| 44 |
+
use_youtube_tool = any(pattern in question.lower() for pattern in youtube_patterns)
|
| 45 |
+
|
| 46 |
+
if use_youtube_tool and any(isinstance(tool, YouTubeVideoTool) for tool in self.tools):
|
| 47 |
+
# Extract potential YouTube URL or ID
|
| 48 |
+
url_match = re.search(r'(?:https?:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/[^\s]+', question)
|
| 49 |
+
youtube_url = url_match.group(0) if url_match else question
|
| 50 |
+
|
| 51 |
+
# Use YouTube tool
|
| 52 |
+
youtube_info = next(tool for tool in self.tools
|
| 53 |
+
if isinstance(tool, YouTubeVideoTool))(youtube_url)
|
| 54 |
+
|
| 55 |
+
relevant_info = self._extract_key_info(youtube_info, question)
|
| 56 |
+
return self._formulate_direct_answer(relevant_info, question)
|
| 57 |
+
else:
|
| 58 |
+
# Use regular search
|
| 59 |
+
search_results = cached_search(question) if self.tools and search_tool in self.tools else "No search results available."
|
| 60 |
+
relevant_info = self._extract_key_info(search_results, question)
|
| 61 |
+
return self._formulate_direct_answer(relevant_info, question)
|
| 62 |
except Exception as e:
|
| 63 |
if "too many requests" in str(e).lower():
|
| 64 |
time.sleep(2)
|