From 96cb5ad9918fd8dfc8b7e48b03ebaca1e7ba29e5 Mon Sep 17 00:00:00 2001 From: Grant Linville Date: Mon, 12 Feb 2024 14:06:07 -0500 Subject: [PATCH] Add a couple examples Signed-off-by: Grant Linville --- examples/generate-gptscript.gpt | 11 +++++++++ examples/hacker-news-headlines.gpt | 36 ++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 examples/generate-gptscript.gpt create mode 100644 examples/hacker-news-headlines.gpt diff --git a/examples/generate-gptscript.gpt b/examples/generate-gptscript.gpt new file mode 100644 index 00000000..934035f9 --- /dev/null +++ b/examples/generate-gptscript.gpt @@ -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 \ No newline at end of file diff --git a/examples/hacker-news-headlines.gpt b/examples/hacker-news-headlines.gpt new file mode 100644 index 00000000..d8c5123d --- /dev/null +++ b/examples/hacker-news-headlines.gpt @@ -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}