mirror of
https://github.com/hanzoai/cli.git
synced 2026-10-30 15:00:27 +00:00
3.0 KiB
3.0 KiB
parent, nav_order, description
| parent | nav_order | description |
|---|---|---|
| More info | 400 | You can script dev via the command line or python. |
Scripting dev
You can script dev via the command line or python.
Command line
Dev takes a --message argument, where you can give it a natural language instruction.
It will do that one thing, apply the edits to the files and then exit.
So you could do:
dev --message "make a script that prints hello" hello.js
Or you can write simple shell scripts to apply the same instruction to many files:
for FILE in *.py ; do
dev --message "add descriptive docstrings to all the functions" $FILE
done
Use dev --help to see all the
command line options,
but these are useful for scripting:
--stream, --no-stream
Enable/disable streaming responses (default: True) [env var:
DEV_STREAM]
--message COMMAND, --msg COMMAND, -m COMMAND
Specify a single message to send GPT, process reply then exit
(disables chat mode) [env var: DEV_MESSAGE]
--message-file MESSAGE_FILE, -f MESSAGE_FILE
Specify a file containing the message to send GPT, process reply,
then exit (disables chat mode) [env var: DEV_MESSAGE_FILE]
--yes Always say yes to every confirmation [env var: DEV_YES]
--auto-commits, --no-auto-commits
Enable/disable auto commit of GPT changes (default: True) [env var:
DEV_AUTO_COMMITS]
--dirty-commits, --no-dirty-commits
Enable/disable commits when repo is found dirty (default: True) [env
var: DEV_DIRTY_COMMITS]
--dry-run, --no-dry-run
Perform a dry run without modifying files (default: False) [env var:
DEV_DRY_RUN]
--commit Commit all pending changes with a suitable commit message, then exit
[env var: DEV_COMMIT]
Python
You can also script dev from python:
from dev.coders import Coder
from dev.models import Model
# This is a list of files to add to the chat
fnames = ["greeting.py"]
model = Model("gpt-4-turbo")
# Create a coder object
coder = Coder.create(main_model=model, fnames=fnames)
# This will execute one instruction on those files and then return
coder.run("make a script that prints hello world")
# Send another instruction
coder.run("make it say goodbye")
# You can run in-chat "/" commands too
coder.run("/tokens")
See the Coder.create() and Coder.init() methods for all the supported arguments.
It can also be helpful to set the equivalent of --yes by doing this:
from dev.io import InputOutput
io = InputOutput(yes=True)
# ...
coder = Coder.create(model=model, fnames=fnames, io=io)
{: .note } The python scripting API is not officially supported or documented, and could change in future releases without providing backwards compatibility.