cowrycode commited on
Commit
24bcf77
·
verified ·
1 Parent(s): 3f8ea42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -31,19 +31,15 @@ class BasicAgent:
31
  [wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
32
  llm=self.llm,
33
  )
34
- def __call__(self, question: str) -> str:
35
- try:
36
- loop = asyncio.get_running_loop()
37
- except RuntimeError:
38
- loop = asyncio.new_event_loop()
39
- asyncio.set_event_loop(loop)
40
 
41
- # Fix for notebooks / AnyIO threads
42
- nest_asyncio.apply(loop)
43
-
44
- # Run async agent synchronously
45
- return loop.run_until_complete(self.llamaindex_agent.run(question))
46
 
 
 
47
  #print(f"Agent received question (first 50 chars): {question[:50]}...")
48
  #fixed_answer = "This is a default answer."
49
  #fixed_answer = self.llamaindex_agent.run(question)
 
31
  [wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
32
  llm=self.llm,
33
  )
 
 
 
 
 
 
34
 
35
+ async def run(self, question: str) -> str:
36
+ print(f"Agent received question (first 50 chars): {question[:50]}...")
37
+ answer = await self.llamaindex_agent.run(question)
38
+ print(f"Agent returning answer: {answer}")
39
+ return answer
40
 
41
+ def __call__(self, question: str) -> str:
42
+ return run(question)
43
  #print(f"Agent received question (first 50 chars): {question[:50]}...")
44
  #fixed_answer = "This is a default answer."
45
  #fixed_answer = self.llamaindex_agent.run(question)