sarath2803 commited on
Commit
3c710c6
·
verified ·
1 Parent(s): 71cb3e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -6
app.py CHANGED
@@ -12,6 +12,7 @@ from langgraph.graph import StateGraph, END
12
  from langchain_openai import ChatOpenAI
13
  from langchain_core.messages import HumanMessage
14
  from langchain_community.document_loaders import WikipediaLoader
 
15
 
16
  # (Keep Constants as is)
17
  # --- Constants ---
@@ -123,6 +124,31 @@ def wikipedia_tool(query: str) -> str:
123
  except Exception as e:
124
  return f"Wikipedia search error: {e}"
125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
126
 
127
 
128
 
@@ -135,11 +161,23 @@ class BasicAgent:
135
  def __init__(self):
136
  print("BasicAgent initialized.")
137
  token=os.environ["OPENROUTER_API_KEY"]
138
- self.system_prompt= """You are a helpful assistant tasked with answering questions using a set of tools.
139
- Now, I will ask you a question. Report your thoughts, and finish your answer with the following template:
140
- FINAL ANSWER: [YOUR FINAL ANSWER].
141
- YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string.
142
- Your answer should only start with "FINAL ANSWER: ", then follows with the answer.
 
 
 
 
 
 
 
 
 
 
 
 
143
 
144
  """
145
 
@@ -149,7 +187,7 @@ Your answer should only start with "FINAL ANSWER: ", then follows with the answe
149
  provider="auto" # Use openrouter as the provider
150
  )
151
  self.agent= CodeAgent(
152
- tools = [add, subtract, multiply, divide, web_search, image_generation_tool],
153
  model=model,
154
  )
155
  def __call__(self, question: str, context: str = "") -> str:
 
12
  from langchain_openai import ChatOpenAI
13
  from langchain_core.messages import HumanMessage
14
  from langchain_community.document_loaders import WikipediaLoader
15
+ from youtube_transcript_api import YouTubeTranscriptApi
16
 
17
  # (Keep Constants as is)
18
  # --- Constants ---
 
124
  except Exception as e:
125
  return f"Wikipedia search error: {e}"
126
 
127
+ @tool
128
+ def youtube_transcript_tool(video_id: str,query:str) -> str:
129
+ """
130
+ Fetches the transcript of a YouTube video.
131
+
132
+ Args:
133
+ video_id (str): The YouTube video ID.
134
+ query (str): The question to be answered based on the transcript.
135
+
136
+ Returns:
137
+ str: The transcript text or an error message.
138
+ """
139
+ try:
140
+ transcript = YouTubeTranscriptApi.get_transcript(video_id)
141
+ question = f"Answer the question based on the transcript: {query}"
142
+ prompt = (
143
+ f"Given the following YouTube transcript, answer the question as directly as possible:\n"
144
+ f"Question: {question}\n"
145
+ f"Transcript: {transcript}\n"
146
+ f"Answer:"
147
+ )
148
+ answer = openrouter_inference(prompt)
149
+ except Exception as e:
150
+ return f"Transcript error: {e}"
151
+
152
 
153
 
154
 
 
161
  def __init__(self):
162
  print("BasicAgent initialized.")
163
  token=os.environ["OPENROUTER_API_KEY"]
164
+ self.system_prompt= """You are a helpful assistant.
165
+ You will answer questions based on the provided context.
166
+ You will always return a valid answer, even if the question is not clear or the context is insufficient.
167
+ Always return a valid answer after validating the source.
168
+
169
+ Your final answer should be in the following format:
170
+ "your answer here".
171
+
172
+ If you are asked question related to numbers,return the answer in numeric format.
173
+ If you want more details about a topic,person, you can use the wikipedia tool.
174
+ If you want to perform web search to find the answer, use the web_search tool.
175
+ If you are given a text which is not known try to rearrange the words and characters if needed to form a valid answer.
176
+ If you are asked to find a specific person form a work,search the work using the web_search_tool or wikipedia_tool and find the person and return the person's name.
177
+ If you are given an youtube video then use the youtube_transcript_tool to get the transcript of the video and then answer the question based on the transcript.
178
+ If you are given a task to create an image, you can use the image_generation_tool.
179
+
180
+ Answer only what is asked, do not add any additional information.
181
 
182
  """
183
 
 
187
  provider="auto" # Use openrouter as the provider
188
  )
189
  self.agent= CodeAgent(
190
+ tools = [add, subtract, multiply, divide, web_search, image_generation_tool,youtube_transcript_tool, wikipedia_tool],
191
  model=model,
192
  )
193
  def __call__(self, question: str, context: str = "") -> str: