Update app.py
Browse files
app.py
CHANGED
|
@@ -11,39 +11,13 @@ from llama_index.tools.arxiv import ArxivToolSpec
|
|
| 11 |
from llama_index.core.agent.workflow import AgentWorkflow
|
| 12 |
from llama_index.core.tools import FunctionTool
|
| 13 |
|
|
|
|
|
|
|
|
|
|
| 14 |
# (Keep Constants as is)
|
| 15 |
# --- Constants ---
|
| 16 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 17 |
|
| 18 |
-
# --- Basic Agent Definition ---
|
| 19 |
-
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 20 |
-
class BasicAgent:
|
| 21 |
-
def __init__(self):
|
| 22 |
-
llm = HuggingFaceInferenceAPI(
|
| 23 |
-
model_name="Qwen/Qwen2.5-Coder-32B-Instruct",
|
| 24 |
-
)
|
| 25 |
-
|
| 26 |
-
self.agent = AgentWorkflow.from_tools_or_functions(
|
| 27 |
-
[
|
| 28 |
-
*ArxivToolSpec().to_tool_list(),
|
| 29 |
-
],
|
| 30 |
-
llm=llm,
|
| 31 |
-
)
|
| 32 |
-
|
| 33 |
-
print("BasicAgent initialized.")
|
| 34 |
-
|
| 35 |
-
def __call__(self, question: str) -> str:
|
| 36 |
-
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
| 37 |
-
|
| 38 |
-
fixed_answer = asyncio.run(self.generate_answer(question))
|
| 39 |
-
|
| 40 |
-
print(f"Agent returning fixed answer: {fixed_answer}")
|
| 41 |
-
return fixed_answer
|
| 42 |
-
|
| 43 |
-
async def generate_answer(self, question: str) -> str:
|
| 44 |
-
response = await self.agent.run(question)
|
| 45 |
-
return response
|
| 46 |
-
|
| 47 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 48 |
"""
|
| 49 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 11 |
from llama_index.core.agent.workflow import AgentWorkflow
|
| 12 |
from llama_index.core.tools import FunctionTool
|
| 13 |
|
| 14 |
+
from my_agent import BasicAgent
|
| 15 |
+
|
| 16 |
+
|
| 17 |
# (Keep Constants as is)
|
| 18 |
# --- Constants ---
|
| 19 |
DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 22 |
"""
|
| 23 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|