Skip to content

Commit 96cb5ad

Browse files
committed
Add a couple examples
Signed-off-by: Grant Linville <[email protected]>
1 parent 41c9c9d commit 96cb5ad

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

examples/generate-gptscript.gpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
tools: sys.find, sys.read, sys.write, sys.exec
2+
3+
I have a new tool called gptscript. You can find information about it here in this folder
4+
by looking at *.gpt files and the README.md file. The examples folder should be particularly helpful.
5+
6+
Do the following:
7+
8+
1. Search through the *.gpt files and README.md in order to learn how gptscript works.
9+
2. Write a new gptscript file called myfile.gpt that uses the sys.write tool to write the first 10
10+
numbers in the Fibonacci sequence to a file called fibonacci.txt.
11+
3. Execute the myfile.gpt script by running the following command: gptscript myfile.gpt

examples/hacker-news-headlines.gpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
tools: sys.http.get, sys.http.html2text, sys.find, sys.write, mongo_run, mongo_command, init_flask_project
2+
3+
Perform the following actions in this order:
4+
5+
1. Start the MongoDB database.
6+
2. Create a collection in the Mongo instance called `headlines`.
7+
3. Visit https://hackernews.com and get the top ten headlines.
8+
4. Call the init_flask_project tool to set up the directories you will need.
9+
5. Write each headline into the MongoDB collection that you created earlier called `headlines`. Write each one using a separate call to the mongo_command tool. The name of the database in Mongo that these will be written to is `headlines`. Don't forget to escape any quotation marks or apostrophes that appear in the headlines.
10+
6. Generate a simple webserver in Python using Flask that will connect to the database and serve a single page listing all the headlines. Create it in the `headline` directory. Embed a link to the article in each headline displayed on the page.
11+
7. Add some basic CSS styling to make the page look cool and modern. I want it to be dark themed. Style the links to be a light gray color. Make sure the page has a neat header with red accents.
12+
13+
---
14+
name: mongo_run
15+
description: starts a MongoDB database
16+
17+
#!/usr/bin/env bash
18+
19+
docker run -d -p 27017:27017 --name mongodb mongo:latest
20+
21+
---
22+
name: mongo_command
23+
description: run a command in the MongoDB database
24+
args: command: the command to run in mongodb
25+
26+
#!/usr/bin/env bash
27+
28+
mongosh mongodb://localhost:27017/headlines --eval "$COMMAND"
29+
30+
---
31+
name: init_flask_project
32+
description: sets up initial directory structure needed for the flask project
33+
34+
#!/usr/bin/env bash
35+
36+
mkdir -p headline/{templates,static}

0 commit comments

Comments
 (0)