lovepreetsingh1996 commited on
Commit
cfaacf9
·
1 Parent(s): 9d812dd

fix: try again

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -33,11 +33,11 @@ class BasicAgent:
33
  # self.llm = Ollama(model="qwen2.5:7b", request_timeout=500)
34
  self.llm = Gemini(model_name="models/gemini-2.0-flash")
35
 
36
- def get_answers_from_youtube_transcript(youtube_link: str) -> str:
37
  try:
38
  loader = YoutubeTranscriptReader()
39
  documents = loader.load_data(
40
- ytlinks=[youtube_link]
41
  )
42
 
43
  text = documents[0].text_resource.text
@@ -46,21 +46,19 @@ class BasicAgent:
46
  except Exception as e:
47
  print("error", e)
48
 
49
- youtube_transcript_answer_tool = FunctionTool.from_defaults(
50
- get_answers_from_youtube_transcript,
51
- name="get_answers_from_youtube_transcript",
52
- description="Fetches transcript of the given youtube_link and returns matching answers based on query. To be called when video link is given.",
53
  )
54
 
55
- def web_page_reader(url: str, query: str) -> str:
56
  try:
57
  documents = SimpleWebPageReader(html_to_text=True).load_data(
58
  [url]
59
  )
60
- index = SummaryIndex.from_documents(documents)
61
- query_engine = index.as_query_engine()
62
- response = query_engine.query(query)
63
- return response.response
64
  except Exception as e:
65
  print("error in webpage", e)
66
 
@@ -105,7 +103,7 @@ class BasicAgent:
105
  description="Searches wikipedia and converts results into a high quality answer."
106
  )
107
 
108
- self.agent = AgentWorkflow.from_tools_or_functions([duckduckgo_search_tool, youtube_transcript_answer_tool, wikipedia_search_tool, web_page_reader_tool], llm=self.llm, system_prompt="You're an ai agent designed for question answering. Keep your answers concise or even one word when possible. You have access to a bunch of tools, utilise them well to reach answers.")
109
  print("BasicAgent initialized.")
110
 
111
  async def run_agent(self, question: str):
 
33
  # self.llm = Ollama(model="qwen2.5:7b", request_timeout=500)
34
  self.llm = Gemini(model_name="models/gemini-2.0-flash")
35
 
36
+ def load_video_transcript(video_link: str) -> str:
37
  try:
38
  loader = YoutubeTranscriptReader()
39
  documents = loader.load_data(
40
+ ytlinks=[video_link]
41
  )
42
 
43
  text = documents[0].text_resource.text
 
46
  except Exception as e:
47
  print("error", e)
48
 
49
+ load_video_transcript_tool = FunctionTool.from_defaults(
50
+ load_video_transcript,
51
+ name="load_video_transcript",
52
+ description="Loads transcript of the given video using the link.",
53
  )
54
 
55
+ def web_page_reader(url: str) -> str:
56
  try:
57
  documents = SimpleWebPageReader(html_to_text=True).load_data(
58
  [url]
59
  )
60
+
61
+ return { "web_page_read_reasult": "\n".join([doc.text for doc in documents]) }
 
 
62
  except Exception as e:
63
  print("error in webpage", e)
64
 
 
103
  description="Searches wikipedia and converts results into a high quality answer."
104
  )
105
 
106
+ self.agent = AgentWorkflow.from_tools_or_functions([duckduckgo_search_tool, load_video_transcript_tool, wikipedia_search_tool, web_page_reader_tool], llm=self.llm, system_prompt="You're an ai agent designed for question answering. Keep your answers concise or even one word when possible. You have access to a bunch of tools, utilise them well to reach answers.")
107
  print("BasicAgent initialized.")
108
 
109
  async def run_agent(self, question: str):