Skip to content

Commit beed68f

Browse files
authored
Merge branch 'gptscript-ai:main' into main
2 parents f0f9f04 + ea1691a commit beed68f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+3690
-328
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
/bin
22
/.idea
33
/static/ui
4+
**/node_modules/
5+
**/package-lock.json
6+
**/__pycache__
7+
/docs/yarn.lock
8+
/releases
9+
/checksums.txt
10+
/.env*

README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ calls. With GPTScript you can do just about anything, like [plan a vacation](./e
1010
[edit a file](./examples/add-go-mod-dep.gpt), [run some SQL](./examples/sqlite-download.gpt), or [build a mongodb/flask app](./examples/hacker-news-headlines.gpt).
1111

1212
| :memo: | We are currently exploring options for interacting with local models using GPTScript. |
13-
|-|:-|
13+
| ------ | :------------------------------------------------------------------------------------ |
1414

1515
```yaml
1616
# example.gpt
@@ -28,14 +28,18 @@ the result of that.
2828

2929
When done remove the database file and the downloaded content.
3030
```
31-
```
31+
32+
```shell
3233
$ gptscript ./example.gpt
34+
```
3335

36+
```
3437
OUTPUT:
3538
3639
The artist with the most number of albums in the database is Iron Maiden, with a total
3740
of 21 albums.
3841
```
42+
3943
## Quick Start
4044

4145
### 1. Install the latest release
@@ -52,6 +56,13 @@ brew install gptscript-ai/tap/gptscript
5256
curl https://get.gptscript.ai/install.sh | sh
5357
```
5458

59+
### Scoop (Windows)
60+
61+
```shell
62+
scoop bucket add extras # If 'extras' is not already enabled
63+
scoop install gptscript
64+
```
65+
5566
#### WinGet (Windows)
5667

5768
```shell
@@ -70,6 +81,15 @@ Download and install the archive for your platform and architecture from the [re
7081
export OPENAI_API_KEY="your-api-key"
7182
```
7283

84+
Alternatively Azure OpenAI can be utilized
85+
86+
```shell
87+
export OPENAI_API_KEY="your-api-key"
88+
export OPENAI_BASE_URL="your-endpiont"
89+
export OPENAI_API_TYPE="AZURE"
90+
export OPENAI_AZURE_DEPLOYMENT="your-deployment-name"
91+
```
92+
7393
#### Windows
7494

7595
```powershell
@@ -80,16 +100,22 @@ $env:OPENAI = 'your-api-key'
80100

81101
```shell
82102
gptscript https://get.gptscript.ai/echo.gpt --input 'Hello, World!'
103+
```
83104

105+
```
84106
OUTPUT:
85107
86108
Hello, World!
87109
```
110+
88111
The model used by default is `gpt-4-turbo-preview` and you must have access to that model in your OpenAI account.
89112

113+
If using Azure OpenAI, make sure you configure the model to be one of the supported versions with the `--default-model` argument.
114+
90115
### 4. Extra Credit: Examples and Run Debugging UI
91116

92117
Clone examples and run debugging UI
118+
93119
```shell
94120
git clone https://github.com/gptscript-ai/gptscript
95121
cd gptscript/examples
@@ -100,13 +126,14 @@ gptscript --server
100126

101127
## How it works
102128

103-
***GPTScript is composed of tools.*** Each tool performs a series of actions similar to a function. Tools have available
129+
**_GPTScript is composed of tools._** Each tool performs a series of actions similar to a function. Tools have available
104130
to them other tools that can be invoked similar to a function call. While similar to a function, the tools are
105-
primarily implemented with a natural language prompt. ***The interaction of the tools is determined by the AI model***,
131+
primarily implemented with a natural language prompt. **_The interaction of the tools is determined by the AI model_**,
106132
the model determines if the tool needs to be invoked and what arguments to pass. Tools are intended to be implemented
107133
with a natural language prompt but can also be implemented with a command or HTTP call.
108134

109135
### Example
136+
110137
Below are two tool definitions, separated by `---`. The first tool does not require a name or description, but
111138
every tool after name and description are required. The first tool, has the parameter `tools: bob` meaning that the tool named `bob` is available to be called if needed.
112139

@@ -122,14 +149,19 @@ args: question: The question to ask Bob.
122149

123150
When asked how I am doing, respond with "Thanks for asking "${question}", I'm doing great fellow friendly AI tool!"
124151
```
152+
125153
Put the above content in a file named `bob.gpt` and run the following command:
154+
126155
```shell
127156
$ gptscript bob.gpt
157+
```
128158

159+
```
129160
OUTPUT:
130161
131162
Bob said, "Thanks for asking 'How are you doing?', I'm doing great fellow friendly AI tool!"
132163
```
164+
133165
Tools can be implemented by invoking a program instead of a natural language prompt. The below
134166
example is the same as the previous example but implements Bob using python.
135167

@@ -156,9 +188,11 @@ or external services.
156188
## GPT File Reference
157189

158190
### Extension
191+
159192
GPTScript files use the `.gpt` extension by convention.
160193

161194
### File Structure
195+
162196
A GPTScript file has one or more tools in the file. Each tool is separated by three dashes `---` alone on a line.
163197

164198
```yaml
@@ -191,6 +225,7 @@ Args: arg1: The description of arg1
191225

192226
Tool instructions go here.
193227
```
228+
194229
#### Tool Parameters
195230

196231
Tool parameters are key-value pairs defined at the beginning of a tool block, before any instructional text. They are specified in the format `key: value`. The parser recognizes the following keys (case-insensitive and spaces are ignored):

docs/README-USECASES.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Use Cases of GPTScript
2+
3+
## Retrieval
4+
5+
Retrieval-Augmented Generation (RAG) leverages a knowledge base outside of the training data before consulting the LLM to generate a response.
6+
The following GPTScript implements RAG:
7+
8+
```yaml
9+
name: rag
10+
description: implements retrieval-augmented generation
11+
args: prompt: a string
12+
tools: query
13+
14+
First query the ${prompt} in the knowledge base, then construsts an answer to ${prompt} based on the result of the query.
15+
16+
---
17+
18+
name: query
19+
description: queries the prompt in the knowledge base
20+
args: prompt: a string
21+
22+
... (implementation of knowledge base query follows) ...
23+
```
24+
25+
The idea behind RAG is simple. Its core logic can be implemented in one GPTScript statement: `First query the ${prompt} in the knowledge base, then construsts an answer to ${prompt} based on the result of the query.` The real work of building RAG lies in the tool that queries your knowledge base.
26+
27+
You construct the appropriate query tool based on the type of knowledge base you have.
28+
29+
| Knowledge Base | Query Tool |
30+
|------|------|
31+
| A vector database storing common document types such as text, HTML, PDF, and Word | Integrate with LlamaIndex for vector database support [Link to example]|
32+
| Use the public or private internet to supply up-to-date knowledge | Implement query tools using a search engine, as shown in [`search.gpt`](../examples/search.gpt)|
33+
| A structured database supporting SQL such as sqlite, MySQL, PostgreSQL, and Oracle DB | Implement query tools using database command line tools such as `sqlite` and `mysql` [Link to example]|
34+
| An ElasticSearch/OpenSearch database storing logs or other text files | Implement query tools using database command line tools [Link to example]|
35+
| Other databases such as graph or time series databases | Implement query tools using database command line tools [Link to example]|
36+
37+
## Task Automation
38+
39+
### Planning
40+
41+
Here is a GPTScript that produces a detailed travel itenirary based on inputs from a user: [`travel-agent.gpt`](../examples/travel-agent.gpt)
42+
43+
### Web UI Automation
44+
45+
GPTScript enables the automation of data collection and analysis from websites through seamless interaction with a Chrome web browser. Here's an example to illustrate how it works:
46+
47+
1. Please install the browsing tool and configure it to operate continuously in the background as a service.
48+
49+
```sh
50+
git clone https://github.com/gptscript-ai/browser
51+
52+
cd browser
53+
54+
npm install
55+
56+
npm run server
57+
```
58+
59+
2. Let's explore a brief example on how to navigate through the Coachella Festival offerings and retrieve ticketing details
60+
61+
```sh
62+
# Go to the browser repo you just cloned
63+
cd browser
64+
65+
gpscript ./example/coachella-browse.gpt
66+
```
67+
68+
For additional examples, please explore [here](https://github.com/gptscript-ai/browser?tab=readme-ov-file#examples).
69+
70+
### CLI Automation
71+
72+
Here is a GPTScript that automates Kubernetes operations by driving the `kubectl` command line. [Link to example here]
73+
74+
## Agents and Assistants
75+
76+
Agents and assistants are synonyms. They are software programs that leverage LLM to carry out tasks.
77+
78+
In GPTScript, agents and assistants are implemented using tools. Tools can use other tools. Tools can be implemented using natural language prompts or using traditional programming languages such as Python or JavaScript. You can therefore build arbitrarily complex agents and assistants in GPTScript. Here is an example of an assistant that leverages an HTTP client, MongoDB, and Python code generation to display Hacker News headlines: [`hacker-news-headlines.gpt`](../examples/hacker-news-headlines.gpt)
79+
80+
## Data Analysis
81+
82+
Depending on the context window supported by the LLM, you can either send a large amount of data to the LLM to analyze in one shot or supply data in batches.
83+
84+
### Summarization
85+
86+
Here is a GPTScript that sends a large document in batches to the LLM and produces a summary of the entire document. [hamlet-summarizer](../examples/hamlet-summarizer)
87+
88+
Here is a GPTScript that reads the content of a large SQL database and produces a summary of the entire database. [Link to example here]
89+
90+
### Tagging
91+
92+
Here is a GPTScript that performs sentiment analysis on the input text. [Link to example here]
93+
94+
### CSV Files
95+
96+
Here is a GPTScript that summarizes the content of a CSV file. [Link to example here]
97+
98+
### Understanding Code
99+
100+
Here is a GPTScript that summarizes the the code stored under the current directory: [`describe-code.gpt`](../examples/describe-code.gpt)
101+
102+
## Vision, Image, and Audio
103+
104+
### Vision
105+
106+
Here is an example of a web app that leverages GPTScript to recognize ingredients in a photo and suggest a recipe based on them: [recipe-generator](../examples/recipegenerator).
107+
108+
### Image Generation
109+
110+
Here is a GPTScript that takes a story prompt and generates an illustrated children's book: [story-book.gpt](../examples/story-book)
111+
112+
## Memory Management
113+
114+
LLMs are stateless. That's why GPTScript by default caches LLM invocations. LLM apps need to keep memory outside of the model.
115+
116+
GPTScript provides a means to manage memory that persists across multiple LLM invocations. The relevant information can be extracted and passed into the LLM as part of the context. In addition, LLM can utilize tools to obtain additional data from the memory maintained in GPTScript.
117+
118+
[More details to follow.]
119+
120+
## Chatbots
121+
122+
GPTScript in combination with Rubra UI provide you with a turn-key implementation of chatbots. [More details to follow]

docs/docs/01-overview.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ the result of that.
2727

2828
When done remove the database file and the downloaded content.
2929
```
30-
```
30+
```shell
3131
$ gptscript ./example.gpt
32-
32+
```
33+
```
3334
OUTPUT:
3435
3536
The artist with the most number of albums in the database is Iron Maiden, with a total

docs/docs/02-getting-started.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,15 @@ Download and install the archive for your platform and architecture from the [re
3232
export OPENAI_API_KEY="your-api-key"
3333
```
3434

35+
Alternatively Azure OpenAI can be utilized
36+
37+
```shell
38+
export OPENAI_API_KEY="your-api-key"
39+
export OPENAI_BASE_URL="your-endpiont"
40+
export OPENAI_API_TYPE="AZURE"
41+
export OPENAI_AZURE_DEPLOYMENT="your-deployment-name"
42+
```
43+
3544
#### Windows
3645

3746
```powershell
@@ -47,11 +56,15 @@ OUTPUT:
4756

4857
Hello, World!
4958
```
59+
5060
The model used by default is `gpt-4-turbo-preview` and you must have access to that model in your OpenAI account.
5161

62+
If using Azure OpenAI, make sure you configure the model to be one of the supported versions with the `--default-model` argument.
63+
5264
### 4. Extra Credit: Examples and Run Debugging UI
5365

5466
Clone examples and run debugging UI
67+
5568
```shell
5669
git clone https://github.com/gptscript-ai/gptscript
5770
cd gptscript/examples
File renamed without changes.

docs/docs/100-tools/03-offerings/01-image-generation.md renamed to docs/docs/100-tools/03-offerings/02-image-generation.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ referencing the tool's link in your GPTScript. For now, you can follow the steps
1414
git clone https://github.com/gptscript-ai/image-generation
1515
```
1616

17-
2. Run `make bootstrap` to setup the python venv and install the required dependencies.
17+
2. In the newly cloned repo, run `make bootstrap` to setup the python venv and install the required dependencies. Then activate the virtual environment.
1818

1919
```shell
2020
make bootstrap
21+
source .venv/bin/activate
2122
```
2223

23-
3. Reference `<path-to-the-repo>/tool.gpt` in your GPTScript.
24+
> Note: You can install the python dependencies manually by running `pip install -r requirements.txt` in the root of the cloned repository. This prevents the need to run `make bootstrap` or activate the virtual environment.
25+
26+
3. In the same shell session that your virutal environment is activated, reference `<path-to-the-repo>/tool.gpt` in your GPTScript.
2427

2528
## Usage
2629
To use the Image Generation tool, you need to make sure that the OPENAI_API_KEY environment variable is set to your OpenAI API key. You can obtain an API key from the OpenAI platform if you don't already have one.

0 commit comments

Comments
 (0)