lucadipalma commited on
Commit
7a75ca8
·
1 Parent(s): 59048dd

add max_new_tokens to huggingface models; modifed graph initiation;

Browse files
pages/play.py CHANGED
@@ -9,7 +9,7 @@ from support.game_settings import TEAM_MODEL_PRESETS
9
  from support.utils import format_messages_as_feed, generate_team_html, plot_game_board_with_guesses
10
 
11
 
12
- graph = MyGraph()
13
  TEAM_OPTIONS = list(TEAM_MODEL_PRESETS.keys()) + ["random"]
14
 
15
 
@@ -54,6 +54,7 @@ with gr.Blocks(fill_width=True) as demo:
54
  turn_state = gr.State(value=0)
55
  winners_state = gr.State(value=None)
56
  api_keys_state = gr.State(value={})
 
57
 
58
  # Team selection (visible initially)
59
  with gr.Row(elem_id="game_setup_row"):
@@ -222,7 +223,8 @@ with gr.Blocks(fill_width=True) as demo:
222
  game_started: False,
223
  players_state: [],
224
  board_state: {},
225
- messages_state: []
 
226
  }
227
 
228
  # Create game with validated API keys
@@ -231,6 +233,9 @@ with gr.Blocks(fill_width=True) as demo:
231
  html = generate_team_html(game.players, starting_team)
232
  board_img = plot_game_board_with_guesses(game.board)
233
 
 
 
 
234
  return {
235
  game_state: game,
236
  new_game_btn: gr.update(visible=True),
@@ -243,7 +248,8 @@ with gr.Blocks(fill_width=True) as demo:
243
  board_state: game.board,
244
  messages_state: [],
245
  api_keys_state: api_keys,
246
- validation_status: gr.update(visible=True, value="✅ Game started successfully!")
 
247
  }
248
 
249
  def generate_new_game(red_team_choice, blue_team_choice, openai_key, google_key, anthropic_key, hf_key, current_api_keys):
@@ -262,7 +268,10 @@ with gr.Blocks(fill_width=True) as demo:
262
  html = generate_team_html(game.players, starting_team)
263
  board_img = plot_game_board_with_guesses(game.board)
264
 
265
- return game, html, board_img, game.players, game.board, [], gr.update(visible=True), api_keys
 
 
 
266
 
267
  def show_red_boss_input():
268
  return gr.Column(visible=True)
@@ -310,7 +319,7 @@ with gr.Blocks(fill_width=True) as demo:
310
  is_human_playing = True
311
  return html, players, gr.Column(visible=False), gr.Row(visible=False), gr.Row(visible=True), is_human_playing, gr.Button(visible=False)
312
 
313
- async def process_message(user_msg, messages, players, board, dropdown, guessed, chat_history, is_human_playing, turn):
314
  """Process user message and stream responses"""
315
 
316
  accumulated_messages = list(messages) if messages else []
@@ -331,10 +340,10 @@ with gr.Blocks(fill_width=True) as demo:
331
  # Don't update if no game is active
332
  if game_state is None:
333
  return gr.update() # No update
334
-
335
  if not guessed_words or not board:
336
  return gr.update() # No update
337
-
338
  logger.info(f"Calling update_plot: {guessed_words}")
339
  board_img = plot_game_board_with_guesses(board, guessed_words)
340
  return board_img
@@ -385,10 +394,10 @@ with gr.Blocks(fill_width=True) as demo:
385
  start_btn.click(
386
  fn=start_game,
387
  inputs=[red_team_dropdown, blue_team_dropdown, openai_api_input, google_api_input, anthropic_api_input, hf_api_input],
388
- outputs=[game_state, new_game_btn, start_btn, game_content, team_html, board_plot, game_started, players_state, board_state, messages_state, api_keys_state, validation_status]
389
  )
390
 
391
- # Update new game button click handler
392
  new_game_btn.click(
393
  fn=generate_new_game,
394
  inputs=[
@@ -408,7 +417,8 @@ with gr.Blocks(fill_width=True) as demo:
408
  board_state,
409
  messages_state,
410
  play_as_boss_section,
411
- api_keys_state
 
412
  ]
413
  )
414
 
@@ -464,12 +474,13 @@ with gr.Blocks(fill_width=True) as demo:
464
  outputs=[blue_boss_name_input]
465
  )
466
 
 
467
  send_btn.click(
468
  fn=lambda: gr.Button(interactive=False),
469
  outputs=[send_btn]
470
  ).then(
471
  fn=process_message,
472
- inputs=[user_input, messages_state, players_state, board_state, dropdown, guessed_words_state, chat_history_state, is_human_playing_state, turn_state],
473
  outputs=[message_feed, guessed_words_state, messages_state, board_state, chat_history_state, winners_state]
474
  ).then(
475
  fn=lambda: "",
 
9
  from support.utils import format_messages_as_feed, generate_team_html, plot_game_board_with_guesses
10
 
11
 
12
+ # graph = MyGraph()
13
  TEAM_OPTIONS = list(TEAM_MODEL_PRESETS.keys()) + ["random"]
14
 
15
 
 
54
  turn_state = gr.State(value=0)
55
  winners_state = gr.State(value=None)
56
  api_keys_state = gr.State(value={})
57
+ graph_instance = gr.State()
58
 
59
  # Team selection (visible initially)
60
  with gr.Row(elem_id="game_setup_row"):
 
223
  game_started: False,
224
  players_state: [],
225
  board_state: {},
226
+ messages_state: [],
227
+ graph_instance: None # ADD THIS
228
  }
229
 
230
  # Create game with validated API keys
 
233
  html = generate_team_html(game.players, starting_team)
234
  board_img = plot_game_board_with_guesses(game.board)
235
 
236
+ # CREATE GRAPH INSTANCE FOR THIS SESSION
237
+ graph = MyGraph() # ADD THIS
238
+
239
  return {
240
  game_state: game,
241
  new_game_btn: gr.update(visible=True),
 
248
  board_state: game.board,
249
  messages_state: [],
250
  api_keys_state: api_keys,
251
+ validation_status: gr.update(visible=True, value="✅ Game started successfully!"),
252
+ graph_instance: graph # ADD THIS
253
  }
254
 
255
  def generate_new_game(red_team_choice, blue_team_choice, openai_key, google_key, anthropic_key, hf_key, current_api_keys):
 
268
  html = generate_team_html(game.players, starting_team)
269
  board_img = plot_game_board_with_guesses(game.board)
270
 
271
+ # CREATE NEW GRAPH INSTANCE
272
+ graph = MyGraph() # ADD THIS
273
+
274
+ return game, html, board_img, game.players, game.board, [], gr.update(visible=True), api_keys, graph # ADD graph to return
275
 
276
  def show_red_boss_input():
277
  return gr.Column(visible=True)
 
319
  is_human_playing = True
320
  return html, players, gr.Column(visible=False), gr.Row(visible=False), gr.Row(visible=True), is_human_playing, gr.Button(visible=False)
321
 
322
+ async def process_message(user_msg, messages, players, board, dropdown, guessed, chat_history, is_human_playing, turn, graph): # ADD graph parameter
323
  """Process user message and stream responses"""
324
 
325
  accumulated_messages = list(messages) if messages else []
 
340
  # Don't update if no game is active
341
  if game_state is None:
342
  return gr.update() # No update
343
+
344
  if not guessed_words or not board:
345
  return gr.update() # No update
346
+
347
  logger.info(f"Calling update_plot: {guessed_words}")
348
  board_img = plot_game_board_with_guesses(board, guessed_words)
349
  return board_img
 
394
  start_btn.click(
395
  fn=start_game,
396
  inputs=[red_team_dropdown, blue_team_dropdown, openai_api_input, google_api_input, anthropic_api_input, hf_api_input],
397
+ outputs=[game_state, new_game_btn, start_btn, game_content, team_html, board_plot, game_started, players_state, board_state, messages_state, api_keys_state, validation_status, graph_instance] # ADD graph_instance
398
  )
399
 
400
+ # Update new_game_btn.click
401
  new_game_btn.click(
402
  fn=generate_new_game,
403
  inputs=[
 
417
  board_state,
418
  messages_state,
419
  play_as_boss_section,
420
+ api_keys_state,
421
+ graph_instance # ADD THIS
422
  ]
423
  )
424
 
 
474
  outputs=[blue_boss_name_input]
475
  )
476
 
477
+ # Update send_btn.click - THIS IS YOUR MAIN QUESTION
478
  send_btn.click(
479
  fn=lambda: gr.Button(interactive=False),
480
  outputs=[send_btn]
481
  ).then(
482
  fn=process_message,
483
+ inputs=[user_input, messages_state, players_state, board_state, dropdown, guessed_words_state, chat_history_state, is_human_playing_state, turn_state, graph_instance], # ADD graph_instance
484
  outputs=[message_feed, guessed_words_state, messages_state, board_state, chat_history_state, winners_state]
485
  ).then(
486
  fn=lambda: "",
support/game_settings.py CHANGED
@@ -482,7 +482,7 @@ TEAM_MODEL_PRESETS = {
482
  "players": ["claude-3-5-haiku-20241022", "claude-3-haiku-20240307"]
483
  },
484
  "opensource": {
485
- "boss": "deepseek-ai/DeepSeek-V3.1",
486
  "captain": "deepseek-ai/DeepSeek-R1", # "Qwen/Qwen3-235B-A22B-Instruct-2507",
487
  "players": ["openai/gpt-oss-120b", "openai/gpt-oss-20b"]
488
  },
 
482
  "players": ["claude-3-5-haiku-20241022", "claude-3-haiku-20240307"]
483
  },
484
  "opensource": {
485
+ "boss": "moonshotai/Kimi-K2-Thinking", # "deepseek-ai/DeepSeek-V3.1",
486
  "captain": "deepseek-ai/DeepSeek-R1", # "Qwen/Qwen3-235B-A22B-Instruct-2507",
487
  "players": ["openai/gpt-oss-120b", "openai/gpt-oss-20b"]
488
  },
support/load_models.py CHANGED
@@ -86,7 +86,8 @@ def create_model(model_name: str, api_keys: dict):
86
  streaming=True,
87
  temperature=0,
88
  top_p=0,
89
- huggingfacehub_api_token=api_keys['HUGGINGFACEHUB_API_TOKEN']
 
90
  )
91
 
92
  return ChatHuggingFace(llm=llm, verbose=True)
 
86
  streaming=True,
87
  temperature=0,
88
  top_p=0,
89
+ huggingfacehub_api_token=api_keys['HUGGINGFACEHUB_API_TOKEN'],
90
+ max_new_tokens=1600
91
  )
92
 
93
  return ChatHuggingFace(llm=llm, verbose=True)