Spaces:
Sleeping

byte-vortex commited on
Commit
720ad00
·
verified ·
1 Parent(s): 1b0696c

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. game/engine.py +2 -20
game/engine.py CHANGED
@@ -274,51 +274,33 @@ def _companion_answer(message, current, context):
274
 
275
  def _local_pipeline_answer(message, current, context):
276
  print("PIPELINE ANSWER CALLED")
277
- """
278
- Ask the locally loaded transformers pipeline for Myco's reply.
279
- Returns None if the pipeline is unavailable so the caller can fall back.
280
- """
281
  pipe = _get_pipeline()
282
  print("PIPE:", pipe)
283
  if not pipe:
284
  return None
285
-
286
  messages = _build_messages(message, current, context)
287
  try:
288
- # BUG FIX: use the chat-template path so the pipeline accepts a list
289
- # of dicts correctly. Pass tokenizer=pipe.tokenizer to ensure the
290
- # chat template is applied, then decode only the new tokens.
291
  outputs = pipe(
292
  messages,
293
  max_new_tokens=90,
294
  temperature=0.8,
295
  do_sample=True,
296
- return_full_text=False, # BUG FIX: only return newly generated text
297
  )
298
-
299
  print("========== MYCO OUTPUT ==========")
300
  print(outputs)
301
  print("=================================")
302
-
303
- # BUG FIX: removed duplicate `last = ...` assignment from original.
304
- # With return_full_text=False, generated_text is a plain string.
305
  generated = outputs[0].get("generated_text", "")
306
  print("GENERATED TYPE:", type(generated))
307
  print("GENERATED VALUE:", repr(generated))
308
-
309
- # Handle both string output (return_full_text=False) and list output
310
- # (return_full_text=True, older transformers versions).
311
  if isinstance(generated, list):
312
  last = generated[-1]
313
  if isinstance(last, dict):
314
  return (last.get("content") or "").strip() or None
315
  return str(last).strip() or None
316
-
317
  return str(generated).strip() or None
318
-
319
  except Exception as exc:
320
- import traceback
321
- print("[Myco] Pipeline inference error:")
322
  traceback.print_exc()
323
  return None
324
 
 
274
 
275
  def _local_pipeline_answer(message, current, context):
276
  print("PIPELINE ANSWER CALLED")
 
 
 
 
277
  pipe = _get_pipeline()
278
  print("PIPE:", pipe)
279
  if not pipe:
280
  return None
 
281
  messages = _build_messages(message, current, context)
282
  try:
 
 
 
283
  outputs = pipe(
284
  messages,
285
  max_new_tokens=90,
286
  temperature=0.8,
287
  do_sample=True,
288
+ return_full_text=False,
289
  )
 
290
  print("========== MYCO OUTPUT ==========")
291
  print(outputs)
292
  print("=================================")
 
 
 
293
  generated = outputs[0].get("generated_text", "")
294
  print("GENERATED TYPE:", type(generated))
295
  print("GENERATED VALUE:", repr(generated))
 
 
 
296
  if isinstance(generated, list):
297
  last = generated[-1]
298
  if isinstance(last, dict):
299
  return (last.get("content") or "").strip() or None
300
  return str(last).strip() or None
 
301
  return str(generated).strip() or None
 
302
  except Exception as exc:
303
+ import traceback
 
304
  traceback.print_exc()
305
  return None
306