Open sangee2004 opened 8 months ago
- For
hacker-news-headlines.gpt
example -https://github.com/gptscript-ai/gptscript/blob/main/examples/hacker-news-headlines.gpt script
to work , we would need to have mongosh pre installed. Is it possible to have this auto installed as part of script execution?
we should not need anything preinstalled if using mongosh
that comes within the mongodb
container is preferred/acceptable, i.e:
-mongosh mongodb://localhost:27017/headlines --eval "$COMMAND"
+docker exec mongodb mongosh mongodb://localhost:27017/headlines --eval "$COMMAND"
- The script results in flask project being created. To run the app.py app that was generated by the scroipt , we have to manually do pip install of the 2 packages - pymong and flask. Is it possible to have a requirements.txt also generated which would have the list of all dependecies ?
Do we want to hardcode it or let the LLM handle it? I'm testing with a modified version (goes a bit further) to keep local machine clean and have it managed by the script for demos.
tools: sys.http.get, sys.http.html2text, sys.find, sys.write, mongo_run, mongo_command, python_run, 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, apostrophes (single quote) 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. Use `host.docker.internal` instead of `localhost` to connect to mongodb. 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.
8. Generate `README.md` file in the `headline` directory containing information on how to create python virtual env, activate it, download python packages needed to run the webserver created and generate `requirements.txt` file. Make sure all steps are documented.
9. Generate `requirements.txt` file in the `headline` directory containing all Python dependencies. Do not attach versions to the dependencies.
10. Start Python instance as the last step.
---
name: mongo_run
description: starts a MongoDB database
#!/usr/bin/env bash
# The name of your container
CONTAINER_NAME=mongodb
# Check if the container already exists
if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
echo "Container ${CONTAINER_NAME} exists."
# Check if the container is already running
if ! docker ps --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
echo "Starting existing container ${CONTAINER_NAME}."
docker start ${CONTAINER_NAME}
else
echo "Container ${CONTAINER_NAME} is already running."
fi
else
echo "Container ${CONTAINER_NAME} does not exist. Running a new one."
docker run --rm -d -p 27017:27017 --name ${CONTAINER_NAME} mongo:latest
fi
---
name: mongo_command
description: run a command in the MongoDB database
args: container: mongodb container name
args: command: the command to run in mongodb
#!/usr/bin/env bash
docker exec "$CONTAINER" 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}
---
name: python_run
description: starts a Python docker instance
#!/usr/bin/env bash
# The name of your container
CONTAINER_NAME=python3-headline
# Check if the container already exists
if docker ps -a --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
echo "Container ${CONTAINER_NAME} exists."
# Check if the container is already running
if ! docker ps --format '{{.Names}}' | grep -Eq "^${CONTAINER_NAME}\$"; then
echo "Starting existing container ${CONTAINER_NAME}."
docker start ${CONTAINER_NAME}
else
echo "Container ${CONTAINER_NAME} is already running."
fi
else
echo "Container ${CONTAINER_NAME} does not exist. Running a new one."
docker run --rm -d -p 5000:5000 --add-host=host.docker.internal:host-gateway --name ${CONTAINER_NAME} -v $(pwd)/headline:/headline:ro python:slim bash -c "cp -r /headline /tmp/; cd /tmp/headline; python3 -m venv venv; source venv/bin/activate; pip install -r requirements.txt; flask run --host=0.0.0.0"
fi
For
hacker-news-headlines.gpt
example -https://github.com/gptscript-ai/gptscript/blob/main/examples/hacker-news-headlines.gpt script
to work , we would need to have mongosh pre installed. Is it possible to have this auto installed as part of script execution?The script results in flask project being created. To run the
app.py
app that was generated by the scroipt , we have to manually do pip install of the 2 packages - pymong and flask. Is it possible to have arequirements.txt
also generated which would have the list of all dependecies ?