### Install and Run GPTScript on Windows Source: https://docs.gptscript.ai/ Installation method for Windows using the winget package manager. ```powershell winget install gptscript-ai.gptscript gptscript github.com/gptscript-ai/llm-basics-demo ``` -------------------------------- ### Install and Run GPTScript via Homebrew Core Source: https://docs.gptscript.ai/ Standard Homebrew installation, though note that the core formula may be outdated compared to the tap. ```bash brew install gptscript gptscript github.com/gptscript-ai/llm-basics-demo ``` -------------------------------- ### Tool Body Instructions Source: https://docs.gptscript.ai/tools/gpt-file-reference Example showing both natural language prompts and shell command execution within a tool body. ```text Name: echo-ai Description: A tool that echos the input Parameter: input: The input Just return only "${input}" --- Name: echo-command Description: A tool that echos the input Parameter: input: The input #!/bin/bash echo "${input}" ``` -------------------------------- ### Example output file Source: https://docs.gptscript.ai/examples/workflow The resulting markdown file generated by the script. ```markdown ## Jun 4, 2024 [Acorn Labs Tweet](https://x.com/acornlabs/status/1798063732394000559) Our latest release of #GPTScript v0.7 is available now. Key updates include OpenAPI v2 support, workspace tools replacement, and a chat history context tool. ### References - [Acorn | Introducing GPTScript v0.7](https://buff.ly/3V1KiWw): The page is a blog post introducing GPTScript v0.7, highlighting its new features and fixes. Key updates include support for OpenAPI v2, removal and replacement of workspace tools, introduction of a chat history context tool, and several housekeeping changes like defaulting to the gpt-4o model and logging token usage. The post also mentions upcoming features in v0.8 and provides links to related articles and resources. ## Jun 4, 2024 [Acorn Labs Tweet](https://x.com/acornlabs/status/1797998244447900084) Use #GPTScript with #Python to build the front end of this AI-powered YouTube generator. Part of this series walks you through it all. ### References - [Tutorial on building an AI-powered YouTube title and thumbnail generator (Part 1)](https://buff.ly/4aGJYCD): Covers setting up the front end with Flask, modifying the script, and creating templates for the front page and result page. - [Tutorial on building an AI-powered YouTube title and thumbnail generator (Part 2)](https://buff.ly/49MSK1k): Covers the installation and setup of GPTScript, creating a basic script, handling command-line arguments, generating a YouTube title, and generating thumbnails using DALL-E 3. ``` -------------------------------- ### Install and Run GPTScript via Homebrew Tap Source: https://docs.gptscript.ai/ Recommended method for MacOS and Linux to ensure the latest version is installed. ```bash brew install gptscript gptscript github.com/gptscript-ai/llm-basics-demo ``` -------------------------------- ### Specify Workspace Directory Source: https://docs.gptscript.ai/examples/local-files Example command syntax for specifying a custom workspace directory. ```bash gptscript --workspace=/Your/path/here ... ``` -------------------------------- ### Define a Daemon Tool with Node.js Source: https://docs.gptscript.ai/tools/daemon Example of a GPTScript tool definition using #!sys.daemon to launch a Node.js HTTP server. ```text Tools: my-daemon Param: first: the first parameter Param: second: the second parameter #!http://my-daemon.daemon.gptscript.local/myPath --- Name: my-daemon #!sys.daemon node const http = require('http'); const server = http.createServer((req, res) => { if (req.method === 'GET' || req.method === 'POST') { // Extract the path from the request URL const path = req.url; let body = ''; req.on('data', chunk => { body += chunk.toString(); }) // Respond with the path and body req.on('end', () => { res.writeHead(200, { 'Content-Type': 'text/plain' }); res.write(`Body: ${body}\n`); res.end(`Path: ${path}`); }) } else { res.writeHead(405, { 'Content-Type': 'text/plain' }); res.end('Method Not Allowed'); } }); const PORT = process.env.PORT || 3000; server.listen(PORT, () => { console.log(`Server is listening on port ${PORT}`); }); ``` -------------------------------- ### Install GPTScript via shell Source: https://docs.gptscript.ai/faqs Use this command on macOS or Linux if Homebrew is not available. ```bash curl https://get.gptscript.ai/install.sh | sh ``` -------------------------------- ### Tool Definition Preamble Source: https://docs.gptscript.ai/tools/gpt-file-reference Example of a tool definition including comments and parameter declarations. ```text Name: tool-name # This is a comment in the preamble. Description: Tool description # This tool can invoke tool1 or tool2 if needed Tools: tool1, tool2 Param: param1: The description of param1 Tool instructions go here. ``` -------------------------------- ### GPTScript File Structure Source: https://docs.gptscript.ai/tools/gpt-file-reference Example of a GPTScript file containing multiple tools separated by triple dashes. ```text Name: tool1 Description: This is tool1 Do sample tool stuff. --- Name: tool2 Description: This is tool2 Do more sample tool stuff. ``` -------------------------------- ### Referencing External Tools Source: https://docs.gptscript.ai/tools/using Examples of importing tools from remote URLs or local files. ```gptscript tools: https://raw.githubusercontent.com/gptscript-ai/gptscript/refs/heads/main/examples/echo.gpt Echo the phrase "Hello, World!". ``` ```gptscript tools: echo.gpt Echo the phrase "Hello, World!". ``` -------------------------------- ### Use OpenAPI Petstore as a Tool Source: https://docs.gptscript.ai/tools/openapi Example of referencing an OpenAPI definition URL directly within a GPTScript tool definition. ```text Tools: https://petstore.gptscript-demos.ai/openapi List all the pets. What are the names of the dogs? ``` -------------------------------- ### GPTScript execution output Source: https://docs.gptscript.ai/tools/how-it-works The expected output after running the provided GPTScript example. ```text OUTPUT: Bob said, "Thanks for asking 'How are you doing?', I'm doing great fellow friendly AI tool!" ``` -------------------------------- ### Define credential in GPTScript Source: https://docs.gptscript.ai/tools/credential-tools Example of referencing a credential tool within a script. ```gptscript Credential: my-credential-tool.gpt as myCred ``` -------------------------------- ### Define remote tools in GPTScript Source: https://docs.gptscript.ai/faqs Example syntax for including a remote tool or context within a script. ```text Tools: github.com/gptscript-ai/browser ``` -------------------------------- ### Define Security Schemes Source: https://docs.gptscript.ai/tools/openapi Example of defining multiple security schemes globally in an OpenAPI document. ```yaml servers: - url: https://api.example.com/v1 components: securitySchemes: MyBasic: type: http scheme: basic MyAPIKey: type: apiKey in: header name: X-API-Key security: - MyBasic: [] - MyAPIKey: [] # The rest of the document defines paths, etc. ``` -------------------------------- ### Clean and format data Source: https://docs.gptscript.ai/examples/local-files Example interaction where the assistant reads a text file and converts it into a structured CSV format. ```text > whats in the key contacts file? The key_contacts.txt file contains the following information: Contains location, name & email Scranton - Michael michael@gptscript-fakeco.com Stamford Martin marty@gptscript-fakeco.com Nashua - Rachael, rach@gptscript-fakeco.com Utica,Ross - ross@gptscript-fakeco.com Albany Allen allen@gptscript-fakeco.com Akron;Pam;pam@gptscript-fakeco.com Camden. Kali. kali@gptscript-fakeco.com Yonkers - Meredith - meredith@gptscript-fakeco.com Rochester Kevin Syracuse William will@gptscript-fakeco.com Is there anything specific you would like to do with this information? > That looks bad. Can you make a cleaned up csv of it? Sure, I'll clean up the data and create a CSV file for you. Here's the cleaned-up data in CSV format: Location,Name,Email Scranton,Michael,michael@gptscript-fakeco.com Stamford,Martin,marty@gptscript-fakeco.com Nashua,Rachael,rach@gptscript-fakeco.com Utica,Ross,ross@gptscript-fakeco.com Albany,Allen,allen@gptscript-fakeco.com Akron,Pam,pam@gptscript-fakeco.com Camden,Kali,kali@gptscript-fakeco.com Yonkers,Meredith,meredith@gptscript-fakeco.com Rochester,Kevin, Syracuse,William,will@gptscript-fakeco.com I will now create a CSV file with this cleaned-up data. ``` -------------------------------- ### Example Output from Filtered Tool Source: https://docs.gptscript.ai/tools/input-output-filters The resulting text after the output filter has processed the poem. ```text OUTPUT: In orchards where the sunlight gleams, Among the leaves, in golden beams, The oranges hang on branches high, A feast for both the heart and eye. Their skins, a palette rich and bright, In hues of red and green delight, With every bite, a crisp surprise, A taste of autumn, pure and wise. From pies to cider, sweet and bold, Their stories through the seasons told, In every crunch, a memory, Of nature's gift, so wild and free. Oh, oranges, treasures of the earth, In every form, you bring us mirth, A simple fruit, yet so profound, In you, a world of joy is found. ``` -------------------------------- ### Cross-reference data files Source: https://docs.gptscript.ai/examples/local-files Example interaction where the assistant retrieves specific sales data from an Excel file based on a location identified in previous steps. ```text > what were sales like for Kevin's location? To find out sales for Kevin's location, I will need to check the yoy_sales.xlsx file for any relevant data. Let me take a look at the contents of that file. ... The sales data for Rochester, where Kevin is located, is as follows: LOCATION │ PRODUCT SKU │ MARCH 2023 SALES │ MARCH 2024 SALES │ YOY SALES GROWTH (%) ────────────┼─────────────┼──────────────────┼──────────────────┼─────────────────────── Rochester │ SKU_001 │ $803.91 │ $843.10 │ 12.12% Rochester │ SKU_002 │ $3,013.36 │ $3,159.02 │ 13.13% Rochester │ SKU_003 │ $1,879.24 │ $1,968.20 │ 12.15% Rochester │ SKU_004 │ $4,989.81 │ $5,239.30 │ 13.88% Rochester │ SKU_005 │ $4,334.03 │ $4,550.73 │ 12.70% Rochester │ SKU_006 │ $2,143.76 │ $2,251.95 │ 13.07% Rochester │ SKU_007 │ $7,976.54 │ $8,375.37 │ 12.23% Rochester │ SKU_008 │ $313.21 │ $328.87 │ 13.80% Rochester │ SKU_009 │ $671.70 │ $705.29 │ 12.91% Rochester │ SKU_010 │ $4,084.94 │ $4,289.19 │ 13.03% Is there anything else you would like to know or do with this data? ``` -------------------------------- ### Identify and fix data gaps Source: https://docs.gptscript.ai/examples/local-files Example interaction where the assistant identifies missing information in a CSV and updates it based on user instructions. ```text > is there any missing data in that csv? ... Yes, there is missing data in the CSV file. Specifically, the email for Kevin in Rochester is missing. Would you like to update this information or perform any other actions? > yes set his email to kev@ and use the same domain as the others I will update Kevin's email to kev@gptscript-fakeco.com in the CSV file. ``` -------------------------------- ### Run the workflow demo Source: https://docs.gptscript.ai/examples/workflow Execute the pre-built workflow demo directly from the repository. ```bash gptscript github.com/gptscript-ai/workflow-demo ``` -------------------------------- ### Initialize the script file Source: https://docs.gptscript.ai/examples/workflow Create a new GPTScript file named workflow-demo.gpt to begin development. ```bash vim workflow-demo.gpt ``` -------------------------------- ### Define the entrypoint tool Source: https://docs.gptscript.ai/examples/cli Configure the main agent tool with context references and chat capabilities. ```text Context: learn-gh Context: github.com/gptscript-ai/context/cli Chat: true You have the gh cli available to you. Use it to accomplish the tasks that the user asks of you. ``` -------------------------------- ### Define a context provider with parameters Source: https://docs.gptscript.ai/tools/context Create a context tool that accepts parameters to customize its output. ```bash # context_with_param.gpt Param: tone: the tone to use when responding to the user's request #!/bin/bash echo "Respond to the user's request in a ${tone} tone." ``` -------------------------------- ### Clone Sample Data Repository Source: https://docs.gptscript.ai/examples/local-files Downloads the sample data repository and navigates into the directory. ```bash git clone https://github.com/gptscript-ai/local-files-demo.git cd local-files-demo ``` -------------------------------- ### Initialize the GPTScript file Source: https://docs.gptscript.ai/examples/cli Create a new file to house the GPTScript configuration. ```bash vim cli-demo.gpt ``` -------------------------------- ### Define tool configuration Source: https://docs.gptscript.ai/tools/authoring Create a tool.gpt file to specify metadata, parameters, and the execution command. ```text Description: Returns the contents of a webpage. Param: url: The URL of the webpage. #!/usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/tool.py ``` -------------------------------- ### Go project file structure Source: https://docs.gptscript.ai/tools/code-tool-guidelines Recommended layout for Go tools, requiring a go.mod file. ```text . ├── go.mod ├── go.sum ├── main.go └── tool.gpt ``` -------------------------------- ### List models from a provider Source: https://docs.gptscript.ai/alternative-model-providers Use the --list-models flag with the provider repository URL to see available models. ```bash gptscript --list-models github.com/gptscript-ai/claude3-anthropic-provider ``` -------------------------------- ### Configure Daemon Readiness Path Source: https://docs.gptscript.ai/tools/daemon Syntax for specifying a custom readiness check path for the daemon server. ```text #!sys.daemon (path=/api/ready) node // (node script here) ``` -------------------------------- ### Define the workflow entrypoint Source: https://docs.gptscript.ai/examples/workflow Configure the main tool to import dependencies, enforce sequential processing, and specify target URLs for summarization. ```gptscript Tools: sys.write, summarize-tweet Description: Summarize tweets Always summarize tweets synchronously in the order they appear. Never summarize tweets in parallel. Write all the summaries for the tweets at the following URLs to `tweets.md`: - https://x.com/acornlabs/status/1798063732394000559 - https://x.com/acornlabs/status/1797998244447900084 ``` -------------------------------- ### Using Packaged GitHub Tools Source: https://docs.gptscript.ai/tools/using Demonstrates referencing tools hosted on GitHub using their repository path. ```gptscript tools: github.com/gptscript-ai/dalle-image-generation, github.com/gptscript-ai/gpt4-v-vision, sys.read Generate an image of a city skyline at night and write the resulting image to a file called city_skyline.png. Take this image and write a description of it in the style of pirate. ``` -------------------------------- ### Show credential command syntax Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential_show Basic usage syntax for displaying a stored credential. ```bash gptscript credential show [flags] ``` -------------------------------- ### Show command options Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential_show Available flags for the show command. ```bash -h, --help help for show ``` -------------------------------- ### Utilizing System Tools Source: https://docs.gptscript.ai/tools/using Demonstrates invoking built-in system tools like sys.read and sys.write within a script. ```gptscript tools: sys.read, sys.write Read all of the files in my current directory, do not recurse over any subdirectories, and give me a description of this directory's contents. ``` -------------------------------- ### Define the learn-gh context tool Source: https://docs.gptscript.ai/examples/cli Provide the LLM with CLI help documentation by executing a bash script that outputs command usage information. ```bash --- Name: learn-gh #!/usr/bin/env bash echo "The following is the help text for the gh cli and some of its sub-commands. Use these when figuring out how to construct new commands. Note that the --search flag is used for filtering and sorting as well; there is no dedicated --sort flag." gh --help gh repo --help gh issue --help gh issue list --help gh issue create --help gh issue comment --help gh issue delete --help gh issue edit --help gh pr --help gh pr create --help gh pr checkout --help gh release --help gh release create --help ``` -------------------------------- ### Create Assistant File Source: https://docs.gptscript.ai/examples/local-files Opens a new GPTScript file for editing. ```bash vim data-assistant.gpt ``` -------------------------------- ### Implement a programmatic tool in Python Source: https://docs.gptscript.ai/tools/how-it-works Demonstrates implementing a tool using a Python script instead of a natural language prompt. ```python Tools: bob Ask Bob how he is doing and let me know exactly what he said. --- Name: bob Description: I'm Bob, a friendly guy. Param: question: The question to ask Bob. #!python3 import os print(f"Thanks for asking {os.environ['question']}, I'm doing great fellow friendly AI tool!") ``` -------------------------------- ### Import a shared tool Source: https://docs.gptscript.ai/tools/authoring Use an existing tool from a GitHub repository in your own script. ```text tools: github.com/gptscript-ai/dalle-image-generation Generate an image of a city skyline at night. ``` -------------------------------- ### List models from an OpenAI-compatible API Source: https://docs.gptscript.ai/alternative-model-providers Use the --list-models flag with the API base URL to list available models. ```bash gptscript --list-models https://api.mistral.ai/v1 ``` -------------------------------- ### Define static context text Source: https://docs.gptscript.ai/tools/context Create a text file to serve as a static context provider. ```text # my-context.txt You have access to run commands on the user's system. Please ask for confirmation from the user before running a command. ``` -------------------------------- ### Python project file structure Source: https://docs.gptscript.ai/tools/code-tool-guidelines Recommended layout for Python tools with dependencies. ```text . ├── requirements.txt ├── tool.py └── tool.gpt ``` -------------------------------- ### Node.js project file structure Source: https://docs.gptscript.ai/tools/code-tool-guidelines Recommended layout for Node.js tools with dependencies. ```text . ├── package.json ├── tool.js └── tool.gpt ``` -------------------------------- ### Use the generic credential tool Source: https://docs.gptscript.ai/tools/credential-tools Utilize the built-in generic credential tool to prompt for a single environment variable. ```text Credentials: github.com/gptscript-ai/credential as myCredentialName with MY_ENV_VAR as env and "this message will be displayed to the user" as message and key as field (tool stuff here) ``` -------------------------------- ### Create a credential provider tool Source: https://docs.gptscript.ai/tools/credential-tools A bash-based credential provider that prompts the user for input and outputs the result in the required JSON format. ```bash # my-credential-tool.gpt Name: my-credential-tool #!/usr/bin/env bash output=$(gptscript -q --disable-cache sys.prompt '{"message":"Please enter your fake credential.","fields":"credential","sensitive":"true"}') credential=$(echo $output | jq -r '.credential') echo "{\"env\":{\"MY_ENV_VAR\":\"$credential\"}}" ``` -------------------------------- ### Command Options Source: https://docs.gptscript.ai/command-line-reference/gptscript_getenv Available flags for the getenv command. ```bash -h, --help help for getenv ``` -------------------------------- ### Usage Syntax Source: https://docs.gptscript.ai/command-line-reference/gptscript_getenv Basic command structure for retrieving an environment variable. ```bash gptscript getenv [flags] KEY [DEFAULT] ``` -------------------------------- ### Command options Source: https://docs.gptscript.ai/command-line-reference/gptscript_fmt Available flags for the fmt command. ```bash -h, --help help for fmt -w, --write Write output to file instead of stdout ($GPTSCRIPT_FMT_WRITE) ``` -------------------------------- ### Run Local Files Demo Source: https://docs.gptscript.ai/examples/local-files Executes the local-files-demo script with the specified workspace directory. ```bash gptscript --workspace=~/Documents github.com/gptscript-ai/local-files-demo ``` -------------------------------- ### Define tool dependencies Source: https://docs.gptscript.ai/tools/authoring List required Python packages in a requirements.txt file. ```text requests ``` -------------------------------- ### List credentials with stacked contexts Source: https://docs.gptscript.ai/tools/credential-tools Displays credentials from multiple contexts, showing only the highest priority version if names collide. ```bash gptscript --credential-context one,two credentials ``` -------------------------------- ### Basic gptscript fmt usage Source: https://docs.gptscript.ai/command-line-reference/gptscript_fmt The standard syntax for invoking the format command. ```bash gptscript fmt [flags] ``` -------------------------------- ### Run script with stacked credential contexts Source: https://docs.gptscript.ai/tools/credential-tools Specifies two contexts where the first context has higher priority for credential resolution and storage. ```bash gptscript --credential-context one,two my-script.gpt ``` -------------------------------- ### Execute a tool from the command line Source: https://docs.gptscript.ai/tools/authoring Run a tool directly using the gptscript CLI with parameters provided as a JSON string. ```bash gptscript github.com// '{"url": "https://github.com"}' ``` -------------------------------- ### Define a context provider tool with exported tools Source: https://docs.gptscript.ai/tools/context Create a GPTScript tool that exports tools and provides dynamic context output. ```gptscript # my-context-tool.gpt Share Tools: sys.exec #!sys.echo You have access to run commands on the user's system. Please ask for confirmation from the user before running a command. ``` -------------------------------- ### Execute script with parameters Source: https://docs.gptscript.ai/tools/context Run a GPTScript file and provide parameter values via JSON. ```bash gptscript tool.gpt '{"tone": "obnoxious"}' ``` -------------------------------- ### Run GPTScript with a workspace Source: https://docs.gptscript.ai/examples/local-files Execute the assistant by specifying a local directory as the workspace. ```bash gptscript --workspace=./sample-data data-assistant.gpt ``` -------------------------------- ### Use a context provider tool Source: https://docs.gptscript.ai/tools/context Reference a GPTScript context tool in a script. ```gptscript Context: ./my-context-tool.gpt Tools: sys.write Which processes on my system are using the most memory? Write their PIDs to a file called pids.txt. ``` -------------------------------- ### Inherited parent command options Source: https://docs.gptscript.ai/command-line-reference/gptscript_fmt Global configuration options inherited from the parent gptscript command. ```bash --cache-dir string Directory to store cache (default: $XDG_CACHE_HOME/gptscript) ($GPTSCRIPT_CACHE_DIR) -C, --chdir string Change current working directory ($GPTSCRIPT_CHDIR) --color Use color in output (default true) ($GPTSCRIPT_COLOR) --config string Path to GPTScript config file ($GPTSCRIPT_CONFIG) --confirm Prompt before running potentially dangerous commands ($GPTSCRIPT_CONFIRM) --credential-context strings Context name(s) in which to store credentials ($GPTSCRIPT_CREDENTIAL_CONTEXT) --credential-override strings Credentials to override (ex: --credential-override github.com/example/cred-tool:API_TOKEN=1234) ($GPTSCRIPT_CREDENTIAL_OVERRIDE) --debug Enable debug logging ($GPTSCRIPT_DEBUG) --debug-messages Enable logging of chat completion calls ($GPTSCRIPT_DEBUG_MESSAGES) --default-model string Default LLM model to use ($GPTSCRIPT_DEFAULT_MODEL) (default "gpt-4o") --default-model-provider string Default LLM model provider to use, this will override OpenAI settings ($GPTSCRIPT_DEFAULT_MODEL_PROVIDER) --disable-cache Disable caching of LLM API responses ($GPTSCRIPT_DISABLE_CACHE) --dump-state string Dump the internal execution state to a file ($GPTSCRIPT_DUMP_STATE) --events-stream-to string Stream events to this location, could be a file descriptor/handle (e.g. fd://2), filename, or named pipe (e.g. \\.\pipe\my-pipe) ($GPTSCRIPT_EVENTS_STREAM_TO) -f, --input string Read input from a file ("-" for stdin) ($GPTSCRIPT_INPUT_FILE) --no-trunc Do not truncate long log messages ($GPTSCRIPT_NO_TRUNC) --openai-api-key string OpenAI API KEY ($OPENAI_API_KEY) --openai-base-url string OpenAI base URL ($OPENAI_BASE_URL) --openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID) -o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT) -q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET) --system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR) --workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE) ``` -------------------------------- ### Execute the chatbot script Source: https://docs.gptscript.ai/examples/api Run the configured GPTScript file to initiate the interactive chat session. ```bash gptscript tool.gpt ``` -------------------------------- ### List stored credentials command Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential Basic syntax for listing credentials using the gptscript CLI. ```bash gptscript credential [flags] ``` -------------------------------- ### Define DigitalOcean Bot tool Source: https://docs.gptscript.ai/examples/api Create a tool.gpt file to configure the chatbot with specific API tools and behavioral instructions. ```text Name: DigitalOcean Bot Chat: true Tools: droplets* from openapi.yaml Tools: databases* from openapi.yaml Tools: images* from openapi.yaml Tools: regions_list from openapi.yaml Tools: tags* from openapi.yaml Tools: sizes_list from openapi.yaml Tools: sshKeys_list from openapi.yaml Tools: sys.time.now You are a helpful assistant with access to the DigitalOcean API to manage droplets and databases. Before creating, updating, or deleting anything, tell the user about the exact action you are going to take, and get their confirmation. Start the conversation by asking the user how you can help. ``` -------------------------------- ### Create a Python tool script Source: https://docs.gptscript.ai/tools/authoring Define the logic for a tool in a Python file that reads environment variables. ```python import os import requests print(requests.get(os.getenv("url")).text) ``` -------------------------------- ### Define Credential Tool Parameters Source: https://docs.gptscript.ai/tools/credential-tools Defines a credential tool with specific parameters and a bash script to output the resulting environment variables. ```bash Name: my-credential-tool Parameter: env: the environment variable to set Parameter: val: the value to set it to #!/usr/bin/env bash echo "{\"env\":{\"$ENV\":\"$VAL\"}}" ``` -------------------------------- ### Execute the GPTScript Source: https://docs.gptscript.ai/examples/cli Run the defined script using the gptscript CLI. ```bash gptscript cli-demo.gpt ``` -------------------------------- ### Specify multiple credential tools Source: https://docs.gptscript.ai/tools/credential-tools Use multiple Credentials directives on separate lines to load multiple credential providers. ```text Credentials: credential-tool-1.gpt Credentials: credential-tool-2.gpt (tool stuff here) ``` -------------------------------- ### Define GPTScript tools Source: https://docs.gptscript.ai/tools/how-it-works Defines an entrypoint tool that calls a secondary tool named 'bob' using natural language prompts. ```gptscript Tools: bob Ask Bob how he is doing and let me know exactly what he said. --- Name: bob Description: I'm Bob, a friendly guy. Param: question: The question to ask Bob. When asked how I am doing, respond with "Thanks for asking "${question}", I'm doing great fellow friendly AI tool!" ``` -------------------------------- ### Call an external Go program Source: https://docs.gptscript.ai/tools/code-tool-guidelines Go tools must use the specific path format shown for the tool body. ```text Name: my-go-tool #!${GPTSCRIPT_TOOL_DIR}/bin/gptscript-go-tool ``` -------------------------------- ### Reference Credential Tool with Parameters Source: https://docs.gptscript.ai/tools/credential-tools Sets specific parameter values when referencing a credential tool in a script. ```text Credential: my-credential-tool.gpt with MY_ENV_VAR as env and "my value" as val (tool stuff here) ``` -------------------------------- ### Show specific credential with stacked contexts Source: https://docs.gptscript.ai/tools/credential-tools Searches for a specific credential across multiple contexts based on priority. ```bash gptscript --credential-context one,two credential show myCred ``` -------------------------------- ### Use a credential provider tool in a script Source: https://docs.gptscript.ai/tools/credential-tools Reference a credential provider tool using the Credentials directive to make environment variables available to the script. ```bash Credentials: my-credential-tool.gpt as myCred #!/usr/bin/env bash echo "The value of MY_ENV_VAR is $MY_ENV_VAR" ``` -------------------------------- ### Credential command options Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential Available flags for the credential command to control output and context scope. ```bash --all-contexts List credentials for all contexts ($GPTSCRIPT_CREDENTIAL_ALL_CONTEXTS) -h, --help help for credential --show-env-vars Show names of environment variables in each credential ($GPTSCRIPT_CREDENTIAL_SHOW_ENV_VARS) ``` -------------------------------- ### Reference workspace context tool Source: https://docs.gptscript.ai/tools/workspace Adds workspace awareness to LLM-based tools by referencing the workspace context. ```text Context: github.com/gptscript-ai/context/workspace ``` -------------------------------- ### Require Multiple Security Schemes Source: https://docs.gptscript.ai/tools/openapi Shows how to define security requirements as a logical AND by grouping them in the same array entry. ```yaml security: - MyBasic: [] MyAPIKey: [] ``` -------------------------------- ### Authenticate with GitHub using the gh CLI Source: https://docs.gptscript.ai/faqs Set the GITHUB_AUTH_TOKEN environment variable using an existing GitHub CLI token to avoid rate limits. ```bash export GITHUB_AUTH_TOKEN="$(gh auth token)" ``` -------------------------------- ### GPTScript Execution Syntax Source: https://docs.gptscript.ai/command-line-reference/gptscript The basic command structure for executing a GPTScript program file. ```bash gptscript [flags] PROGRAM_FILE [INPUT...] ``` -------------------------------- ### Download DigitalOcean OpenAPI definition Source: https://docs.gptscript.ai/examples/api Use curl to fetch the OpenAPI YAML file locally for easier reference in GPTScript. ```bash curl -o openapi.yaml -L https://api-engineering.nyc3.cdn.digitaloceanspaces.com/spec-ci/DigitalOcean-public.v2.yaml ``` -------------------------------- ### Defining In-Script Tools Source: https://docs.gptscript.ai/tools/using Shows how to define a custom tool directly within the main script file for modularity. ```gptscript tools: random-number Select a number at random and, based on the results, write a poem about it. --- name: random-number description: Generate a random number between 1 and 100. Select a number at random between 1 and 100 and return only the number. ``` -------------------------------- ### Execute GPTScript with Daemon Source: https://docs.gptscript.ai/tools/daemon Command to run the script and the expected output from the daemon tool. ```bash gptscript script.gpt '{"first":"hello","second":"world"}' ``` ```text OUTPUT: Body: {"first":"hello","second":"world"} Path: /myPath ``` -------------------------------- ### Credential override via key-value pairs Source: https://docs.gptscript.ai/tools/credential-tools Sets specific environment variables for a credential tool using explicit values. ```text toolA:ENV_VAR_1=value1,ENV_VAR_2=value2 ``` -------------------------------- ### Invoke a tool via GPTScript Source: https://docs.gptscript.ai/tools/authoring Reference a GitHub-hosted tool within a GPTScript file. ```text Tools: github.com// Get the contents of https://github.com ``` -------------------------------- ### Inherited credential options Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential Global flags inherited from parent commands for credential context management. ```bash --credential-context strings Context name(s) in which to store credentials ($GPTSCRIPT_CREDENTIAL_CONTEXT) ``` -------------------------------- ### Reference an OpenAI-compatible API model Source: https://docs.gptscript.ai/alternative-model-providers Specify the model name and the base URL of the OpenAI-compatible API. ```text model: mistral-large-latest from https://api.mistral.ai/v1 Say hello world ``` -------------------------------- ### Execute a GPTScript file Source: https://docs.gptscript.ai/examples/workflow Command to run the defined workflow script. ```bash gpscript workflow-demo.gpt ``` -------------------------------- ### Use context with parameters Source: https://docs.gptscript.ai/tools/context Pass parameters to a context tool within a script. ```gptscript # tool.gpt Context: ./context_with_param.gpt with ${tone} as tone Param: tone: the tone to use when responding to the user's request Tools: sys.http.html2text What are the top stories on Hacker News right now? ``` -------------------------------- ### Define an inline Node.js tool Source: https://docs.gptscript.ai/tools/code-tool-guidelines Use for simple Node.js scripts without external dependencies. ```text Name: my-node-tool #!node console.log('hello world') ``` -------------------------------- ### GPTScript Configuration Flags Source: https://docs.gptscript.ai/command-line-reference/gptscript A comprehensive list of flags used to configure the GPTScript runtime environment, including cache settings, model selection, and debugging options. ```bash --cache-dir string Directory to store cache (default: $XDG_CACHE_HOME/gptscript) ($GPTSCRIPT_CACHE_DIR) --chat-state string The chat state to continue, or null to start a new chat and return the state ($GPTSCRIPT_CHAT_STATE) -C, --chdir string Change current working directory ($GPTSCRIPT_CHDIR) --color Use color in output (default true) ($GPTSCRIPT_COLOR) --config string Path to GPTScript config file ($GPTSCRIPT_CONFIG) --confirm Prompt before running potentially dangerous commands ($GPTSCRIPT_CONFIRM) --credential-context strings Context name(s) in which to store credentials ($GPTSCRIPT_CREDENTIAL_CONTEXT) --credential-override strings Credentials to override (ex: --credential-override github.com/example/cred-tool:API_TOKEN=1234) ($GPTSCRIPT_CREDENTIAL_OVERRIDE) --debug Enable debug logging ($GPTSCRIPT_DEBUG) --debug-messages Enable logging of chat completion calls ($GPTSCRIPT_DEBUG_MESSAGES) --default-model string Default LLM model to use ($GPTSCRIPT_DEFAULT_MODEL) (default "gpt-4o") --default-model-provider string Default LLM model provider to use, this will override OpenAI settings ($GPTSCRIPT_DEFAULT_MODEL_PROVIDER) --disable-cache Disable caching of LLM API responses ($GPTSCRIPT_DISABLE_CACHE) --disable-tui Don't use chat TUI but instead verbose output ($GPTSCRIPT_DISABLE_TUI) --dump-state string Dump the internal execution state to a file ($GPTSCRIPT_DUMP_STATE) --events-stream-to string Stream events to this location, could be a file descriptor/handle (e.g. fd://2), filename, or named pipe (e.g. \\.\pipe\my-pipe) ($GPTSCRIPT_EVENTS_STREAM_TO) --force-chat Force an interactive chat session if even the top level tool is not a chat tool ($GPTSCRIPT_FORCE_CHAT) --force-sequential Force parallel calls to run sequentially ($GPTSCRIPT_FORCE_SEQUENTIAL) --github-enterprise-hostname string The host name for a Github Enterprise instance to enable for remote loading ($GPTSCRIPT_GITHUB_ENTERPRISE_HOSTNAME) -h, --help help for gptscript -f, --input string Read input from a file ("-" for stdin) ($GPTSCRIPT_INPUT_FILE) --list-models List the models available and exit ($GPTSCRIPT_LIST_MODELS) --list-tools List built-in tools and exit ($GPTSCRIPT_LIST_TOOLS) --no-trunc Do not truncate long log messages ($GPTSCRIPT_NO_TRUNC) --openai-api-key string OpenAI API KEY ($OPENAI_API_KEY) --openai-base-url string OpenAI base URL ($OPENAI_BASE_URL) --openai-org-id string OpenAI organization ID ($OPENAI_ORG_ID) -o, --output string Save output to a file, or - for stdout ($GPTSCRIPT_OUTPUT) -q, --quiet No output logging (set --quiet=false to force on even when there is no TTY) ($GPTSCRIPT_QUIET) --save-chat-state-file string A file to save the chat state to so that a conversation can be resumed with --chat-state ($GPTSCRIPT_SAVE_CHAT_STATE_FILE) --sub-tool string Use tool of this name, not the first tool in file ($GPTSCRIPT_SUB_TOOL) --system-tools-dir string Directory that contains system managed tool for which GPTScript will not manage the runtime ($GPTSCRIPT_SYSTEM_TOOLS_DIR) --ui Launch the UI ($GPTSCRIPT_UI) --workspace string Directory to use for the workspace, if specified it will not be deleted on exit ($GPTSCRIPT_WORKSPACE) ``` -------------------------------- ### Execute GPTScript with Input Filters Source: https://docs.gptscript.ai/tools/input-output-filters Command to run the script and verify the filtered output. ```bash gptscript script.gpt '{"message":"apple is great"}' # Then view the output: cat gptscript_output.txt ``` -------------------------------- ### Inherited options Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential_show Options inherited from parent commands for credential context. ```bash --credential-context strings Context name(s) in which to store credentials ($GPTSCRIPT_CREDENTIAL_CONTEXT) ``` -------------------------------- ### Set a custom workspace directory Source: https://docs.gptscript.ai/faqs Override the default temporary workspace directory using the --workspace flag. ```bash gptscript --workspace . my-script.gpt ``` -------------------------------- ### Credential delete options Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential_delete Help flag available for the delete command. ```bash -h, --help help for delete ``` -------------------------------- ### Resolve Server Variables Source: https://docs.gptscript.ai/tools/openapi Demonstrates how GPTScript resolves variables within the server URL definition. ```yaml servers: - url: '{server}/v1' variables: server: default: https://api.example.com ``` -------------------------------- ### Reference a Claude model in a script Source: https://docs.gptscript.ai/alternative-model-providers Use the model directive to specify a provider repository for Claude models. ```text model: claude-3-haiku-20240307 from github.com/gptscript-ai/claude3-anthropic-provider Say hello world ``` -------------------------------- ### Credential override via environment variables Source: https://docs.gptscript.ai/tools/credential-tools Maps existing environment variables to a credential tool. Avoid this if multiple tools share the same variable names. ```text toolA:ENV_VAR_1,ENV_VAR_2 ``` -------------------------------- ### Define Input Filters in GPTScript Source: https://docs.gptscript.ai/tools/input-output-filters Demonstrates chaining input filters to modify a message parameter through multiple tool calls. ```gptscript # File name: script.gpt Param: message: the message from the user Tools: subtool Input Filter: appleToOrange Take the message and give it to the subtool. Then say "Done". --- Name: subtool Param: message: the message from the user Input Filter: orangeToBanana #!python3 import os message = os.getenv("message", "") with open("gptscript_output.txt", "w") as f: f.write(message) --- Name: appleToOrange #!python3 import os def output(input: str): return input.replace("apple", "orange") print(output(os.getenv("INPUT", ""))) --- Name: orangeToBanana #!python3 import os def output(input: str): return input.replace("orange", "banana") print(output(os.getenv("INPUT", ""))) ``` -------------------------------- ### Reference an external Node.js script Source: https://docs.gptscript.ai/tools/code-tool-guidelines Use for complex Node.js tools requiring external dependencies. ```text Name: my-node-tool #!/usr/bin/env node ${GPTSCRIPT_TOOL_DIR}/tool.js ``` -------------------------------- ### Save and resume chat state Source: https://docs.gptscript.ai/faqs Use these commands to persist chat history to a file and resume it in a later session. ```bash gptscript --save-chat-state-file chat-state.json my-script.gpt ``` ```bash gptscript --chat-state chat-state.json my-script.gpt ``` -------------------------------- ### Define an inline Python tool Source: https://docs.gptscript.ai/tools/code-tool-guidelines Use for simple Python scripts without external dependencies. ```text Name: my-python-tool #!python3 print('hello world') ``` -------------------------------- ### Reference an external Python script Source: https://docs.gptscript.ai/tools/code-tool-guidelines Use for complex Python tools requiring external dependencies. ```text Name: my-python-tool #!/usr/bin/env python3 ${GPTSCRIPT_TOOL_DIR}/tool.py ``` -------------------------------- ### Use context in a tool Source: https://docs.gptscript.ai/tools/context Reference a context file within a GPTScript tool definition. ```gptscript Context: ./my-context.txt Tools: sys.exec, sys.write Which processes on my system are using the most memory? Write their PIDs to a file called pids.txt. ``` ```gptscript Context: ./my-context.txt Tools: sys.exec Which file in my current directory is the largest? ``` -------------------------------- ### gptscript parse options Source: https://docs.gptscript.ai/command-line-reference/gptscript_parse Specific flags available for the parse command. ```bash -h, --help help for parse -p, --pretty-print Indent the json output ($GPTSCRIPT_PARSE_PRETTY_PRINT) ``` -------------------------------- ### gptscript parse command usage Source: https://docs.gptscript.ai/command-line-reference/gptscript_parse Basic syntax for invoking the parse command. ```bash gptscript parse [flags] ``` -------------------------------- ### Accessing Credential Expiration in a Tool Source: https://docs.gptscript.ai/tools/credential-tools Demonstrates how to retrieve the nearest credential expiration time using the GPTSCRIPT_CREDENTIAL_EXPIRATION environment variable within a tool. ```python Credential: my-credential-tool.gpt as myCred #!python3 import os print("myCred expires at " + os.getenv("GPTSCRIPT_CREDENTIAL_EXPIRATION", "")) ``` -------------------------------- ### Inspect OpenAPI operation IDs Source: https://docs.gptscript.ai/examples/api Identify available tool names by searching for operationId fields within the downloaded YAML file. ```bash grep operationId openapi.yaml # ... # operationId: domains_delete_record # operationId: droplets_list # operationId: droplets_create # operationId: droplets_destroy_byTag # operationId: droplets_get # operationId: droplets_destroy # operationId: droplets_list_backups # operationId: droplets_list_snapshots # operationId: dropletActions_list # operationId: dropletActions_post # operationId: dropletActions_post_byTag # operationId: dropletActions_get # operationId: droplets_list_kernels # operationId: droplets_list_firewalls # operationId: droplets_list_neighbors # ... ``` -------------------------------- ### Set workspace directory via CLI Source: https://docs.gptscript.ai/tools/workspace Configures the current directory as the workspace for a GPTScript execution. ```bash gptscript --workspace . my-script.gpt ``` -------------------------------- ### Set Credential Context via CLI Source: https://docs.gptscript.ai/tools/credential-tools Uses the --credential-context flag to specify a namespace for stored credentials during script execution. ```bash gptscript --credential-context my-azure-workspace my-azure-script.gpt ``` -------------------------------- ### Define a GPTScript workflow Source: https://docs.gptscript.ai/examples/workflow A complete GPTScript file defining the main task and supporting tools for tweet summarization. ```gptscript Description: Summarize tweets Tools: sys.write, summarize-tweet Always summarize tweets synchronously in the order they appear. Never summarize tweets in parallel. Write all the summaries for the tweets at the following URLs to `tweets.md`: - https://x.com/acornlabs/status/1798063732394000559 - https://x.com/acornlabs/status/1797998244447900084 --- Name: summarize-tweet Description: Returns a brief summary of a tweet in markdown Tools: get-hyperlinks, summarize-hyperlink, github.com/gptscript-ai/browser Parameters: url: Absolute URL of the tweet to summarize Return a markdown formatted summary of the tweet at ${url} using the following format: ## [](${url}) Short summary of the tweet. ### References --- Name: get-hyperlinks Description: Returns the list of hyperlinks in a given text Parameters: text: Text to extract hyperlinks from Return the list of hyperlinks found in ${text}. If ${text} contains no hyperlinks, return an empty list. --- Name: summarize-hyperlink Description: Returns a summary of the page at a given hyperlink URL Tools: github.com/gptscript-ai/browser Parameters: url: HTTPS URL of a page to summarize Briefly summarize the page at ${url}. ``` -------------------------------- ### Delete credential command syntax Source: https://docs.gptscript.ai/command-line-reference/gptscript_credential_delete Basic usage pattern for deleting a credential by name. ```bash gptscript credential delete [flags] ``` -------------------------------- ### Define hyperlink processing tools Source: https://docs.gptscript.ai/examples/workflow Defines helper tools for extracting hyperlinks from text and summarizing the content found at those URLs. ```yaml --- Name: get-hyperlinks Description: Returns the list of hyperlinks in a given text Parameters: text: Text to extract hyperlinks from Return the list of hyperlinks found in ${text}. If ${text} contains no hyperlinks, return an empty list. --- Name: summarize-hyperlink Description: Returns a summary of the page at a given hyperlink URL Tools: github.com/gptscript-ai/browser Parameters: url: HTTPS URL of a page to summarize Briefly summarize the page at ${url}. ``` -------------------------------- ### Define Data Processing Assistant Source: https://docs.gptscript.ai/examples/local-files The configuration for the data processing assistant, including tools and workspace context. ```gptscript Name: Data Processing Assitant Description: An assistant to help you with processing data found in files on your workstation. Helpful for querying spreadsheets, CSVs, JSON files, and PDFs. Tools: github.com/gptscript-ai/structured-data-querier, github.com/gptscript-ai/pdf-reader Context: github.com/gptscript-ai/context/workspace Chat: true You are a helpful data processing assistant. Your goal is to help the user with data processing. Help the user accomplish their tasks using the tools you have. When the user starts this chat, say hi, introduce yourself, and ask what you can help with. ``` -------------------------------- ### gptscript getenv Source: https://docs.gptscript.ai/command-line-reference/gptscript_getenv Retrieves the value of an environment variable, optionally providing a default value if the variable is not set. ```APIDOC ## gptscript getenv ### Description Looks up an environment variable for use in GPTScript tools. If the variable is not found, the provided default value is returned. ### Usage `gptscript getenv [flags] KEY [DEFAULT]` ### Parameters - **KEY** (string) - Required - The name of the environment variable to retrieve. - **DEFAULT** (string) - Optional - The value to return if the environment variable is not set. ### Options - **-h, --help** - Displays help information for the getenv command. ``` -------------------------------- ### gptscript parse Source: https://docs.gptscript.ai/command-line-reference/gptscript_parse Parses a GPTScript file and outputs the result. This command supports flags for formatting the output. ```APIDOC ## gptscript parse ### Description Parses a GPTScript file and returns the parsed structure in JSON format. ### Flags - **-p, --pretty-print** (boolean) - Optional - Indent the JSON output. - **-h, --help** (boolean) - Optional - Display help for the parse command. ```