Facelook commited on
Commit
bca4c13
·
1 Parent(s): c1db38d

Trial and error.

Browse files
Files changed (1) hide show
  1. app.py +5 -34
app.py CHANGED
@@ -34,40 +34,11 @@ class BasicAgent:
34
  {"role": "user", "content": question}
35
  ]
36
 
37
- print(f"Messages prepared for model: {messages}")
38
-
39
  # Generate response
40
- if self.model and self.tokenizer:
41
- printf("Using local model for generation...")
42
-
43
- # Local model generation
44
- text = self.tokenizer.apply_chat_template(
45
- messages,
46
- tokenize=False,
47
- add_generation_prompt=True
48
- )
49
- model_inputs = self.tokenizer([text], return_tensors="pt").to(self.model.device)
50
-
51
- print(f"Model inputs prepared: {model_inputs}")
52
-
53
- generated_ids = self.model.generate(
54
- **model_inputs,
55
- max_new_tokens=512
56
- )
57
- generated_ids = [
58
- output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
59
- ]
60
-
61
- print(f"Generated IDs: {generated_ids}")
62
-
63
- answer = self.tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
64
- else:
65
- print("Using Inference API for generation...")
66
-
67
- # Fallback to Inference API
68
- response = self.client.chat(messages=messages)
69
- answer = response.content
70
-
71
  print(f"Agent generated response (first 50 chars): {answer[:50]}...")
72
  return answer
73
  except Exception as e:
@@ -202,7 +173,7 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
202
 
203
  # --- Build Gradio Interface using Blocks ---
204
  with gr.Blocks() as demo:
205
- gr.Markdown("# Basic Agent Evaluation Runner #2")
206
  gr.Markdown(
207
  """
208
  **Instructions:**
 
34
  {"role": "user", "content": question}
35
  ]
36
 
 
 
37
  # Generate response
38
+ print("Using Inference API for generation...")
39
+ response = self.client.text_generation(messages=messages)
40
+ print(f"Inference API response received. {len(response.choices)} choices.")
41
+ answer = response.choices[0].message.content
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  print(f"Agent generated response (first 50 chars): {answer[:50]}...")
43
  return answer
44
  except Exception as e:
 
173
 
174
  # --- Build Gradio Interface using Blocks ---
175
  with gr.Blocks() as demo:
176
+ gr.Markdown("# Basic Agent Evaluation Runner #3")
177
  gr.Markdown(
178
  """
179
  **Instructions:**