Skip to content

Commit 64be97b

Browse files
Refactor runner
1 parent 76385e0 commit 64be97b

38 files changed

+768
-308
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1-
GO_TAGS ?= netgo
21
build:
32
CGO_ENABLED=0 go build -o bin/gptscript -tags "${GO_TAGS}" -ldflags "-s -w" .
3+
4+
test:
5+
go test -v ./...
6+
7+
ci: build
8+
./bin/gptscript ./scripts/ci.gpt

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ arg: file: The filename to read
5757
5858
#!/bin/bash
5959
60-
cat ${ARG_FILE} </dev/null
60+
cat ${FILE} </dev/null
6161
```
6262
#### From `./tables.gpt`
6363
```
@@ -69,13 +69,13 @@ Arg: cmd: The sqlite command or sql statement to run.
6969
7070
#!/bin/bash
7171
72-
sqlite3 ${ARG_DATABASEFILE} -cmd "${ARG_CMD}" </dev/null
72+
sqlite3 ${DATABASEFILE} -cmd "${CMD}" </dev/null
7373
```
7474

7575
## Additional Observations
7676
- The fields and code block are separated by a new line.
7777
- The arguments are indicated as `arg: argument_name: argument_description`.
78-
- The executable code is introduced with a `#!/bin/bash` shebang line and is expected to replace the argument placeholders (`${ARG_NAME}`) with actual values during execution.
78+
- The executable code is introduced with a `#!/bin/bash` shebang line and is expected to replace the argument placeholders (`${NAME}`) with actual values during execution.
7979

8080
Please note that this description of the syntax is based on the provided examples and may not cover variations which are not included in those files. Additional GPT files may include diverse structures and should be reviewed to check for consistency with this syntax.
8181

examples/describe.gpt

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ arg: list: A comma separated list of numbers to sort
99

1010
#!/bin/bash
1111

12-
for i in $(echo "${ARG_LIST}" | sed 's/[[,\]]/ /g'); do
12+
for i in $(echo "${LIST}" | sed 's/[[,\]]/ /g'); do
1313
echo $i
1414
done | sort -n
1515

@@ -28,7 +28,7 @@ arg: file: The filename to count the lines of
2828

2929
#!/bin/bash
3030

31-
wc -l "${ARG_FILE}"
31+
wc -l "${FILE}"
3232

3333
---
3434
name: summarize
@@ -46,4 +46,4 @@ arg: file: The filename to count the lines of
4646

4747
#!/bin/bash
4848

49-
cat "${ARG_FILE}" </dev/null
49+
cat "${FILE}" </dev/null

examples/echo.gpt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# You can run this script with "gptscript echo.gpt --input 'Hello, World!'"
2+
echo "${input}"

examples/fib.gpt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
tools: myfunction
2+
What's the myfunction of 3
3+
4+
---
5+
name: myfunction
6+
description: A function taking an integer as argument and returns an integer
7+
args: number: An integer
8+
tools: myfunction
9+
10+
Do the following steps in strict sequence:
11+
Step 1. If ${number} is 0, skip the remaining steps and return 1
12+
Step 2. Calculate ${number} minus 1
13+
Step 3. Calculate myfunction of the result of Step 2
14+
Step 4. Multiply result of Step 3 with ${number}
15+
Step 5. Return the result of Step 4

examples/input.gpt

-1
This file was deleted.

examples/summarize-syntax.gpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ arg: file: The filename to read
1717

1818
#!/bin/bash
1919

20-
cat ${ARG_FILE} </dev/null
20+
cat ${FILE} </dev/null

examples/tables.gpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Arg: cmd: The sqlite command or sql statement to run.
1212

1313
#!/bin/bash
1414

15-
sqlite3 ${ARG_DATABASEFILE} -cmd "${ARG_CMD}" </dev/null
15+
sqlite3 ${DATABASEFILE} -cmd "${CMD}" </dev/null

go.mod

+16-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ go 1.21.5
44

55
require (
66
github.com/acorn-io/baaah v0.0.0-20240119160309-2a58ee757bbd
7-
github.com/acorn-io/cmd v0.0.0-20240101193821-66a32bc6b939
7+
github.com/acorn-io/cmd v0.0.0-20240203032901-e9e631185ddb
88
github.com/adrg/xdg v0.4.0
9+
github.com/hexops/autogold/v2 v2.1.0
910
github.com/pterm/pterm v0.12.76
1011
github.com/sashabaranov/go-openai v1.18.3
12+
github.com/sirupsen/logrus v1.9.3
1113
github.com/spf13/cobra v1.8.0
12-
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
14+
github.com/stretchr/testify v1.8.4
1315
golang.org/x/sync v0.5.0
1416
golang.org/x/term v0.16.0
1517
)
@@ -20,29 +22,39 @@ require (
2022
atomicgo.dev/schedule v0.1.0 // indirect
2123
github.com/bombsimon/logrusr/v4 v4.0.0 // indirect
2224
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
25+
github.com/davecgh/go-spew v1.1.1 // indirect
26+
github.com/fatih/color v1.15.0 // indirect
2327
github.com/fsnotify/fsnotify v1.7.0 // indirect
2428
github.com/go-logr/logr v1.4.1 // indirect
29+
github.com/google/go-cmp v0.6.0 // indirect
2530
github.com/google/go-containerregistry v0.16.1 // indirect
2631
github.com/gookit/color v1.5.4 // indirect
32+
github.com/hexops/gotextdiff v1.0.3 // indirect
33+
github.com/hexops/valast v1.4.3 // indirect
2734
github.com/inconshreveable/mousetrap v1.1.0 // indirect
28-
github.com/kr/text v0.2.0 // indirect
2935
github.com/lithammer/fuzzysearch v1.1.8 // indirect
36+
github.com/mattn/go-colorable v0.1.13 // indirect
37+
github.com/mattn/go-isatty v0.0.17 // indirect
3038
github.com/mattn/go-runewidth v0.0.15 // indirect
39+
github.com/nightlyone/lockfile v1.0.0 // indirect
40+
github.com/pmezard/go-difflib v1.0.0 // indirect
3141
github.com/rivo/uniseg v0.4.4 // indirect
3242
github.com/rogpeppe/go-internal v1.11.0 // indirect
3343
github.com/samber/lo v1.38.1 // indirect
3444
github.com/samber/slog-logrus v1.0.0 // indirect
3545
github.com/sergi/go-diff v1.3.1 // indirect
36-
github.com/sirupsen/logrus v1.9.3 // indirect
3746
github.com/spf13/pflag v1.0.5 // indirect
3847
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
48+
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc // indirect
3949
golang.org/x/mod v0.14.0 // indirect
4050
golang.org/x/sys v0.16.0 // indirect
4151
golang.org/x/text v0.14.0 // indirect
4252
golang.org/x/tools v0.16.0 // indirect
4353
gopkg.in/yaml.v2 v2.4.0 // indirect
54+
gopkg.in/yaml.v3 v3.0.1 // indirect
4455
k8s.io/apimachinery v0.29.0 // indirect
4556
k8s.io/klog/v2 v2.110.1 // indirect
57+
mvdan.cc/gofumpt v0.4.0 // indirect
4658
sigs.k8s.io/controller-runtime v0.16.3 // indirect
4759
sigs.k8s.io/controller-tools v0.12.0 // indirect
4860
)

0 commit comments

Comments
 (0)