cowrycode commited on
Commit
2ba2c5a
·
verified ·
1 Parent(s): 6770c84

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -4,6 +4,7 @@ import requests
4
  import inspect
5
  import pandas as pd
6
 
 
7
  from llama_index.core.agent.workflow import AgentWorkflow
8
  from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
9
  from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_tool
@@ -30,9 +31,21 @@ class BasicAgent:
30
  llm=self.llm,
31
  )
32
  def __call__(self, question: str) -> str:
 
 
 
 
 
 
 
 
 
 
 
 
33
  print(f"Agent received question (first 50 chars): {question[:50]}...")
34
  #fixed_answer = "This is a default answer."
35
- fixed_answer = self.llamaindex_agent.run(question)
36
  print(f"Agent returning fixed answer: {fixed_answer}")
37
  return fixed_answer
38
 
 
4
  import inspect
5
  import pandas as pd
6
 
7
+ import asyncio
8
  from llama_index.core.agent.workflow import AgentWorkflow
9
  from llama_index.llms.huggingface_api import HuggingFaceInferenceAPI
10
  from youtube_tool import youtube_transcript_tool, youtube_transcript_snippet_tool
 
31
  llm=self.llm,
32
  )
33
  def __call__(self, question: str) -> str:
34
+ fixed_answer = ''
35
+ # Wrap async run in synchronous call
36
+ loop = asyncio.get_event_loop()
37
+ if loop.is_running():
38
+ # Use nest_asyncio for notebooks / interactive environments
39
+ import nest_asyncio
40
+ nest_asyncio.apply()
41
+ fixed_answer = loop.run_until_complete(self.llamaindex_agent.run(question))
42
+ else:
43
+ fixed_answer = loop.run_until_complete(self.llamaindex_agent.run(question))
44
+
45
+
46
  print(f"Agent received question (first 50 chars): {question[:50]}...")
47
  #fixed_answer = "This is a default answer."
48
+ #fixed_answer = self.llamaindex_agent.run(question)
49
  print(f"Agent returning fixed answer: {fixed_answer}")
50
  return fixed_answer
51