Compare commits

..

6 Commits

Author SHA1 Message Date
rob 7e9bd0d533 made an adjustment to the adjust code instructions 2025-12-07 05:34:24 -04:00
rob 35835f8254 fix: Add clearer example showing variable assignment pattern
The AI prompt now explicitly shows:
1. Assign Available Variables to standard Python variables first
2. Then use those variables in the code
3. Multi-line example with file writing pattern

This prevents the AI from trying to use {variable} directly in
expressions without proper assignment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 05:15:12 -04:00
rob d09a0088ef fix: Show available variables in triple-quote format in AI prompt
The AI follows the pattern better when the available variables are
shown in the exact format they should be used:
  """{input}""", """{response}""", etc.

This helps the AI generate code that properly uses triple quotes
for variable substitution.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 04:58:37 -04:00
rob bcda4150a7 docs: Improve AI auto-adjust prompt with variable substitution guidance
Updated the default prompt template to explain how to use variables:
- Variables must be wrapped in curly braces: {variable}
- Use triple quotes since content may contain quotes/newlines
- Added example: my_var = """{response}"""

This helps the AI generate code that works correctly with the
variable substitution system.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 03:57:41 -04:00
rob 0c966a8adb fix: Add variable substitution to code steps
Code steps were executing with literal {variable} placeholders instead
of substituted values. Now substitute_variables() is called on the code
before execution, matching the behavior of prompt steps.

This fixes issues like {outputfile} being treated as a Python set literal
or written as a literal filename.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-07 02:59:35 -04:00
rob 9c6b682c73 fix: Improve AI auto-adjust prompt to prevent function wrapping
The AI was generating function definitions instead of inline code.
Updated the default prompt template to explicitly:
- Request inline executable code, NOT function definitions
- Clarify that variables are already available
- Emphasize no wrapping in functions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 21:39:48 -04:00
2 changed files with 16 additions and 5 deletions

View File

@ -67,12 +67,15 @@ def execute_code_step(step: CodeStep, variables: dict) -> tuple[dict, bool]:
Returns:
Tuple of (output_vars_dict, success)
"""
# Substitute variables in code (like {outputfile} -> actual value)
code = substitute_variables(step.code, variables)
# Create execution environment with variables
local_vars = dict(variables)
try:
# Execute the code
exec(step.code, {"__builtins__": __builtins__}, local_vars)
# Execute the code with substituted variables
exec(code, {"__builtins__": __builtins__}, local_vars)
# Support comma-separated output vars (e.g., "a, b, c")
output_vars = [v.strip() for v in step.output_var.split(',')]

View File

@ -1829,7 +1829,14 @@ class SmartToolsUI:
ai_provider_select_btn = Button3DCompact("", on_press=show_ai_provider_dropdown)
# Default prompt template for AI code generation/adjustment
default_ai_prompt = f"""Modify or generate Python code according to my instruction below.
# Show variables in triple-quote format so the AI follows the pattern
vars_formatted = ', '.join(f'\"\"\"{{{v}}}\"\"\"' for v in vars_available)
default_ai_prompt = f"""Write inline Python code (NOT a function definition) according to my instruction.
The code runs directly with variable substitution. Assign any "Available Variables" used to a new standard variable first, then use that variable in the code. Use triple quotes and curly braces since the substituted content may contain quotes/newlines.
Example:
my_var = \"\"\"{{variable}}\"\"\"
INSTRUCTION: [Describe what you want]
@ -1838,9 +1845,10 @@ CURRENT CODE:
{{code}}
```
AVAILABLE VARIABLES: {', '.join(vars_available)}
AVAILABLE VARIABLES: {vars_formatted}
Return ONLY the Python code, no explanations or markdown fencing."""
IMPORTANT: Return ONLY executable inline code. Do NOT wrap in a function.
No explanations, no markdown fencing, just the code."""
# Multiline editable prompt for AI with DOS-style scrollbar
ai_prompt_edit = TabPassEdit(edit_text=default_ai_prompt, multiline=True)