Use underscores instead of dashes for AI-generated filenames (#40)

Updated the artifact filename generator to use snake_case (underscores)
instead of kebab-case (dashes) for better consistency with Python
naming conventions.

Changes:
- Updated AI prompt examples to show underscore format
- Modified filename processing to replace spaces with underscores
- Updated validation regex to accept underscores instead of dashes
- Changed docstring to reflect underscore usage

Examples: hello_world, prime_checker, array_sort (instead of hello-world, etc.)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Russell 2025-11-11 17:55:35 -05:00 committed by GitHub
parent 45f183df37
commit 3f9b1827c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

16
app.py
View file

@ -335,7 +335,7 @@ def get_activities():
def generate_artifact_name():
"""Generate a meaningful filename for an artifact using AI.
Returns a 1-3 word filename with dashes based on what the code does.
Returns a 1-3 word filename with underscores based on what the code does.
Respects ENABLE_CODE_GEN_FILENAMES environment variable (enabled by default).
"""
# Check if feature is enabled (default: true)
@ -359,16 +359,16 @@ def generate_artifact_name():
Rules:
- Output ONLY the filename, nothing else
- Use 1-3 words maximum
- Use lowercase with dashes between words (e.g., "fizzbuzz" or "hello-world" or "prime-checker")
- Use lowercase with underscores between words (e.g., "fizzbuzz" or "hello_world" or "prime_checker")
- NO file extension
- NO explanations or commentary
- Be specific about what the code does
Examples:
- Code that prints "Hello World" "hello-world"
- Code that checks for prime numbers "prime-checker"
- Code that prints "Hello World" "hello_world"
- Code that checks for prime numbers "prime_checker"
- Code that plays FizzBuzz "fizzbuzz"
- Code that sorts an array "array-sort"
- Code that sorts an array "array_sort"
- Code that calculates factorial "factorial"
"""
@ -389,12 +389,12 @@ Examples:
# Clean up the filename (remove quotes, extensions, whitespace)
filename = filename.strip('"\'')
filename = filename.split('.')[0] # Remove any extension
filename = filename.replace(' ', '-')
filename = filename.replace(' ', '_')
filename = filename.lower()
# Validate filename (alphanumeric and dashes only)
# Validate filename (alphanumeric and underscores only)
import re
if not re.match(r'^[a-z0-9-]+$', filename):
if not re.match(r'^[a-z0-9_]+$', filename):
filename = "compiled_binary"
# Ensure it's not too long (max 50 chars)