byte-vortex commited on
Commit
7541fd3
·
verified ·
1 Parent(s): da74a37

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. game/engine.py +25 -20
game/engine.py CHANGED
@@ -1,9 +1,26 @@
1
  """Core Myco gameplay — LLM is the primary game engine."""
2
 
3
  try:
4
- import spaces # must be imported before any CUDA/transformers code on HF Spaces
 
 
 
 
 
 
 
 
 
 
5
  except ImportError:
6
- pass # not running on HF Spaces, ignore
 
 
 
 
 
 
 
7
 
8
  import os
9
  import random
@@ -150,13 +167,7 @@ def _llm(prompt: str, context: dict | None = None) -> str | None:
150
  ]
151
 
152
  try:
153
- outputs = pipe(
154
- messages,
155
- max_new_tokens=80,
156
- temperature=0.85,
157
- do_sample=True,
158
- return_full_text=False,
159
- )
160
  print("========== MYCO OUTPUT ==========")
161
  print(outputs)
162
  print("=================================")
@@ -170,7 +181,7 @@ def _llm(prompt: str, context: dict | None = None) -> str | None:
170
  print(f"[Myco] Inference error: {exc}")
171
  traceback.print_exc()
172
  return None
173
-
174
 
175
  def _llm_with_history(history: list, user_message: str, context: dict) -> str | None:
176
  """Call Gemma with full conversation history for the chat interface."""
@@ -208,16 +219,10 @@ def _llm_with_history(history: list, user_message: str, context: dict) -> str |
208
  messages.append({"role": "user", "content": user_message})
209
 
210
  try:
211
- outputs = pipe(
212
- messages,
213
- max_new_tokens=80,
214
- temperature=0.85,
215
- do_sample=True,
216
- return_full_text=False,
217
- )
218
- print("========== MYCO CHAT OUTPUT ==========")
219
  print(outputs)
220
- print("======================================")
221
  generated = outputs[0].get("generated_text", "")
222
  if isinstance(generated, list):
223
  last = generated[-1]
@@ -225,7 +230,7 @@ def _llm_with_history(history: list, user_message: str, context: dict) -> str |
225
  return str(generated).strip() or None
226
  except Exception as exc:
227
  import traceback
228
- print(f"[Myco] Chat inference error: {exc}")
229
  traceback.print_exc()
230
  return None
231
 
 
1
  """Core Myco gameplay — LLM is the primary game engine."""
2
 
3
  try:
4
+ import spaces
5
+
6
+ @spaces.GPU
7
+ def _run_pipeline(pipe, messages):
8
+ return pipe(
9
+ messages,
10
+ max_new_tokens=80,
11
+ temperature=0.85,
12
+ do_sample=True,
13
+ return_full_text=False,
14
+ )
15
  except ImportError:
16
+ def _run_pipeline(pipe, messages):
17
+ return pipe(
18
+ messages,
19
+ max_new_tokens=80,
20
+ temperature=0.85,
21
+ do_sample=True,
22
+ return_full_text=False,
23
+ )
24
 
25
  import os
26
  import random
 
167
  ]
168
 
169
  try:
170
+ outputs = _run_pipeline(pipe, messages)
 
 
 
 
 
 
171
  print("========== MYCO OUTPUT ==========")
172
  print(outputs)
173
  print("=================================")
 
181
  print(f"[Myco] Inference error: {exc}")
182
  traceback.print_exc()
183
  return None
184
+
185
 
186
  def _llm_with_history(history: list, user_message: str, context: dict) -> str | None:
187
  """Call Gemma with full conversation history for the chat interface."""
 
219
  messages.append({"role": "user", "content": user_message})
220
 
221
  try:
222
+ outputs = _run_pipeline(pipe, messages)
223
+ print("========== MYCO OUTPUT ==========")
 
 
 
 
 
 
224
  print(outputs)
225
+ print("=================================")
226
  generated = outputs[0].get("generated_text", "")
227
  if isinstance(generated, list):
228
  last = generated[-1]
 
230
  return str(generated).strip() or None
231
  except Exception as exc:
232
  import traceback
233
+ print(f"[Myco] Inference error: {exc}")
234
  traceback.print_exc()
235
  return None
236