ishan-25 commited on
Commit
60ef454
Β·
verified Β·
1 Parent(s): 5b9569a

Update engine.py

Browse files
Files changed (1) hide show
  1. engine.py +11 -12
engine.py CHANGED
@@ -121,9 +121,19 @@ except ImportError:
121
 
122
  '''
123
 
 
 
 
 
 
 
 
 
124
  def ask_llm(prompt: str, temperature: float = 0.7, max_tokens: int = 512) -> str:
125
  try:
 
126
  safe_temp = temperature if temperature > 0 else 0.01
 
127
  response = client.text_generation(
128
  prompt,
129
  max_new_tokens=max_tokens,
@@ -133,29 +143,18 @@ def ask_llm(prompt: str, temperature: float = 0.7, max_tokens: int = 512) -> str
133
 
134
  cleaned = response.replace("<s>", "").replace("</s>", "").strip()
135
 
136
- # 🚨 THE SMOKING GUN PRINT: This will print out exactly what the LLM answers
137
  print("\n" + "="*40)
138
  print(f"[LLM RAW OUTPUT]: '{cleaned}'")
139
  print("="*40 + "\n")
140
 
141
  return cleaned
142
  except Exception as e:
143
- # 🚨 THE CRASH PRINT: If the token is missing or network fails, this tells you why
144
  print("\n" + "❌"*20)
145
  print(f"[API ERROR DETECTED]: {str(e)}")
146
  print("❌"*20 + "\n")
147
  return ""
148
 
149
-
150
-
151
-
152
-
153
- # ── Agent instances (singletons, created once at startup) ─────────────────────
154
- _validator = ValidatorAgent(ask_llm)
155
- _q_gen = QuestionGenAgent(ask_llm)
156
- _scorer = ScorerAgent(ask_llm)
157
-
158
-
159
  # ── History helpers ────────────────────────────────────────────────────────────
160
  # (Removed load_history and save_history for HF Spaces compatibility.
161
  # State is now tracked purely via Gradio's gr.State session variables.)
 
121
 
122
  '''
123
 
124
+ # ── Hugging Face LLM call ────────────────────────────────────────────────────
125
+ from huggingface_hub import InferenceClient
126
+ import os
127
+ from config import HF_MODEL
128
+
129
+ # 🚨 THIS IS THE MISSING LINE THAT WAS ACCIDENTALLY DELETED:
130
+ client = InferenceClient(model=HF_MODEL, token=os.environ.get("HF_TOKEN"))
131
+
132
  def ask_llm(prompt: str, temperature: float = 0.7, max_tokens: int = 512) -> str:
133
  try:
134
+ # Hugging Face API requirements demand a temperature reading strictly > 0
135
  safe_temp = temperature if temperature > 0 else 0.01
136
+
137
  response = client.text_generation(
138
  prompt,
139
  max_new_tokens=max_tokens,
 
143
 
144
  cleaned = response.replace("<s>", "").replace("</s>", "").strip()
145
 
146
+ # This tracks successful outputs cleanly in your logs console
147
  print("\n" + "="*40)
148
  print(f"[LLM RAW OUTPUT]: '{cleaned}'")
149
  print("="*40 + "\n")
150
 
151
  return cleaned
152
  except Exception as e:
 
153
  print("\n" + "❌"*20)
154
  print(f"[API ERROR DETECTED]: {str(e)}")
155
  print("❌"*20 + "\n")
156
  return ""
157
 
 
 
 
 
 
 
 
 
 
 
158
  # ── History helpers ────────────────────────────────────────────────────────────
159
  # (Removed load_history and save_history for HF Spaces compatibility.
160
  # State is now tracked purely via Gradio's gr.State session variables.)