from langgraph.prebuilt import create_react_agent
from get_comments import (
analyze_comments_from_url,
get_comments_from_url,
get_video_info,
)
from search_videos import search_youtube_by_query
from get_video_subtitles import get_transcript_from_url
from llm_helpers import llm
from langchain_core.messages import (
SystemMessage,
HumanMessage,
AIMessage,
BaseMessage,
ToolMessage,
FunctionMessage,
)
from langchain_experimental.tools.python.tool import PythonREPLTool
import datetime as dt
repl_tools = PythonREPLTool()
tools = [
analyze_comments_from_url,
get_comments_from_url,
search_youtube_by_query,
get_transcript_from_url,
get_video_info,
repl_tools,
]
system_prompt = """You're youtube topic analysis agent. You can analyze various topics by searching for videos, analyzing comments, and extracting transcripts.
First search for videos on this topic, then check if videos is relevant to the topic by title, description etc. After geting the relevant videos, analyze comments on the videos to get insights about the topic. If you find a video that is not relevant, skip it and move to the next one. Prioritize videos with high view count and engagement, same for comments.
"""
agent = create_react_agent(
model=llm,
tools=tools,
)
print("Agent created successfully.")
messages: list[BaseMessage] = [SystemMessage(content=system_prompt)]
prompt = """Current topic is Lord of mysteries episode 1 and 2. Find total views on the topic, find common themes.
Create a in-depth analysis of the topic check 100 videos, including the following information:
1. Total number of videos found
2. Total number of comments analyzed
3. Common themes found in the comments
4. Any notable insights or trends observed
5. Check how youtubers are reacting to the anime
Also you need to add references to the videos you analyzed, so that I can check them later.
Topic info:
Lord of Mysteries also knows as Guimi Zhi Zhu: Xiaochou Pian is a Chinese web novel written by Cuttlefish That Loves Diving. Currently the anime is being aired and first two episodes are out.
Synopsis:
In a Victorian world of steam, dreadnoughts, and occult horrors, Zhou Mingrui awakens as Klein Moretti. He walks a razor's edge between light and darkness, entangled with warring Churches. This is the legend of unlimited potential...and unspeakable danger.
Current date and time is {current_date_time}.
"""
messages.append(
HumanMessage(
content=prompt.format(
current_date_time=dt.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
)
)
)
for step in agent.stream(
{"messages": messages},
stream_mode="values",
):
step["messages"][-1].pretty_print()