Skip to content

Add a couple examples #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/generate-gptscript.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
tools: sys.find, sys.read, sys.write, sys.exec

I have a new tool called gptscript. You can find information about it here in this folder
by looking at *.gpt files and the README.md file. The examples folder should be particularly helpful.

Do the following:

1. Search through the *.gpt files and README.md in order to learn how gptscript works.
2. Write a new gptscript file called myfile.gpt that uses the sys.write tool to write the first 10
numbers in the Fibonacci sequence to a file called fibonacci.txt.
3. Execute the myfile.gpt script by running the following command: gptscript myfile.gpt
36 changes: 36 additions & 0 deletions examples/hacker-news-headlines.gpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
tools: sys.http.get, sys.http.html2text, sys.find, sys.write, mongo_run, mongo_command, init_flask_project

Perform the following actions in this order:

1. Start the MongoDB database.
2. Create a collection in the Mongo instance called `headlines`.
3. Visit https://hackernews.com and get the top ten headlines.
4. Call the init_flask_project tool to set up the directories you will need.
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.
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.
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.

---
name: mongo_run
description: starts a MongoDB database

#!/usr/bin/env bash

docker run -d -p 27017:27017 --name mongodb mongo:latest

---
name: mongo_command
description: run a command in the MongoDB database
args: command: the command to run in mongodb

#!/usr/bin/env bash

mongosh mongodb://localhost:27017/headlines --eval "$COMMAND"

---
name: init_flask_project
description: sets up initial directory structure needed for the flask project

#!/usr/bin/env bash

mkdir -p headline/{templates,static}