Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -162,11 +162,20 @@ def get_youtube_transcript(url: str) -> dict:
|
|
| 162 |
url: The full URL of the YouTube video.
|
| 163 |
"""
|
| 164 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
loader = YoutubeLoader.from_youtube_url(url, add_video_info=True)
|
| 166 |
docs = loader.load()
|
| 167 |
content = "\n\n".join([doc.page_content for doc in docs])
|
| 168 |
-
|
|
|
|
|
|
|
| 169 |
except Exception as e:
|
|
|
|
|
|
|
| 170 |
return {"error": f"Failed to get transcript: {str(e)}"}
|
| 171 |
|
| 172 |
@tool
|
|
|
|
| 162 |
url: The full URL of the YouTube video.
|
| 163 |
"""
|
| 164 |
try:
|
| 165 |
+
response = requests.get("https://www.google.com", timeout=5)
|
| 166 |
+
print(f"--- DEBUG: Network test successful. Status code: {response.status_code} ---")
|
| 167 |
+
|
| 168 |
+
# --- STEP 2: IF THE TEST PASSES, TRY THE YOUTUBE LOADER ---
|
| 169 |
+
print(f"--- DEBUG: Attempting to load YouTube URL: {url} ---")
|
| 170 |
loader = YoutubeLoader.from_youtube_url(url, add_video_info=True)
|
| 171 |
docs = loader.load()
|
| 172 |
content = "\n\n".join([doc.page_content for doc in docs])
|
| 173 |
+
print("--- DEBUG: YouTube transcript loaded successfully. ---")
|
| 174 |
+
return {"transcript": content[:4000]}
|
| 175 |
+
|
| 176 |
except Exception as e:
|
| 177 |
+
# This will now catch errors from either the network test or the YoutubeLoader
|
| 178 |
+
print(f"--- DEBUG: An error occurred in the tool. Error type: {type(e).__name__} ---")
|
| 179 |
return {"error": f"Failed to get transcript: {str(e)}"}
|
| 180 |
|
| 181 |
@tool
|