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

fix: AI logs using docker

Browse files
Files changed (4) hide show
  1. .dockerignore +25 -23
  2. .env.example +7 -5
  3. README.md +10 -3
  4. backend/ai_service.py +44 -15
.dockerignore CHANGED
@@ -1,3 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Python
2
  __pycache__
3
  *.pyc
@@ -9,38 +21,28 @@ __pycache__
9
  *.egg-info
10
  dist
11
  build
12
-
13
- # Virtual environments
14
- venv/
15
- env/
16
- ENV/
17
 
18
  # IDE
19
  .vscode
20
  .idea
21
  *.swp
22
  *.swo
 
23
 
24
- # Git
25
- .git
26
- .gitignore
27
- .gitattributes
 
 
 
28
 
29
  # Documentation
 
 
30
  *.md
31
- !README.md
32
-
33
- # Environment files
34
- .env
35
 
36
- # Game data
37
  games.json
38
-
39
- # OS
40
- .DS_Store
41
- Thumbs.db
42
-
43
- # Testing
44
- .pytest_cache
45
- .coverage
46
- htmlcov
 
1
+ # Environment files (security)
2
+ .env
3
+ .env.local
4
+
5
+ # Git
6
+ .git
7
+ .gitignore
8
+
9
+ # Node
10
+ node_modules
11
+ npm-debug.log
12
+
13
  # Python
14
  __pycache__
15
  *.pyc
 
21
  *.egg-info
22
  dist
23
  build
24
+ .venv
25
+ venv
 
 
 
26
 
27
  # IDE
28
  .vscode
29
  .idea
30
  *.swp
31
  *.swo
32
+ *~
33
 
34
+ # OS
35
+ .DS_Store
36
+ Thumbs.db
37
+
38
+ # Test files
39
+ *.test.js
40
+ *.spec.js
41
 
42
  # Documentation
43
+ README.md
44
+ CORRECTIONS_IA.md
45
  *.md
 
 
 
 
46
 
47
+ # Game data (will be created at runtime)
48
  games.json
 
 
 
 
 
 
 
 
 
.env.example CHANGED
@@ -1,7 +1,9 @@
1
- # Application Configuration
 
 
 
 
 
 
2
  APP_NAME=Cluedo Custom
3
  MAX_PLAYERS=8
4
-
5
- # AI Configuration (set to true to enable OpenAI integration)
6
- USE_OPENAI=false
7
- OPENAI_API_KEY=
 
1
+ # Configuration for Cluedo Custom
2
+
3
+ # OpenAI API Configuration (for AI narrator Desland)
4
+ USE_OPENAI=true
5
+ OPENAI_API_KEY=your_openai_api_key_here
6
+
7
+ # Application Settings
8
  APP_NAME=Cluedo Custom
9
  MAX_PLAYERS=8
 
 
 
 
README.md CHANGED
@@ -41,19 +41,26 @@ Application web de Cluedo personnalisable avec narrateur IA sarcastique (Desland
41
  # Build l'image
42
  docker build -t custom-cluedo .
43
 
44
- # Lance l'application
45
  docker run -p 7860:7860 custom-cluedo
46
 
47
- # Avec IA Desland activée
48
  docker run -p 7860:7860 \
49
  -e USE_OPENAI=true \
50
  -e OPENAI_API_KEY=your_key_here \
51
  custom-cluedo
52
 
 
 
 
 
 
53
  # Accéder à l'application
54
- open http://localhost:7860
55
  ```
56
 
 
 
57
  ### Développement Local
58
 
59
  #### Backend
 
41
  # Build l'image
42
  docker build -t custom-cluedo .
43
 
44
+ # Option 1: Lance sans IA (Desland désactivé)
45
  docker run -p 7860:7860 custom-cluedo
46
 
47
+ # Option 2: Avec IA Desland activée (variables d'environnement)
48
  docker run -p 7860:7860 \
49
  -e USE_OPENAI=true \
50
  -e OPENAI_API_KEY=your_key_here \
51
  custom-cluedo
52
 
53
+ # Option 3: Avec IA Desland activée (fichier .env)
54
+ # 1. Créer un fichier .env avec vos variables (voir .env.example)
55
+ # 2. Lancer avec --env-file
56
+ docker run -p 7860:7860 --env-file .env custom-cluedo
57
+
58
  # Accéder à l'application
59
+ # Navigateur: http://localhost:7860
60
  ```
61
 
62
+ **⚠️ IMPORTANT pour l'IA** : Si vous voulez les commentaires sarcastiques de Desland, vous DEVEZ passer les variables d'environnement au conteneur Docker (option 2 ou 3).
63
+
64
  ### Développement Local
65
 
66
  #### Backend
backend/ai_service.py CHANGED
@@ -74,7 +74,12 @@ COMMENCE obligatoirement par Desland se trompant sur son nom, puis introduis le
74
  Generate a sarcastic comment from Desland about a suggestion.
75
  Returns None if AI is disabled or if generation fails.
76
  """
 
 
 
 
77
  if not self.enabled or not self.client:
 
78
  return None
79
 
80
  try:
@@ -93,17 +98,22 @@ IMPORTANT: Desland est SARCASTIQUE et INCISIF. Il se moque des théories absurde
93
  Ton narratif: {narrative_tone}
94
  Sois sarcastique, condescendant et incisif. Moque la logique (ou l'absence de logique) de la suggestion."""
95
 
 
96
  response = await asyncio.wait_for(
97
  asyncio.to_thread(self._generate_text, prompt), timeout=10.0
98
  )
 
99
 
100
  return response
101
 
102
  except asyncio.TimeoutError:
103
- print("AI comment generation timed out")
104
  return None
105
  except Exception as e:
106
- print(f"Error generating comment: {e}")
 
 
 
107
  return None
108
 
109
  async def generate_accusation_comment(
@@ -156,14 +166,17 @@ Rends-le incisif et mémorable."""
156
  Uses higher temperature for creative sarcasm.
157
  """
158
  if not self.client:
 
159
  return ""
160
 
161
- response = self.client.chat.completions.create(
162
- model="gpt-4o-mini",
163
- messages=[
164
- {
165
- "role": "system",
166
- "content": """Tu es Desland, un vieux jardinier suspect, sarcastique et incisif.
 
 
167
 
168
  Traits clés:
169
  - SARCASTIQUE: Tu te moques des théories absurdes et des déductions illogiques avec des remarques cinglantes
@@ -177,14 +190,30 @@ Exemples de ton style:
177
  "Ah oui, excellente déduction Sherlock. Prochaine étape : accuser le chat du voisin."
178
 
179
  Garde tes réponses brèves (1 phrase pour les commentaires, 2-3 pour les scénarios), EN FRANÇAIS, sarcastiques et mémorables.""",
180
- },
181
- {"role": "user", "content": prompt},
182
- ],
183
- temperature=0.9,
184
- max_tokens=150,
185
- )
 
 
 
 
 
 
 
 
 
 
 
186
 
187
- return response.choices[0].message.content.strip()
 
 
 
 
 
188
 
189
 
190
  # Global AI service instance
 
74
  Generate a sarcastic comment from Desland about a suggestion.
75
  Returns None if AI is disabled or if generation fails.
76
  """
77
+ print(
78
+ f"[AI Service] generate_suggestion_comment called: enabled={self.enabled}, client={self.client is not None}"
79
+ )
80
+
81
  if not self.enabled or not self.client:
82
+ print(f"[AI Service] AI disabled or client not initialized")
83
  return None
84
 
85
  try:
 
98
  Ton narratif: {narrative_tone}
99
  Sois sarcastique, condescendant et incisif. Moque la logique (ou l'absence de logique) de la suggestion."""
100
 
101
+ print(f"[AI Service] Calling OpenAI API...")
102
  response = await asyncio.wait_for(
103
  asyncio.to_thread(self._generate_text, prompt), timeout=10.0
104
  )
105
+ print(f"[AI Service] OpenAI response received: {response}")
106
 
107
  return response
108
 
109
  except asyncio.TimeoutError:
110
+ print("[AI Service] AI comment generation timed out")
111
  return None
112
  except Exception as e:
113
+ import traceback
114
+
115
+ print(f"[AI Service] Error generating comment: {e}")
116
+ print(traceback.format_exc())
117
  return None
118
 
119
  async def generate_accusation_comment(
 
166
  Uses higher temperature for creative sarcasm.
167
  """
168
  if not self.client:
169
+ print("[AI Service] _generate_text: No client")
170
  return ""
171
 
172
+ try:
173
+ print("[AI Service] _generate_text: Calling OpenAI API...")
174
+ response = self.client.chat.completions.create(
175
+ model="gpt-5-nano",
176
+ messages=[
177
+ {
178
+ "role": "system",
179
+ "content": """Tu es Desland, un vieux jardinier suspect, sarcastique et incisif.
180
 
181
  Traits clés:
182
  - SARCASTIQUE: Tu te moques des théories absurdes et des déductions illogiques avec des remarques cinglantes
 
190
  "Ah oui, excellente déduction Sherlock. Prochaine étape : accuser le chat du voisin."
191
 
192
  Garde tes réponses brèves (1 phrase pour les commentaires, 2-3 pour les scénarios), EN FRANÇAIS, sarcastiques et mémorables.""",
193
+ },
194
+ {"role": "user", "content": prompt},
195
+ ],
196
+ temperature=0.9,
197
+ max_tokens=150,
198
+ )
199
+
200
+ print(
201
+ f"[AI Service] _generate_text: Response received, choices={len(response.choices)}"
202
+ )
203
+ if response.choices:
204
+ content = response.choices[0].message.content
205
+ print(f"[AI Service] _generate_text: Content={content}")
206
+ return content.strip() if content else ""
207
+ else:
208
+ print("[AI Service] _generate_text: No choices in response")
209
+ return ""
210
 
211
+ except Exception as e:
212
+ import traceback
213
+
214
+ print(f"[AI Service] _generate_text error: {e}")
215
+ print(traceback.format_exc())
216
+ return ""
217
 
218
 
219
  # Global AI service instance