Update app.py
Browse files
app.py
CHANGED
@@ -13,36 +13,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
14 |
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
self.llm = HfApiModel(
|
22 |
-
token=token,
|
23 |
-
model="microsoft/phi-2", # <— change this line for any other model
|
24 |
-
stop_sequences=["ANSWER:"], # stop as soon as it produces an answer
|
25 |
-
)
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
"Answer each question in ONE line that starts with “ANSWER: ” "
|
31 |
-
"and nothing else."
|
32 |
)
|
33 |
|
34 |
def __call__(self, question: str) -> str:
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
text = reply["content"].strip()
|
41 |
-
# ensure we only return the line after “ANSWER:”
|
42 |
-
if "ANSWER" in text:
|
43 |
-
text = text.split("ANSWER", 1)[-1].lstrip(": ").splitlines()[0]
|
44 |
-
text = f"ANSWER: {text}"
|
45 |
-
return text
|
46 |
|
47 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
48 |
"""
|
|
|
13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
14 |
class BasicAgent:
|
15 |
def __init__(self):
|
16 |
+
print("BasicAgent initialized.")
|
17 |
+
|
18 |
+
hf_token = os.getenv("HF_TOKEN")
|
19 |
+
if not hf_token:
|
20 |
+
raise ValueError("HF_TOKEN environment variable is not set.")
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
+
self.agent = CodeAgent(
|
23 |
+
tools=[DuckDuckGoSearchTool()],
|
24 |
+
model=HfApiModel(token=hf_token, model="microsoft/phi-2")
|
|
|
|
|
25 |
)
|
26 |
|
27 |
def __call__(self, question: str) -> str:
|
28 |
+
print(f"Agent received question (first 50 chars): {question[:50]}...")
|
29 |
+
fixed_answer = self.agent.run("You are a helpful assistant answering short factual questions. Answer the question: " + question, max_steps=1)
|
30 |
+
print(fixed_answer)
|
31 |
+
print(f"Agent returning fixed answer: {fixed_answer}")
|
32 |
+
return fixed_answer
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
35 |
"""
|