Update agent.py
Browse files
agent.py
CHANGED
|
@@ -10,12 +10,12 @@ from langgraph.prebuilt import tools_condition
|
|
| 10 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 11 |
from langchain_core.tools import tool
|
| 12 |
from langchain_community.document_loaders import WikipediaLoader
|
| 13 |
-
from
|
| 14 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 15 |
from langchain_tavily import TavilySearch
|
| 16 |
import tempfile
|
| 17 |
import pandas as pd
|
| 18 |
-
|
| 19 |
load_dotenv()
|
| 20 |
|
| 21 |
# ReAct System Prompt
|
|
@@ -108,25 +108,14 @@ def load_youtube_transcript(url: str, add_video_info: bool = True, language: Lis
|
|
| 108 |
|
| 109 |
Args:
|
| 110 |
url: YouTube video URL
|
| 111 |
-
|
| 112 |
-
language: List of language codes in descending priority
|
| 113 |
-
translation: Language to translate transcript to
|
| 114 |
"""
|
| 115 |
try:
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
language=language,
|
| 120 |
-
translation=translation
|
| 121 |
-
)
|
| 122 |
-
docs = loader.load()
|
| 123 |
-
|
| 124 |
-
formatted_transcript = "\n\n---\n\n".join([
|
| 125 |
-
f'<Document source="{doc.metadata.get("source", "")}" title="{doc.metadata.get("title", "")}" author="{doc.metadata.get("author", "")}" length="{doc.metadata.get("length", "")}"/>\n{doc.page_content}\n</Document>'
|
| 126 |
-
for doc in docs
|
| 127 |
-
])
|
| 128 |
|
| 129 |
-
return {"youtube_transcript":
|
| 130 |
except Exception as e:
|
| 131 |
return f"Error loading YouTube transcript: {str(e)}"
|
| 132 |
|
|
@@ -645,7 +634,7 @@ class LangGraphAgent:
|
|
| 645 |
|
| 646 |
if __name__ == "__main__":
|
| 647 |
agent = LangGraphAgent()
|
| 648 |
-
question = "
|
| 649 |
answer = agent(question)
|
| 650 |
|
| 651 |
|
|
|
|
| 10 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 11 |
from langchain_core.tools import tool
|
| 12 |
from langchain_community.document_loaders import WikipediaLoader
|
| 13 |
+
from youtube_transcript_api import YouTubeTranscriptApi
|
| 14 |
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 15 |
from langchain_tavily import TavilySearch
|
| 16 |
import tempfile
|
| 17 |
import pandas as pd
|
| 18 |
+
import numpy as np
|
| 19 |
load_dotenv()
|
| 20 |
|
| 21 |
# ReAct System Prompt
|
|
|
|
| 108 |
|
| 109 |
Args:
|
| 110 |
url: YouTube video URL
|
| 111 |
+
|
|
|
|
|
|
|
| 112 |
"""
|
| 113 |
try:
|
| 114 |
+
video_id = url.split("v=")[1]
|
| 115 |
+
ytt_api = YouTubeTranscriptApi()
|
| 116 |
+
docs = ytt_api.fetch(video_id)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
+
return {"youtube_transcript": docs}
|
| 119 |
except Exception as e:
|
| 120 |
return f"Error loading YouTube transcript: {str(e)}"
|
| 121 |
|
|
|
|
| 634 |
|
| 635 |
if __name__ == "__main__":
|
| 636 |
agent = LangGraphAgent()
|
| 637 |
+
question = "The attached Excel file contains the sales of menu items for a local fast-food chain. What were the total sales that the chain made from food (not including drinks)? Express your answer in USD with two decimal places. task_id: 1234567890"
|
| 638 |
answer = agent(question)
|
| 639 |
|
| 640 |
|