Skip to content

Commit 0ad8d86

Browse files
Initial commit
0 parents  commit 0ad8d86

28 files changed

+2376
-0
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
GO_TAGS ?= netgo
2+
build:
3+
CGO_ENABLED=0 go build -o bin/gptscript -tags "${GO_TAGS}" -ldflags "-s -w" .

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# README for GPT File Syntax
2+
3+
## Overview
4+
GPT files found in this project use a custom syntax to describe various shell tools and their respective functionalities. Each file contains definitions for tools including their names, descriptions, arguments, and executable code. Below is an explanation of the syntax based on the contents of the GPT files reviewed (`./describe.gpt`, `./summarize-syntax.gpt`, `./tables.gpt`).
5+
6+
## Syntax Description
7+
8+
### General Format
9+
GPT files follow a structured format that includes a preamble (indicating available tools), followed by metadata (descriptions of each tool), and Bash script examples for the tool's operation.
10+
11+
Here's the general layout of a GPT file definition:
12+
```
13+
Tools: <tool_list>
14+
<empty_line>
15+
--- (3 hyphens to separate each tool definition)
16+
name: <tool_name>
17+
description: <description_of_tool>
18+
arg: <argument_description> (Optional and re-occurring)
19+
<empty_line>
20+
<executable_code_block>
21+
```
22+
23+
### Tool Definition Header
24+
A tool definition always starts with three hyphens (`---`). This is a separator used to distinguish between different tool descriptions within the file.
25+
26+
### Name
27+
The `name` field defines the name of the tool. It is used to invoke a specific functionality.
28+
29+
### Description
30+
The `description` field provides a concise explanation of what the tool does.
31+
32+
### Arguments
33+
The `arg` fields describe the arguments that the tool accepts. Each argument is paired with a brief description. Argument definitions are optional and can be repeated if a tool accepts multiple arguments.
34+
35+
### Executable Code Block
36+
Following the metadata, an executable code block is provided. It is written in Bash and contains the script to execute the tool's functionality.
37+
38+
### Examples
39+
Here are examples extracted from the GPT files which follow the syntax described:
40+
41+
#### From `./describe.gpt`
42+
```
43+
---
44+
name: ls
45+
description: Recursively lists all go files
46+
47+
#!/bin/bash
48+
49+
find . -name '*.go'
50+
```
51+
#### From `./summarize-syntax.gpt`
52+
```
53+
---
54+
name: cat
55+
description: Reads the contents of a file
56+
arg: file: The filename to read
57+
58+
#!/bin/bash
59+
60+
cat ${ARG_FILE} </dev/null
61+
```
62+
#### From `./tables.gpt`
63+
```
64+
---
65+
Name: sqlite
66+
Description: The sqlite command line program ... to run sqlite command or SQL statements against a database.
67+
Arg: databaseFile: The filename of the database to open
68+
Arg: cmd: The sqlite command or sql statement to run.
69+
70+
#!/bin/bash
71+
72+
sqlite3 ${ARG_DATABASEFILE} -cmd "${ARG_CMD}" </dev/null
73+
```
74+
75+
## Additional Observations
76+
- The fields and code block are separated by a new line.
77+
- 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.
79+
80+
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.
81+

examples/describe.gpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Tools: ls, count, summarize, compare
2+
3+
Find the top 10 go files that have to most lines of code. Then summarize each one and provide an overview of what this go program does. I don't want a file by file summary, just one overall summary.
4+
5+
---
6+
name: compare
7+
description: Sorts a list of number from smallest to biggest
8+
arg: list: A comma separated list of numbers to sort
9+
10+
#!/bin/bash
11+
12+
for i in $(echo "${ARG_LIST}" | sed 's/[[,\]]/ /g'); do
13+
echo $i
14+
done | sort -n
15+
16+
---
17+
name: ls
18+
description: Recursively lists all go files
19+
20+
#!/bin/bash
21+
22+
find . -name '*.go'
23+
24+
---
25+
name: count
26+
description: Count the lines a file
27+
arg: file: The filename to count the lines of
28+
29+
#!/bin/bash
30+
31+
wc -l "${ARG_FILE}"
32+
33+
---
34+
name: summarize
35+
tools: cat
36+
description: Read a go file
37+
arg: file: The filename to read
38+
39+
First read the passed file and then summarize it's content into no more than 100 words
40+
41+
42+
---
43+
name: cat
44+
description: Read a files content
45+
arg: file: The filename to count the lines of
46+
47+
#!/bin/bash
48+
49+
cat "${ARG_FILE}" </dev/null

examples/summarize-syntax.gpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
tools: ls, cat
2+
3+
Read all gpt files and then write a README that describes the syntax of the gpt files
4+
5+
---
6+
name: ls
7+
description: list all gpt files
8+
9+
#!/bin/bash
10+
11+
find -name '*.gpt'
12+
13+
---
14+
name: cat
15+
description: Reads the contents of a file
16+
arg: file: The filename to read
17+
18+
#!/bin/bash
19+
20+
cat ${ARG_FILE} </dev/null

examples/tables.gpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Tools: sqlite
2+
3+
I have the file sqlite database file /home/darren/src/openai-cookbook/examples/data/Chinook.db.
4+
5+
What is the table with the most amount of rows in it?
6+
7+
---
8+
Name: sqlite
9+
Description: The sqlite command line program. This tool is used to run sqlite command or SQL statements against a database. The result of this tool will be the output of the executed command or statement.
10+
Arg: databaseFile: The filename of the database to open
11+
Arg: cmd: The sqlite command or sql statement to run.
12+
13+
#!/bin/bash
14+
15+
sqlite3 ${ARG_DATABASEFILE} -cmd "${ARG_CMD}" </dev/null

generate.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
//go:generate go run github.com/acorn-io/baaah/cmd/deepcopy ./pkg/engine/ ./pkg/types/
2+
3+
package main

go.mod

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module github.com/acorn-io/gptscript
2+
3+
go 1.21.5
4+
5+
require (
6+
github.com/acorn-io/baaah v0.0.0-20240119160309-2a58ee757bbd
7+
github.com/acorn-io/cmd v0.0.0-20240101193821-66a32bc6b939
8+
github.com/adrg/xdg v0.4.0
9+
github.com/pterm/pterm v0.12.76
10+
github.com/sashabaranov/go-openai v1.18.3
11+
github.com/spf13/cobra v1.8.0
12+
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
13+
golang.org/x/sync v0.5.0
14+
)
15+
16+
require (
17+
atomicgo.dev/cursor v0.2.0 // indirect
18+
atomicgo.dev/keyboard v0.2.9 // indirect
19+
atomicgo.dev/schedule v0.1.0 // indirect
20+
github.com/bombsimon/logrusr/v4 v4.0.0 // indirect
21+
github.com/containerd/console v1.0.3 // indirect
22+
github.com/fsnotify/fsnotify v1.7.0 // indirect
23+
github.com/go-logr/logr v1.4.1 // indirect
24+
github.com/google/go-containerregistry v0.16.1 // indirect
25+
github.com/gookit/color v1.5.4 // indirect
26+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
27+
github.com/kr/text v0.2.0 // indirect
28+
github.com/lithammer/fuzzysearch v1.1.8 // indirect
29+
github.com/mattn/go-runewidth v0.0.15 // indirect
30+
github.com/rivo/uniseg v0.4.4 // indirect
31+
github.com/rogpeppe/go-internal v1.11.0 // indirect
32+
github.com/samber/lo v1.38.1 // indirect
33+
github.com/samber/slog-logrus v1.0.0 // indirect
34+
github.com/sergi/go-diff v1.3.1 // indirect
35+
github.com/sirupsen/logrus v1.9.3 // indirect
36+
github.com/spf13/pflag v1.0.5 // indirect
37+
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
38+
golang.org/x/mod v0.14.0 // indirect
39+
golang.org/x/sys v0.16.0 // indirect
40+
golang.org/x/term v0.16.0 // indirect
41+
golang.org/x/text v0.14.0 // indirect
42+
golang.org/x/tools v0.16.0 // indirect
43+
gopkg.in/yaml.v2 v2.4.0 // indirect
44+
k8s.io/apimachinery v0.29.0 // indirect
45+
k8s.io/klog/v2 v2.110.1 // indirect
46+
sigs.k8s.io/controller-runtime v0.16.3 // indirect
47+
sigs.k8s.io/controller-tools v0.12.0 // indirect
48+
)

0 commit comments

Comments
 (0)