Skip to content

Commit 498091c

Browse files
committed
Update to use new pyinstaller release approach; add GH release action
1 parent 3db1e97 commit 498091c

File tree

14 files changed

+142
-378
lines changed

14 files changed

+142
-378
lines changed

.gitattributes

Lines changed: 0 additions & 10 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Build and Release
2+
on:
3+
push:
4+
tags:
5+
- 'v*.*.*'
6+
7+
jobs:
8+
build:
9+
strategy:
10+
matrix:
11+
os: [windows-latest, ubuntu-latest, macos-latest]
12+
artifact_name: [windows, linux, macos]
13+
runs-on: ${{ matrix.os }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.x'
20+
- name: Install dependencies
21+
run: pip install -r requirements.txt
22+
- name: Build binary
23+
run: pyinstaller --onefile gpt_cmd.py
24+
- name: Upload artifact
25+
uses: actions/upload-artifact@v4
26+
with:
27+
name: ${{ matrix.artifact_name }}
28+
path: dist/gpt_cmd
29+
30+
release:
31+
runs-on: ubuntu-latest
32+
needs: build
33+
steps:
34+
- uses: actions/checkout@v4
35+
- name: Download artifacts
36+
uses: actions/download-artifact@v4
37+
- name: Rename artifacts
38+
run: |
39+
for os in windows linux macos; do
40+
echo "Moving ${os}/dist/gpt_cmd to gpt_cmd-${os}"
41+
mv "${os}/dist/gpt_cmd" "gpt_cmd-${os}"
42+
rm -rf "${os}/"
43+
done
44+
- name: Create release
45+
uses: ncipollo/release-action@v1.14.0
46+
with:
47+
artifacts: gpt_cmd-linux,gpt_cmd-macos,gpt_cmd-windows
48+
tag: ${{ github.ref }}
49+
name: ${{ github.ref }}

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
22
**/__pycache__/
3-
vendor/
3+
build/
4+
dist/
5+
env/

CONTRIBUTING.md

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
First, install the dependencies (**note**: make sure you're using python 3 and pip 3):
66

77
```sh
8-
# install pipenv
9-
brew install pipenv
8+
# create virtual env
9+
python -m venv env
1010

11-
# install both runtime and dev dependencies
12-
pipenv install --dev
11+
# activate env
12+
source env/bin/activate
1313

14-
# activate the virtual env
15-
pipenv shell
14+
# install deps
15+
pip install -r requirements.txt
1616
```
1717

1818
Now you can run the tool via:
@@ -23,10 +23,6 @@ python -m gpt_cmd [...]
2323

2424
## Cutting a release
2525

26-
Currently this just updates the `vendor` tarball (only needed if deps were added/upgraded):
26+
Pushing a version tag (e.g. `v.1.0.0`) will trigger the [release.yml](.github/workflows/release.yml) GitHub action, which will build binaries for supported OSes and publish a release with them.
2727

28-
```sh
29-
./release.sh
30-
```
31-
32-
This script requires all the tools mentioned in the [Running locally](#running-locally) section.
28+
The binaries are generated using [pyinstaller](https://pyinstaller.org/en/stable/).

Pipfile

Lines changed: 0 additions & 13 deletions
This file was deleted.

Pipfile.lock

Lines changed: 0 additions & 281 deletions
This file was deleted.

bin/gpt_cmd

Lines changed: 0 additions & 31 deletions
This file was deleted.

gpt_cmd.py

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,20 @@
55
import sys
66
from openai import OpenAI
77

8+
SYSTEM_PROMPT = '''
9+
Your job is to run commands necessary for achieving a task from a terminal.
10+
11+
You'll be provided with an end goal, and you'll send replies in JSON format containing an array of commands to run in the terminal. Each time you send command(s) to run, you'll then be provided with the resulting stdout and stderr (you're being accessed via the OpenAI API, so when possible, include arguments in your commands to reduce noise in stdout and stderr to limit API usage).
12+
13+
To convey context, you can use a JSON object with `context` (string) and `commands` (array).
14+
15+
When you believe that the end goal is accomplished or unrecoverably failed, send a JSON object containing `status` ("success" or "failed") and `context` (noting things like commands that can be used to use any tools you installed, or why it failed if it did).
16+
17+
IMPORTANT NOTE: each command you provide is being executed in a subshell via a python script, which means things like `cd` won't persist across commands, so you'll need to account for that.
18+
19+
IMPORTANT NOTE: in your response to the first user prompt, generate a short (5 words max) dash-separated file name to describe their prompt. Provide this in a `convo-file-name` property in your JSON object.
20+
'''
21+
822
def ensure_dir(directory):
923
if not os.path.exists(directory):
1024
os.makedirs(directory, exist_ok=True)
@@ -27,13 +41,8 @@ def write_file(file_path, content):
2741
),
2842
}
2943

30-
# trust path provided by entrypoint bash script over `__file__`,
31-
# which can be a relative path in some cases
32-
PROJECT_ROOT_DIR = os.path.normpath(
33-
os.environ.get('GPT_CMD_PROJECT_ROOT', os.path.dirname(__file__))
34-
)
35-
CONVOS_DIR = os.path.join(PROJECT_ROOT_DIR, '.convos')
36-
SYSTEM_PROMPT = read_file(os.path.join(PROJECT_ROOT_DIR, 'system-prompt.txt'))
44+
PROJECT_FILES_DIR = os.path.join(os.path.expanduser('~'), '.gpt_cmd')
45+
CONVOS_DIR = os.path.join(PROJECT_FILES_DIR, '.convos')
3746
OPENAI_CLIENT = None
3847

3948
class ansi:
@@ -145,7 +154,7 @@ def save_convo():
145154
print(response['context'])
146155

147156
save_convo()
148-
exit(0 if was_success else 1)
157+
sys.exit(0 if was_success else 1)
149158

150159
if isinstance(response.get('context'), str):
151160
print(f"{ansi.blue('Context:')} {response['context']}")
@@ -162,7 +171,7 @@ def save_convo():
162171
clear_prev_line()
163172
else:
164173
save_convo()
165-
exit(1)
174+
sys.exit(1)
166175
stdout, exit_code = exec_cmd(cmd)
167176

168177
cmd_ansi_color = ansi.green if exit_code == 0 else ansi.red
@@ -177,22 +186,22 @@ def save_convo():
177186
else:
178187
print(ansi.red('ERROR: No further commands provided, and no success/failure signal was provided'))
179188
save_convo()
180-
exit(1)
189+
sys.exit(1)
181190

182191
if __name__ == "__main__":
183192
helptext = 'Usage:\ngpt_cmd <goal>\ngpt_cmd --get-convos-dir'
184193

185194
if len(sys.argv) != 2:
186195
print(helptext)
187-
sys.exit(1)
196+
sys.sys.exit(1)
188197

189198
if sys.argv[1] == '--help':
190199
print(helptext)
191-
exit(0)
200+
sys.exit(0)
192201

193202
if sys.argv[1] == '--get-convos-dir':
194203
print(CONVOS_DIR)
195-
exit(0)
204+
sys.exit(0)
196205

197206
goal = sys.argv[1]
198207
main(goal)

gpt_cmd.spec

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- mode: python ; coding: utf-8 -*-
2+
3+
4+
a = Analysis(
5+
['gpt_cmd.py'],
6+
pathex=[],
7+
binaries=[],
8+
datas=[],
9+
hiddenimports=[],
10+
hookspath=[],
11+
hooksconfig={},
12+
runtime_hooks=[],
13+
excludes=[],
14+
noarchive=False,
15+
optimize=0,
16+
)
17+
pyz = PYZ(a.pure)
18+
19+
exe = EXE(
20+
pyz,
21+
a.scripts,
22+
a.binaries,
23+
a.datas,
24+
[],
25+
name='gpt_cmd',
26+
debug=False,
27+
bootloader_ignore_signals=False,
28+
strip=False,
29+
upx=True,
30+
upx_exclude=[],
31+
runtime_tmpdir=None,
32+
console=True,
33+
disable_windowed_traceback=False,
34+
argv_emulation=False,
35+
target_arch=None,
36+
codesign_identity=None,
37+
entitlements_file=None,
38+
)

install.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -e
44

5+
# FIXME: update to use new binary approach
6+
57
ansi_blue='\033[94m'
68
ansi_green='\033[92m'
79
ansi_red='\033[91m'

release.sh

Lines changed: 0 additions & 6 deletions
This file was deleted.

requirements.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
altgraph==0.17.4
2+
annotated-types==0.7.0
3+
anyio==4.4.0
4+
certifi==2024.2.2
5+
distro==1.9.0
6+
h11==0.14.0
7+
httpcore==1.0.5
8+
httpx==0.27.0
9+
idna==3.7
10+
macholib==1.16.3
11+
openai==1.30.4
12+
packaging==24.0
13+
pydantic==2.7.2
14+
pydantic_core==2.18.3
15+
pyinstaller==6.7.0
16+
pyinstaller-hooks-contrib==2024.6
17+
setuptools==70.0.0
18+
sniffio==1.3.1
19+
tqdm==4.66.4
20+
typing_extensions==4.12.0

system-prompt.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

vendor.tar.gz

-4.54 MB
Binary file not shown.

0 commit comments

Comments
 (0)