-
Notifications
You must be signed in to change notification settings - Fork 281
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
Add kubectl example #175
base: main
Are you sure you want to change the base?
Add kubectl example #175
Changes from all commits
28371b5
32c9f53
ac7408d
1e03b0e
2397e04
2c2b660
a3b9ccb
4865819
f19775d
012bc60
9e381d6
29b9f6d
db2e38f
c9ccbc5
a62221e
e130d06
d8537fc
cc5e188
83fa002
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
tools: sys.write, kubectl, helm, browser | ||
|
||
Do not make parallel function calls. Only call one function at a time. | ||
Perform the following tasks in order: | ||
|
||
1. Create a Namespace named vote but do not fail if it already exists | ||
2. Deploy in the vote namespace the application which yaml specification is available at https://luc.run/vote.yaml | ||
3. Use a single command to wait for all the Pods in the vote namespace to be ready | ||
4. Install Traefik ingress controller in kube-system namespace with helm only if it is not already installed in this namespace | ||
5. Make sure the Traefik Pod is in running status | ||
6. Wait for the IP address of the traefik Service to be available and save it in the file ./lb-ip.txt | ||
7. Create the file ./ingress.yaml and make sure it contains the yaml specification of an Ingress resource which exposes the vote-ui Service on vote.LBIP.nip.io and the result-ui Service on result.LBIP.nip.io, first making sure to replace the LBIP placeholders with the content of the file ./lb-ip.txt | ||
8. Create the Ingress resource specified in ./ingress.yaml | ||
9. Open a browser on vote.LBIP.nip.io but make sure to replace the LBIP placeholder with the content of lb-ip.txt in this URL first | ||
|
||
--- | ||
name: kubectl | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't remember if we discussed this, but this is technically a "safer" way to implement:
Can you do it this way or was there a particular reason you didn't? I can't recall the details of the convos we had around this. |
||
tools: sys.exec | ||
description: use kubectl command to manage k8s resources | ||
args: command: the command kubectl needs to run | ||
|
||
You are a kubernetes operator which can run kubectl commands to manage clusters and applications | ||
The only reason you use sys.exec tool must be to use kubectl to run the command provided, this command must start with kubectl | ||
|
||
--- | ||
name: helm | ||
tools: sys.exec | ||
description: use helm command to manage k8s charts | ||
args: command: the command helm needs to run | ||
|
||
You are a kubernetes operator which can run helm commands to manage charts | ||
The only reason you use sys.exec tool must be to use helm to run the command provided, this command must start with helm | ||
|
||
--- | ||
name: browser | ||
tools: sys.exec | ||
args: url: the url to open | ||
description: open a browser window | ||
|
||
You are only in charge of opening a browser window on the requested url | ||
You can only use the sys.exec tool to open a browser window | ||
Comment on lines
+34
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you not use our browser tool for this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, I need to open a window so show the application. Can the browser tool open a window ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! That's what it is designed to do. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
This example shows how to use GPTScript to run regular tasks. It involves the creation of a VM and defines a crontab entry onto that one. | ||
|
||
This example checks if a specific URL is reachable and sends the status code to an external webhook. If you want to test this example, you need to follow the steps below: | ||
|
||
- Create a DigitalOcean PAT token and export it in the DIGITALOCEAN_ACCESS_TOKEN environment variable | ||
|
||
- Create a new SSH key on your local machine | ||
|
||
``` | ||
ssh-keygen -f /tmp/do_gptscript | ||
``` | ||
|
||
- Define a new SSH key in DigitalOcean using the public part of the SSH key created above and call it `gptscript` | ||
|
||
- Get a token from [https://webhooks.app](https://webhooks.app) | ||
|
||
![webhooks](./picts/webhooks-1.png) | ||
|
||
Note: your token will be different | ||
|
||
- Run gptscript example using this token | ||
|
||
``` | ||
gptscript --cache=false ./regular-task.gpt --url https://fakely.app --token 1e105ea8bef80ca6aba7c8953c34d3 | ||
``` | ||
|
||
- Check the message coming every minute on the [Webhooks dashboard](https://webhooks.app/dashboard) | ||
|
||
![webhooks](./picts/webhooks-2.png) | ||
|
||
- Once you're done, do not forget to remove the DigitalOcean VM created in the process |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
tools: get-webhook-token, create-regular-task | ||
args: url: URL of the website to check | ||
|
||
First get a new token to authenticate against a webhook | ||
|
||
Next create a task which verifies every minute if the website ${url} is reachable and sends the status code to the following HTTP POST request: | ||
- URL is https://webhooks.app/data | ||
- Authorization bearer is the content of ./token.txt file | ||
- A json payload must be returned, containing a "message" property with the value of the ${url} and the status code returned | ||
|
||
--- | ||
tools: sys.exec | ||
name: get-webhook-token | ||
description: get a token to authenticate against https://webhooks.app | ||
|
||
#!/bin/bash | ||
|
||
curl -s -XGET https://webhooks.app/wh | jq -r .token > ./token.txt | ||
|
||
--- | ||
tools: create-vm, create-crontab-entry | ||
name: create-regular-task | ||
decription: Manage the creation of a crontab on a remove VM | ||
args: command: command to be run in a crontab without the schedule part | ||
args: schedule: schedule to be used in a crontab | ||
|
||
Perform the actions in the following order: | ||
|
||
1. Create a virtual machine on DigitalOcean | ||
2. Create a crontab entry for command ${command} and schedule ${schedule} in that VM | ||
|
||
--- | ||
tools: sys.exec, sys.write | ||
name: create-crontab-entry | ||
description: Create a crontab entry in a remote VM | ||
args: command: command to run in a crontab on the remote VM | ||
args: schedule: schedule for the crontab | ||
|
||
Perform the step in this exact order taking into account that if you need to call a ssh command you must use user root and the IP address which value is in ./vm.ip | ||
|
||
1. Create a bash file containing the ${command} to run without the schedule part, make it executable, and make sure the components are correctly escaped first. | ||
2. Make sure this file contains the value of the token that is inside the ./token.txt file and that it does not only reference this file | ||
3. Send this file to the remote VM via ssh saving it to /tmp/cron.sh on the remove VM | ||
4. Create a crontab entry calling /tmp/cron.sh file for the schedule specified in the ${command} | ||
|
||
--- | ||
tools: sys.exec | ||
name: create-vm | ||
description: create a virtual machine on DigitalOcean | ||
|
||
You are an operator which can use the doctl command line tool to interact with DigitalOcean infrastructure | ||
|
||
Perform the actions in this exact order: | ||
|
||
1. Get the ID of the ssh-key named gptscript and save it in ./key.id | ||
2. Create a Virtual Machine in the new-york datacenter named cron making sure to provide the id from ./key.id as the ssh-key of the new droplet | ||
3. Wait for the VM to be up and running and save its IP address only in ./vm.ip | ||
4. Loop waiting for the SSH connection with user root to be possible to that VM. Do not raise an error in case the SSH connection is not yet possible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and line 5 should no longer be needed as we baked this into the system prompt of gptscript (see: https://github.com/gptscript-ai/gptscript/pull/161/files)
I'll merge this as-is, but I'm curious if you see unexpected behavior without these two lines.