Skip to content

Commit 9cd7460

Browse files
authored
Improve LLM prompts (#50)
1 parent a00573d commit 9cd7460

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

lemonade_arcade/llm_service.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import re
3+
import tempfile
34
from dataclasses import dataclass
45
from typing import AsyncGenerator, Optional, Union
56

@@ -147,7 +148,7 @@ async def generate_game_code_with_llm(
147148
7. Make sure the game window closes properly when the user clicks the X button
148149
8. Use reasonable colors and make the game visually appealing with pygame primitives
149150
150-
Generate ONLY the Python code in a single code block. Do not include any explanations outside the code block."""
151+
Generate ONLY the Python code wrapped in a markdown code block using triple backticks (```python). Do not include any explanations outside the code block."""
151152

152153
user_prompt = f"Create a game: {content}"
153154
messages = [
@@ -191,7 +192,7 @@ async def generate_game_code_with_llm(
191192
2. Incorporate the fix into a code snippet in the style of a before/after git diff.
192193
a. Show the fix and a couple surrounding lines of code.
193194
b. ONLY 5-10 lines of code.
194-
3. Complete CORRECTED code in a python code block.
195+
3. Complete CORRECTED code wrapped in a markdown code block using triple backticks (```python).
195196
196197
IMPORTANT:
197198
- The final code you output must have the fix applied.
@@ -227,7 +228,9 @@ async def generate_game_code_with_llm(
227228
6. Make sure the game window closes properly when the user clicks the X button
228229
7. Use reasonable colors and make the game visually appealing with pygame primitives
229230
230-
Generate ONLY the complete modified Python code in a single code block. Do not include any explanations outside the code block."""
231+
Output format:
232+
First, a one-sentence explanation of the modification in the context of the game, starting with a phrase like "I will modify the game to...".
233+
Then, generate ONLY the complete modified Python code wrapped in a markdown code block using triple backticks (```python)."""
231234

232235
user_prompt = f"""Here is the existing game code:
233236
@@ -287,6 +290,23 @@ async def generate_game_code_with_llm(
287290
full_response += content_chunk
288291
yield content_chunk
289292

293+
# Save the complete LLM response to a temporary file for debugging
294+
try:
295+
with tempfile.NamedTemporaryFile(
296+
mode="w",
297+
suffix=f"_llm_response_{mode}.txt",
298+
delete=False,
299+
encoding="utf-8",
300+
) as temp_file:
301+
temp_file.write(full_response)
302+
temp_file_path = temp_file.name
303+
logger.info(
304+
f"DEBUG: Complete LLM response for {mode} mode saved to: {temp_file_path}"
305+
)
306+
logger.debug(f"Full response length: {len(full_response)} characters")
307+
except Exception as e:
308+
logger.error(f"Failed to save LLM response to temp file: {e}")
309+
290310
extracted_code = _extract_python_code(full_response)
291311
if extracted_code:
292312
logger.debug(f"Successfully extracted code for {mode} mode")

0 commit comments

Comments
 (0)