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
Thecode() method returns a dictionary containing:
-
success (
bool)- Whether meaningful changes were made
Trueif changes were applied,Falseotherwise
-
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:- Create
src/calculator.py - Add
multiplyanddividefunctions with zero-division handling - Print the diff and updated file content
Multi-File Example
Run the multi-file example script:- 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