Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,34 +15,35 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
15 |
# --- GAIA-Optimized Agent Implementation ---
|
16 |
from huggingface_hub import InferenceClient, login
|
17 |
|
|
|
18 |
class BasicAgent:
|
19 |
-
def __init__(self
|
20 |
-
|
21 |
-
self.hf_api = HfApi(token=hf_token)
|
22 |
-
|
23 |
-
# Verify model access
|
24 |
-
try:
|
25 |
-
self.hf_api.model_info("meta-llama/Meta-Llama-3-70B-Instruct")
|
26 |
-
except Exception as e:
|
27 |
-
raise RuntimeError(f"Model access failed: {str(e)}")
|
28 |
-
|
29 |
-
# Initialize inference client
|
30 |
self.client = InferenceClient(
|
31 |
-
model="
|
32 |
-
token=
|
33 |
-
timeout=60
|
34 |
)
|
35 |
-
|
36 |
def __call__(self, question: str) -> str:
|
|
|
37 |
try:
|
|
|
38 |
response = self.client.text_generation(
|
39 |
-
prompt=f"
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
)
|
43 |
-
|
|
|
|
|
44 |
except Exception:
|
45 |
-
return ""
|
46 |
|
47 |
|
48 |
|
|
|
15 |
# --- GAIA-Optimized Agent Implementation ---
|
16 |
from huggingface_hub import InferenceClient, login
|
17 |
|
18 |
+
|
19 |
class BasicAgent:
|
20 |
+
def __init__(self):
|
21 |
+
# Use free-tier compatible Qwen model via Inference API
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
self.client = InferenceClient(
|
23 |
+
model="Qwen/Qwen2-7B-Instruct",
|
24 |
+
token=os.environ.get("HF_TOKEN", "free") # Works without token
|
|
|
25 |
)
|
26 |
+
|
27 |
def __call__(self, question: str) -> str:
|
28 |
+
"""Optimized for GAIA scoring without hardware upgrades"""
|
29 |
try:
|
30 |
+
# GAIA-optimized prompt template
|
31 |
response = self.client.text_generation(
|
32 |
+
prompt=f"""<|im_start|>system
|
33 |
+
Answer with ONLY the exact value requested, no explanations.<|im_end|>
|
34 |
+
<|im_start|>user
|
35 |
+
{question}<|im_end|>
|
36 |
+
<|im_start|>assistant
|
37 |
+
""",
|
38 |
+
max_new_tokens=50,
|
39 |
+
temperature=0.01,
|
40 |
+
stop_sequences=["<|im_end|>"]
|
41 |
)
|
42 |
+
|
43 |
+
# Strict answer extraction
|
44 |
+
return response.split("<|im_start|>assistant")[-1].split("<|im_end|>")[0].strip()
|
45 |
except Exception:
|
46 |
+
return "" # Empty answers preserve scoring eligibility
|
47 |
|
48 |
|
49 |
|