Skip to content

Commit

Permalink
Update to use new pyinstaller release approach; add GH release action
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdothtml committed May 30, 2024
1 parent 3db1e97 commit 498091c
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 378 deletions.
10 changes: 0 additions & 10 deletions .gitattributes

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build and Release
on:
push:
tags:
- 'v*.*.*'

jobs:
build:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
artifact_name: [windows, linux, macos]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build binary
run: pyinstaller --onefile gpt_cmd.py
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: dist/gpt_cmd

release:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Download artifacts
uses: actions/download-artifact@v4
- name: Rename artifacts
run: |
for os in windows linux macos; do
echo "Moving ${os}/dist/gpt_cmd to gpt_cmd-${os}"
mv "${os}/dist/gpt_cmd" "gpt_cmd-${os}"
rm -rf "${os}/"
done
- name: Create release
uses: ncipollo/release-action@v1.14.0
with:
artifacts: gpt_cmd-linux,gpt_cmd-macos,gpt_cmd-windows
tag: ${{ github.ref }}
name: ${{ github.ref }}
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.DS_Store
**/__pycache__/
vendor/
build/
dist/
env/
20 changes: 8 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
First, install the dependencies (**note**: make sure you're using python 3 and pip 3):

```sh
# install pipenv
brew install pipenv
# create virtual env
python -m venv env

# install both runtime and dev dependencies
pipenv install --dev
# activate env
source env/bin/activate

# activate the virtual env
pipenv shell
# install deps
pip install -r requirements.txt
```

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

## Cutting a release

Currently this just updates the `vendor` tarball (only needed if deps were added/upgraded):
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.

```sh
./release.sh
```

This script requires all the tools mentioned in the [Running locally](#running-locally) section.
The binaries are generated using [pyinstaller](https://pyinstaller.org/en/stable/).
13 changes: 0 additions & 13 deletions Pipfile

This file was deleted.

281 changes: 0 additions & 281 deletions Pipfile.lock

This file was deleted.

31 changes: 0 additions & 31 deletions bin/gpt_cmd

This file was deleted.

35 changes: 22 additions & 13 deletions gpt_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
import sys
from openai import OpenAI

SYSTEM_PROMPT = '''
Your job is to run commands necessary for achieving a task from a terminal.
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).
To convey context, you can use a JSON object with `context` (string) and `commands` (array).
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).
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.
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.
'''

def ensure_dir(directory):
if not os.path.exists(directory):
os.makedirs(directory, exist_ok=True)
Expand All @@ -27,13 +41,8 @@ def write_file(file_path, content):
),
}

# trust path provided by entrypoint bash script over `__file__`,
# which can be a relative path in some cases
PROJECT_ROOT_DIR = os.path.normpath(
os.environ.get('GPT_CMD_PROJECT_ROOT', os.path.dirname(__file__))
)
CONVOS_DIR = os.path.join(PROJECT_ROOT_DIR, '.convos')
SYSTEM_PROMPT = read_file(os.path.join(PROJECT_ROOT_DIR, 'system-prompt.txt'))
PROJECT_FILES_DIR = os.path.join(os.path.expanduser('~'), '.gpt_cmd')
CONVOS_DIR = os.path.join(PROJECT_FILES_DIR, '.convos')
OPENAI_CLIENT = None

class ansi:
Expand Down Expand Up @@ -145,7 +154,7 @@ def save_convo():
print(response['context'])

save_convo()
exit(0 if was_success else 1)
sys.exit(0 if was_success else 1)

if isinstance(response.get('context'), str):
print(f"{ansi.blue('Context:')} {response['context']}")
Expand All @@ -162,7 +171,7 @@ def save_convo():
clear_prev_line()
else:
save_convo()
exit(1)
sys.exit(1)
stdout, exit_code = exec_cmd(cmd)

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

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

if len(sys.argv) != 2:
print(helptext)
sys.exit(1)
sys.sys.exit(1)

if sys.argv[1] == '--help':
print(helptext)
exit(0)
sys.exit(0)

if sys.argv[1] == '--get-convos-dir':
print(CONVOS_DIR)
exit(0)
sys.exit(0)

goal = sys.argv[1]
main(goal)
38 changes: 38 additions & 0 deletions gpt_cmd.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- mode: python ; coding: utf-8 -*-


a = Analysis(
['gpt_cmd.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)

exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='gpt_cmd',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
2 changes: 2 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -e

# FIXME: update to use new binary approach

ansi_blue='\033[94m'
ansi_green='\033[92m'
ansi_red='\033[91m'
Expand Down
6 changes: 0 additions & 6 deletions release.sh

This file was deleted.

20 changes: 20 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
altgraph==0.17.4
annotated-types==0.7.0
anyio==4.4.0
certifi==2024.2.2
distro==1.9.0
h11==0.14.0
httpcore==1.0.5
httpx==0.27.0
idna==3.7
macholib==1.16.3
openai==1.30.4
packaging==24.0
pydantic==2.7.2
pydantic_core==2.18.3
pyinstaller==6.7.0
pyinstaller-hooks-contrib==2024.6
setuptools==70.0.0
sniffio==1.3.1
tqdm==4.66.4
typing_extensions==4.12.0
11 changes: 0 additions & 11 deletions system-prompt.txt

This file was deleted.

Binary file removed vendor.tar.gz
Binary file not shown.

0 comments on commit 498091c

Please sign in to comment.