Skip to content

Commit 64be97b

Browse files
Refactor runner
1 parent 76385e0 commit 64be97b

38 files changed

+768
-308
lines changed

Makefile

Lines changed: 6 additions & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 15 additions & 0 deletions
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

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/summarize-syntax.gpt

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 16 additions & 4 deletions
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)