ryomo commited on
Commit
781ecb0
·
1 Parent(s): 353b2d2

feat: enhance game initialization by auto-filling session ID

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -132,8 +132,6 @@ Add the following to your MCP settings configuration:
132
 
133
  init_output = gr.JSON(label="Game Session Info")
134
 
135
- init_btn.click(fn=init_game, inputs=personality_input, outputs=init_output)
136
-
137
  gr.Markdown("### Test: Get Game State")
138
  with gr.Row():
139
  session_id_input = gr.Textbox(
@@ -185,6 +183,18 @@ Add the following to your MCP settings configuration:
185
  outputs=exec_output,
186
  )
187
 
 
 
 
 
 
 
 
 
 
 
 
 
188
 
189
  if __name__ == "__main__":
190
  demo.launch(mcp_server=True)
 
132
 
133
  init_output = gr.JSON(label="Game Session Info")
134
 
 
 
135
  gr.Markdown("### Test: Get Game State")
136
  with gr.Row():
137
  session_id_input = gr.Textbox(
 
183
  outputs=exec_output,
184
  )
185
 
186
+ # Auto-fill session_id when starting a new game
187
+ def init_game_and_extract_session(personality: str):
188
+ result = init_game(personality)
189
+ session_id = result.get("session_id", "")
190
+ return result, session_id, session_id
191
+
192
+ init_btn.click(
193
+ fn=init_game_and_extract_session,
194
+ inputs=personality_input,
195
+ outputs=[init_output, session_id_input, exec_session_id],
196
+ )
197
+
198
 
199
  if __name__ == "__main__":
200
  demo.launch(mcp_server=True)