Skip to content

Commit e225194

Browse files
committed
docs: add image-generator cookbook
Signed-off-by: tylerslaton <[email protected]>
1 parent 41de01e commit e225194

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Image Generator
2+
3+
In this example, let's say that we want to create an image generator tool that will take a prompt from the user and generate an image based on that prompt but
4+
in a specific style that we tell the tool to use.
5+
6+
1. Clone the image-generation tool repository from Github.
7+
8+
```shell
9+
git clone https://github.com/gptscript-ai/image-generation
10+
```
11+
12+
2. Bootstrap the tool.
13+
14+
```shell
15+
make bootstrap
16+
```
17+
18+
3. Create a file called `painter.gpt`.
19+
20+
```yaml
21+
tools: ./image-generation/tool.gpt, sys.download, sys.write
22+
args: prompt: (required) The prompt to use for generating the image.
23+
24+
Generate the ${prompt} in the style of a 17th century impressionist oil painting.
25+
26+
Write the resulting image to a file named "painting.png".
27+
```
28+
29+
4. Run the script.
30+
31+
```shell
32+
gptscript painter.gpt --prompt "a city skyline at night"
33+
```
34+
35+
This will generate an image of a city skyline at night in the style of a 17th century impressionist oil painting and write the resulting image to a file named `painting.png`.
36+
37+
## Recap
38+
In this example, we have created a GPTScript that leverages the `image-generation` tool to generate an image based on a prompt. We gave it some flexibility by specifiying an argument `prompt` that the user can provide when running the script. We also specified gave the script a specific style of the image that we want to generate, that being a 17th century impressionist oil painter.
39+
40+
Notable things to point out:
41+
#### Tools
42+
The `tools` directive was used here to reference the `image-generation` tool and the `sys.download` and `sys.write` system tools. GPTScript will know the tools availble to it and will use them when it sees fit in the script.
43+
44+
#### Args
45+
We used the `args` directive to specify the `prompt` argument that the user can provide when running the script. This is a required argument and the user must provide it when running the script.
46+
47+
#### Interpolation
48+
The `${prompt}` syntax can we used to reference the `prompt` argument in the script. This is a made-up syntax and can be replaced with any other syntax that you prefer. The LLM should be able to understand the syntax and use the argument in the script.

0 commit comments

Comments
 (0)