0r0b0r0s commited on
Commit
84fec8c
·
verified ·
1 Parent(s): 63affe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -20
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, hf_token: str):
20
- login(token=hf_token, add_to_git_credential=False)
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="meta-llama/Meta-Llama-3-70B-Instruct",
32
- token=hf_token,
33
- timeout=60
34
  )
35
-
36
  def __call__(self, question: str) -> str:
 
37
  try:
 
38
  response = self.client.text_generation(
39
- prompt=f"Question: {question}\nAnswer:",
40
- temperature=0.1,
41
- max_new_tokens=50
 
 
 
 
 
 
42
  )
43
- return response.split("Answer:")[-1].strip().split("\n")[0]
 
 
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