Skip to content

Commit 6dbdea1

Browse files
committed
init commit
0 parents  commit 6dbdea1

File tree

14 files changed

+883
-0
lines changed

14 files changed

+883
-0
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# ignore these files when generating release tarballs
2+
.editorconfig export-ignore
3+
.gitattributes export-ignore
4+
.gitignore export-ignore
5+
CONTRIBUTING.md export-ignore
6+
install.sh export-ignore
7+
Pipfile export-ignore
8+
Pipfile.lock export-ignore
9+
README.md export-ignore
10+
release.sh export-ignore

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.DS_Store
2+
**/__pycache__/
3+
vendor/

CONTRIBUTING.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Contributing
2+
3+
## Running locally
4+
5+
First, install the dependencies (**note**: make sure you're using python 3 and pip 3):
6+
7+
```sh
8+
# install pipenv
9+
brew install pipenv
10+
11+
# install both runtime and dev dependencies
12+
pipenv install --dev
13+
14+
# activate the virtual env
15+
pipenv shell
16+
```
17+
18+
Now you can run the tool via:
19+
20+
```sh
21+
python -m gpt_cmd [...]
22+
```
23+
24+
## Cutting a release
25+
26+
Currently this just updates the `vendor` tarball (only needed if deps were added/upgraded):
27+
28+
```sh
29+
./release.sh
30+
```
31+
32+
This script requires all the tools mentioned in the [Running locally](#running-locally) section.

Pipfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[[source]]
2+
url = "https://pypi.org/simple"
3+
verify_ssl = true
4+
name = "pypi"
5+
6+
[packages]
7+
openai = "*"
8+
9+
[dev-packages]
10+
black = "*"
11+
12+
[requires]
13+
python_version = "3"

Pipfile.lock

Lines changed: 281 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# gpt-cmd
2+
3+
> Sit back and let ChatGPT figure out what commands need to be run
4+
5+
> [!WARNING]
6+
> It's always risky to execute commands directly from a third party. Use responsibly and at your own risk.
7+
8+
```sh
9+
gpt_cmd "Install python3 and pip3 and symlink them to python and pip"
10+
11+
gpt_cmd "You're running on an alpine linux distro that already has wget and bash installed. Install kafka"
12+
13+
gpt_cmd "Install SQLite and write a script to verify it's working correctly"
14+
```
15+
16+
### Problem
17+
18+
> I'm working on a fresh Docker image, and I can't remember the specific commands needed to install tools. I can ask ChatGPT, but it might give me an answer that doesn't work with the exact environment I'm running in (e.g. differences between linux distros). Why can't ChatGPT just figure all that out for me?
19+
20+
The main problem is that, a lot of the time, to determine what exactly needs to be run (e.g. to install kafka in a Docker image), you need to try running commands to see if they fail, or run commands to probe the system to determine what tools are available.
21+
22+
For example, sometimes `sudo` doesn't exist in Docker, and since it runs as the root user by default, you can just leave it out. ChatGPT has no problem deducing that it can just remove the `sudo` in those cases.
23+
24+
### Solution
25+
26+
Let ChatGPT iteratively run commands for you to achieve your end goal.
27+
28+
The way it works is that you provide some end goal (e.g. 'Install python3 and pip3'), and ChatGPT will respond with a list of commands it wants to run. The tool will execute these commands and respond to ChatGPT with the stdout and exit code of each. Once ChatGPT thinks it's done, it'll respond accordingly and the loop will end.
29+
30+
With this approach, ChatGPT is able to probe your system and try running commands, responding to potential failures as they happen with alternative commands.
31+
32+
## Install
33+
34+
> [!WARNING]
35+
> In light of my other warning above, this install script is pulled directly from my GitHub repo, and is a potential vulnerability if the repo (or GitHub) becomes compromised. Always inspect scripts for shady behavior before running them on your device (even mine: [install.sh](https://raw.githubusercontent.com/chrisdothtml/gpt-cmd/main/install.sh)).
36+
37+
**NOTE**: the install script and tool require: `python` (v3), `bash`, and either `curl` or `wget`
38+
39+
```sh
40+
curl -s https://raw.githubusercontent.com/chrisdothtml/gpt-cmd/main/install.sh | bash
41+
42+
# or if you prefer wget
43+
wget -qO- https://raw.githubusercontent.com/chrisdothtml/gpt-cmd/main/install.sh | bash
44+
```
45+
46+
See [Env var overrides](#env-var-overrides) section for changing the install dir.
47+
48+
The install script will write to your `.profile` file to expose it to your `$PATH`, but if that doesn't work, you'll have to manually add it your path:
49+
50+
```sh
51+
# replace `$HOME` with your custom install dir if you used one
52+
export PATH="$HOME/gpt_cmd/bin:$PATH"
53+
```
54+
55+
## Use
56+
57+
Before running, you need to create an `~/OPENAI_TOKEN` file and put your token in it.
58+
59+
```sh
60+
gpt_cmd <goal>
61+
62+
# see `Env var overrides` section below for full list
63+
GPT_CMD_MODEL="gpt-4-turbo" gpt_cmd <goal>
64+
GPT_CMD_TOKEN_FILE_PATH="/my/token/file" gpt_cmd <goal>
65+
66+
# print path to the dir containing message logs for your previous runs
67+
gpt_cmd --get-convos-dir
68+
```
69+
70+
The `goal` can be literally anything you can achieve via a terminal (which is a lot). Even if it takes dozens of commands to get there, it'll eventually get there (maybe). You can be as descriptive or vague as you want, and list as many different tasks as you want (e.g. 'Install [some tool] and then write a starter script with some examples of how to use it').
71+
72+
## Env var overrides
73+
74+
Enironment vars that you can provide to change the behavior of the tool.
75+
76+
### `GPT_CMD_INSTALL_DIR`
77+
78+
Override the dir the installer puts the tool in.
79+
80+
**Default**: home dir
81+
82+
**Example**:
83+
84+
```sh
85+
curl -s [...] | GPT_CMD_INSTALL_DIR="/my/custom/dir" bash
86+
```
87+
88+
### `GPT_CMD_MODEL`
89+
90+
Override the gpt model used by the tool.
91+
92+
**Default**: `gpt-4o`
93+
94+
### `GPT_CMD_TOKEN_FILE_PATH`
95+
96+
Override the file path the tool gets your OpenAI token from.
97+
98+
**Default**: `~/OPENAI_TOKEN`
99+
100+
### `GPT_CMD_DANGEROUSLY_SKIP_PROMPTS`
101+
102+
By default, the tool will prompt you before running each command, as giving an AI unfettered access to run commands on your system is usually a bad idea. However, if you're on a throwaway machine/container and don't care what happens to it, you can disable the prompts via `GPT_CMD_DANGEROUSLY_SKIP_PROMPTS=true`.
103+
104+
## License
105+
106+
[MIT](license)

bin/gpt_cmd

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
project_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
6+
7+
function quit_python_required() {
8+
echo "ERROR: python 3 is required to run gpt_cmd" >&2
9+
exit 1
10+
}
11+
12+
function get_python_bin() {
13+
if command -v python3 >/dev/null; then
14+
echo "python3"
15+
return 0
16+
elif command -v python >/dev/null; then
17+
major_version="$(python --version | grep -oE '[0-9]+' | head -1)"
18+
if [ "$major_version" -ne 3 ]; then
19+
quit_python_required
20+
fi
21+
22+
echo "python"
23+
return 0
24+
fi
25+
26+
quit_python_required
27+
}
28+
29+
export PYTHONPATH="$project_root/vendor"
30+
export GPT_CMD_PROJECT_ROOT="$project_root"
31+
$(get_python_bin) "$project_root/gpt_cmd.py" "$@"

0 commit comments

Comments
 (0)