cowrycode commited on
Commit
fc99b6d
·
verified ·
1 Parent(s): 6ca0310

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -34
app.py CHANGED
@@ -29,10 +29,25 @@ class BasicAgent:
29
  provider="auto",
30
  max_iterations=10
31
  )
32
- self.agent = AgentWorkflow.from_tools_or_functions(
33
- [wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool,
34
- round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
35
- llm=self.llm
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
  )
37
 
38
  async def run(self, question: str) -> str:
@@ -66,11 +81,11 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
66
  submit_url = f"{api_url}/submit"
67
 
68
  # 1. Instantiate Agent ( modify this part to create your agent)
69
- # try:
70
- # agent = BasicAgent()
71
- # except Exception as e:
72
- # print(f"Error instantiating agent: {e}")
73
- # return f"Error initializing agent: {e}", None
74
  #In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
75
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
76
  print(agent_code)
@@ -121,32 +136,20 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
121
  #3A
122
 
123
  async def run_all_questions(questions_data):
124
- try:
125
- agent = BasicAgent()
126
- except Exception as e:
127
- print(f"Error instantiating agent: {e}")
128
- return f"Error initializing agent: {e}", None
129
- question_text = questions_data[0].get("question")
130
- task_id = questions_data[0].get("task_id")
131
- print(f"Processing my question 0 : : : : : : :")
132
- answer = await agent.run(question_text)
133
- print(f"Answered Task {task_id}: {answer[:50]}...")
134
  answers_payload = []
135
- # answers_payload.append({"task_id": task_id, "submitted_answer": answer})
136
- # answers_payload = []
137
- # for item in questions_data:
138
- # task_id = item.get("task_id")
139
- # question_text = item.get("question")
140
- # if not task_id or question_text is None:
141
- # print(f"Skipping item with missing task_id or question: {item}")
142
- # continue
143
- # try:
144
- # answer = await agent.run(question_text) # await coroutine
145
- # answers_payload.append({"task_id": task_id, "submitted_answer": answer})
146
- # print(f"Answered Task {task_id}: {answer[:50]}...")
147
- # except Exception as e:
148
- # answers_payload.append({"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"})
149
- # print(f"Error on Task {task_id}: {e}")
150
  return answers_payload
151
 
152
  answers_payload = asyncio.run(run_all_questions(questions_data))
 
29
  provider="auto",
30
  max_iterations=10
31
  )
32
+ # self.agent = AgentWorkflow.from_tools_or_functions(
33
+ # [wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool,
34
+ # round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
35
+ # llm=self.llm
36
+ # )
37
+
38
+ self.tools = [
39
+ wikipedia_search_tool,
40
+ youtube_transcript_tool,
41
+ youtube_transcript_snippet_tool,
42
+ round_to_two_decimals_tool,
43
+ text_inverter_tool,
44
+ google_web_search_tool
45
+ ]
46
+
47
+ self.agent = ReActAgent.from_tools(
48
+ tools=self.tools,
49
+ llm=self.llm,
50
+ verbose=True
51
  )
52
 
53
  async def run(self, question: str) -> str:
 
81
  submit_url = f"{api_url}/submit"
82
 
83
  # 1. Instantiate Agent ( modify this part to create your agent)
84
+ try:
85
+ agent = BasicAgent()
86
+ except Exception as e:
87
+ print(f"Error instantiating agent: {e}")
88
+ return f"Error initializing agent: {e}", None
89
  #In the case of an app running as a hugging Face space, this link points toward your codebase ( usefull for others so please keep it public)
90
  agent_code = f"https://huggingface.co/spaces/{space_id}/tree/main"
91
  print(agent_code)
 
136
  #3A
137
 
138
  async def run_all_questions(questions_data):
 
 
 
 
 
 
 
 
 
 
139
  answers_payload = []
140
+ for item in questions_data:
141
+ task_id = item.get("task_id")
142
+ question_text = item.get("question")
143
+ if not task_id or question_text is None:
144
+ print(f"Skipping item with missing task_id or question: {item}")
145
+ continue
146
+ try:
147
+ answer = await agent.run(question_text) # await coroutine
148
+ answers_payload.append({"task_id": task_id, "submitted_answer": answer})
149
+ print(f"Answered Task {task_id}: {answer[:50]}...")
150
+ except Exception as e:
151
+ answers_payload.append({"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"})
152
+ print(f"Error on Task {task_id}: {e}")
 
 
153
  return answers_payload
154
 
155
  answers_payload = asyncio.run(run_all_questions(questions_data))