abhi1294 commited on
Commit
1e22ea2
·
1 Parent(s): 0d014aa

Fix gradio version conflict

Browse files
Files changed (4) hide show
  1. __pycache__/agent.cpython-313.pyc +0 -0
  2. agent.py +8 -11
  3. app.py +0 -1
  4. llm_client.py +38 -0
__pycache__/agent.cpython-313.pyc CHANGED
Binary files a/__pycache__/agent.cpython-313.pyc and b/__pycache__/agent.cpython-313.pyc differ
 
agent.py CHANGED
@@ -6,6 +6,7 @@ from typing import Optional
6
  from prompts import build_solver_prompt
7
  from tools import TaskFileTool
8
  from utils import extract_final_answer, normalize_final_answer
 
9
 
10
 
11
  @dataclass
@@ -24,12 +25,11 @@ class SubmissionAgent:
24
  - Return ONLY the final answer string
25
  - Stay framework-agnostic for now so we can plug in any LLM later
26
  """
27
-
28
- def __init__(self, llm_client=None, config: Optional[AgentConfig] = None):
29
- self.llm_client = llm_client
30
  self.config = config or AgentConfig()
 
31
  self.task_file_tool = TaskFileTool(api_base_url=self.config.api_base_url)
32
-
33
  def __call__(self, question: str, task_id: Optional[str] = None) -> str:
34
  """
35
  Main entry point used by app.py.
@@ -67,12 +67,9 @@ class SubmissionAgent:
67
  """
68
  prompt = build_solver_prompt(question=question, context=context)
69
 
70
- if self.llm_client is None:
71
- # Safe placeholder so the app can run while we build the stack.
72
- # We will replace this with a real model client later.
73
- return "PLACEHOLDER"
74
-
75
  try:
76
  return self.llm_client.generate(prompt)
77
- except Exception:
78
- return "PLACEHOLDER"
 
 
 
6
  from prompts import build_solver_prompt
7
  from tools import TaskFileTool
8
  from utils import extract_final_answer, normalize_final_answer
9
+ from llm_client import HFLLMClient
10
 
11
 
12
  @dataclass
 
25
  - Return ONLY the final answer string
26
  - Stay framework-agnostic for now so we can plug in any LLM later
27
  """
28
+ def __init__(self, config: Optional[AgentConfig] = None, llm_client=None):
 
 
29
  self.config = config or AgentConfig()
30
+ self.llm_client = llm_client or HFLLMClient()
31
  self.task_file_tool = TaskFileTool(api_base_url=self.config.api_base_url)
32
+
33
  def __call__(self, question: str, task_id: Optional[str] = None) -> str:
34
  """
35
  Main entry point used by app.py.
 
67
  """
68
  prompt = build_solver_prompt(question=question, context=context)
69
 
 
 
 
 
 
70
  try:
71
  return self.llm_client.generate(prompt)
72
+ except Exception as e:
73
+ print(f"LLM generation error: {e}")
74
+ return ""
75
+
app.py CHANGED
@@ -187,7 +187,6 @@ with gr.Blocks() as demo:
187
 
188
  run_button.click(
189
  fn=run_and_submit_all,
190
- inputs=[login_button],
191
  outputs=[status_output, results_table],
192
  )
193
 
 
187
 
188
  run_button.click(
189
  fn=run_and_submit_all,
 
190
  outputs=[status_output, results_table],
191
  )
192
 
llm_client.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from huggingface_hub import InferenceClient
3
+ from dotenv import load_dotenv
4
+
5
+ load_dotenv()
6
+
7
+
8
+ class HFLLMClient:
9
+ def __init__(self):
10
+ self.api_key = os.getenv("HF_TOKEN")
11
+ print("HF token present:", bool(self.api_key))
12
+
13
+ if not self.api_key:
14
+ raise ValueError("HF_TOKEN is not set")
15
+
16
+ self.model = "Qwen/Qwen2.5-7B-Instruct"
17
+ self.client = InferenceClient(
18
+ provider="auto",
19
+ api_key=self.api_key,
20
+ )
21
+
22
+ def generate(self, prompt: str) -> str:
23
+ try:
24
+ output = self.client.chat_completion(
25
+ model=self.model,
26
+ messages=[
27
+ {"role": "user", "content": prompt}
28
+ ],
29
+ max_tokens=64,
30
+ temperature=0.1,
31
+ )
32
+
33
+ text = output.choices[0].message.content
34
+ print("LLM response preview:", str(text)[:300])
35
+ return str(text)
36
+
37
+ except Exception as e:
38
+ raise ValueError(f"Inference call failed: {e}")