clementpep commited on
Commit
1fd3b32
·
1 Parent(s): d0bb718

fix: POST request validation 400 error + improve logs

Browse files
backend/game_engine.py CHANGED
@@ -288,6 +288,9 @@ class GameEngine:
288
  if not player:
289
  return False, "Joueur introuvable"
290
 
 
 
 
291
  current_room = game.rooms[player.current_room_index]
292
  if current_room != room:
293
  return False, f"Tu dois être dans {room} pour faire cette suggestion ! Tu es actuellement dans {current_room}."
 
288
  if not player:
289
  return False, "Joueur introuvable"
290
 
291
+ if not player.has_rolled:
292
+ return False, "Tu dois d'abord lancer les dés avant de faire une suggestion !"
293
+
294
  current_room = game.rooms[player.current_room_index]
295
  if current_room != room:
296
  return False, f"Tu dois être dans {room} pour faire cette suggestion ! Tu es actuellement dans {current_room}."
backend/main.py CHANGED
@@ -133,14 +133,16 @@ async def start_game(game_id: str):
133
  if game and game.use_ai and not game.scenario:
134
  try:
135
  from backend.ai_service import ai_service
 
136
  game.scenario = await ai_service.generate_scenario(
137
  game.rooms,
138
  [c.name for c in game.characters],
139
  game.narrative_tone
140
  )
 
141
  game_manager.save_games()
142
  except Exception as e:
143
- print(f"AI scenario generation failed: {e}")
144
 
145
  return {
146
  "status": "started",
@@ -308,6 +310,7 @@ async def make_suggestion(game_id: str, req: SuggestionRequest):
308
  try:
309
  from backend.ai_service import ai_service
310
  import asyncio
 
311
  ai_comment = await ai_service.generate_suggestion_comment(
312
  player_name,
313
  req.suspect,
@@ -316,8 +319,9 @@ async def make_suggestion(game_id: str, req: SuggestionRequest):
316
  can_disprove,
317
  game.narrative_tone
318
  )
 
319
  except Exception as e:
320
- print(f"AI comment generation failed: {e}")
321
 
322
  result = {
323
  "suggestion": f"{req.suspect} + {req.weapon} + {req.room}",
@@ -376,6 +380,7 @@ async def make_accusation(game_id: str, req: AccusationRequest):
376
  if game.use_ai:
377
  try:
378
  from backend.ai_service import ai_service
 
379
  ai_comment = await ai_service.generate_accusation_comment(
380
  player_name,
381
  req.suspect,
@@ -384,8 +389,9 @@ async def make_accusation(game_id: str, req: AccusationRequest):
384
  is_correct,
385
  game.narrative_tone
386
  )
 
387
  except Exception as e:
388
- print(f"AI comment generation failed: {e}")
389
 
390
  # Record turn with AI comment
391
  GameEngine.add_turn_record(
 
133
  if game and game.use_ai and not game.scenario:
134
  try:
135
  from backend.ai_service import ai_service
136
+ print(f"[AI] Generating scenario...")
137
  game.scenario = await ai_service.generate_scenario(
138
  game.rooms,
139
  [c.name for c in game.characters],
140
  game.narrative_tone
141
  )
142
+ print(f"[AI] Generated scenario: {game.scenario[:100]}...")
143
  game_manager.save_games()
144
  except Exception as e:
145
+ print(f"[AI] AI scenario generation failed: {e}")
146
 
147
  return {
148
  "status": "started",
 
310
  try:
311
  from backend.ai_service import ai_service
312
  import asyncio
313
+ print(f"[AI] Generating suggestion comment for {player_name}...")
314
  ai_comment = await ai_service.generate_suggestion_comment(
315
  player_name,
316
  req.suspect,
 
319
  can_disprove,
320
  game.narrative_tone
321
  )
322
+ print(f"[AI] Generated comment: {ai_comment}")
323
  except Exception as e:
324
+ print(f"[AI] AI comment generation failed: {e}")
325
 
326
  result = {
327
  "suggestion": f"{req.suspect} + {req.weapon} + {req.room}",
 
380
  if game.use_ai:
381
  try:
382
  from backend.ai_service import ai_service
383
+ print(f"[AI] Generating accusation comment for {player_name}...")
384
  ai_comment = await ai_service.generate_accusation_comment(
385
  player_name,
386
  req.suspect,
 
389
  is_correct,
390
  game.narrative_tone
391
  )
392
+ print(f"[AI] Generated comment: {ai_comment}")
393
  except Exception as e:
394
+ print(f"[AI] AI comment generation failed: {e}")
395
 
396
  # Record turn with AI comment
397
  GameEngine.add_turn_record(
frontend/src/components/AINavigator.jsx CHANGED
@@ -7,8 +7,13 @@ function AINavigator({ recentActions, gameStatus }) {
7
  useEffect(() => {
8
  // Extract AI comments from recent actions
9
  if (recentActions) {
 
10
  const aiComments = recentActions
11
- .filter(action => action.ai_comment)
 
 
 
 
12
  .map(action => ({
13
  id: `${action.player}-${action.action}-${Date.now()}`,
14
  text: action.ai_comment,
@@ -16,6 +21,7 @@ function AINavigator({ recentActions, gameStatus }) {
16
  action: action.action
17
  }))
18
 
 
19
  setComments(aiComments)
20
  }
21
  }, [recentActions])
 
7
  useEffect(() => {
8
  // Extract AI comments from recent actions
9
  if (recentActions) {
10
+ console.log('[AINavigator] Recent actions:', recentActions)
11
  const aiComments = recentActions
12
+ .filter(action => {
13
+ const hasComment = !!action.ai_comment
14
+ console.log(`[AINavigator] Action ${action.action} by ${action.player}: has_comment=${hasComment}, comment="${action.ai_comment}"`)
15
+ return hasComment
16
+ })
17
  .map(action => ({
18
  id: `${action.player}-${action.action}-${Date.now()}`,
19
  text: action.ai_comment,
 
21
  action: action.action
22
  }))
23
 
24
+ console.log('[AINavigator] AI comments found:', aiComments.length)
25
  setComments(aiComments)
26
  }
27
  }, [recentActions])