Features
AI Code Modification
Transform your code with AI using the code method
The primary feature of the Local SDK is the ability to modify code using AI. This is done through the code()
method.
The code()
Method
Parameters
-
prompt (
str
)- Natural language instruction for the AI
- Be specific about what changes you want to make
-
editable_files (
List[str]
)- Paths to files the AI may modify
- Can be relative (to working_dir) or absolute paths
-
readonly_files (
List[str]
, optional)- Paths to files the AI may read but not change
- Useful for providing context to the AI
Return Value
The code()
method returns a dictionary containing:
-
success (
bool
)- Whether meaningful changes were made
True
if changes were applied,False
otherwise
-
diff (
str
)- Git diff if use_git=True, otherwise a description of changes
-
result (
object
)- The raw result object from the underlying coder
-
cost (
Dict[str, float]
)- Contains cost information including:
message_cost
: cost of this specific operationsession_cost
: cumulative cost of the sessiontokens
: token usage information
- Contains cost information including:
-
marked_up_cost (
Dict[str, float]
)- Cost with a 20% markup
-
credits_remaining (
float
)- Your remaining cloudcode credits (if authenticated)
Quick Start Example
Run the real Quick Start script included in the examples:
This script will:
- Create
src/calculator.py
- Add
multiply
anddivide
functions with zero-division handling - Print the diff and updated file content
Multi-File Example
Run the multi-file example script:
This script demonstrates:
- Creating and reading files
- Searching within files
- Improving the calculator with AI
Advanced Usage
With Git Integration
With Architect Mode
Best Practices
Writing Effective Prompts
- Be specific about what you want to change
- Mention any libraries, frameworks, or patterns to use
- Specify error handling and edge cases
- Reference existing patterns in the codebase
Managing File Context
- Group related files in the editable_files list
- Use readonly_files to provide context without allowing changes
- Limit the number of files for better results
- Consider the dependencies between files
Error Handling
Always check the success status and handle appropriately: