Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,21 +48,34 @@ class BasicAgent:
|
|
| 48 |
return self.run(question)
|
| 49 |
#return self.agent.run(question)
|
| 50 |
|
| 51 |
-
|
| 52 |
-
|
| 53 |
llm = HuggingFaceInferenceAPI(
|
| 54 |
-
model_name="deepseek-ai/DeepSeek-R1-0528",
|
| 55 |
token=api_key,
|
| 56 |
-
provider="auto"
|
| 57 |
-
max_iterations=10
|
| 58 |
-
)
|
| 59 |
-
agent = AgentWorkflow.from_tools_or_functions(
|
| 60 |
-
[wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool,
|
| 61 |
-
round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
|
| 62 |
-
llm=llm
|
| 63 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 68 |
"""
|
|
@@ -84,7 +97,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 84 |
submit_url = f"{api_url}/submit"
|
| 85 |
|
| 86 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
| 87 |
-
agent = create_llamaindex_agent()
|
| 88 |
# try:
|
| 89 |
# agent = BasicAgent()
|
| 90 |
# except Exception as e:
|
|
@@ -139,24 +151,25 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
| 139 |
|
| 140 |
#3A
|
| 141 |
|
| 142 |
-
async def run_all_questions(questions_data):
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
answers_payload = asyncio.run(run_all_questions(questions_data))
|
|
|
|
| 160 |
|
| 161 |
#3B
|
| 162 |
|
|
|
|
| 48 |
return self.run(question)
|
| 49 |
#return self.agent.run(question)
|
| 50 |
|
| 51 |
+
|
| 52 |
+
async def smart_agent(questions_data: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
| 53 |
llm = HuggingFaceInferenceAPI(
|
| 54 |
+
model_name="deepseek-ai/DeepSeek-R1-0528",
|
| 55 |
token=api_key,
|
| 56 |
+
provider="auto"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
)
|
| 58 |
+
|
| 59 |
+
llamaindex_agent = AgentWorkflow.from_tools_or_functions(
|
| 60 |
+
[wikipedia_search_tool, youtube_transcript_tool, youtube_transcript_snippet_tool, round_to_two_decimals_tool, text_inverter_tool, google_web_search_tool],
|
| 61 |
+
llm=llm,
|
| 62 |
+
)
|
| 63 |
|
| 64 |
+
answers_payload = []
|
| 65 |
+
for item in questions_data:
|
| 66 |
+
task_id = item.get("task_id")
|
| 67 |
+
question_text = item.get("question")
|
| 68 |
+
if not task_id or question_text is None:
|
| 69 |
+
print(f"Skipping item with missing task_id or question: {item}")
|
| 70 |
+
continue
|
| 71 |
+
try:
|
| 72 |
+
answer = await llamaindex_agent.run(question_text) # await coroutine
|
| 73 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": answer})
|
| 74 |
+
print(f"Answered Task {task_id}: {answer[:50]}...")
|
| 75 |
+
except Exception as e:
|
| 76 |
+
answers_payload.append({"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"})
|
| 77 |
+
print(f"Error on Task {task_id}: {e}")
|
| 78 |
+
return answers_payload
|
| 79 |
|
| 80 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 81 |
"""
|
|
|
|
| 97 |
submit_url = f"{api_url}/submit"
|
| 98 |
|
| 99 |
# 1. Instantiate Agent ( modify this part to create your agent)
|
|
|
|
| 100 |
# try:
|
| 101 |
# agent = BasicAgent()
|
| 102 |
# except Exception as e:
|
|
|
|
| 151 |
|
| 152 |
#3A
|
| 153 |
|
| 154 |
+
# async def run_all_questions(questions_data):
|
| 155 |
+
# answers_payload = []
|
| 156 |
+
# for item in questions_data:
|
| 157 |
+
# task_id = item.get("task_id")
|
| 158 |
+
# question_text = item.get("question")
|
| 159 |
+
# if not task_id or question_text is None:
|
| 160 |
+
# print(f"Skipping item with missing task_id or question: {item}")
|
| 161 |
+
# continue
|
| 162 |
+
# try:
|
| 163 |
+
# answer = await agent.run(question_text) # await coroutine
|
| 164 |
+
# answers_payload.append({"task_id": task_id, "submitted_answer": answer})
|
| 165 |
+
# print(f"Answered Task {task_id}: {answer[:50]}...")
|
| 166 |
+
# except Exception as e:
|
| 167 |
+
# answers_payload.append({"task_id": task_id, "submitted_answer": f"AGENT ERROR: {e}"})
|
| 168 |
+
# print(f"Error on Task {task_id}: {e}")
|
| 169 |
+
# return answers_payload
|
| 170 |
+
|
| 171 |
+
#answers_payload = asyncio.run(run_all_questions(questions_data))
|
| 172 |
+
answers_payload = asyncio.run(smart_agent())
|
| 173 |
|
| 174 |
#3B
|
| 175 |
|