Blog

Chat with your Scripts in GPTScript v0.6

May 14, 2024 by craig jellick

We’re excited to bring your release v0.6 of GPTScript. This release has several exciting features that we’re ready to dive into. So please, read on!

Chat with your scripts

First and foremost, we’re introducing the ability to chat with your GPTScripts. This deceptively simple feature brings together the ease-of-use of chat interfaces and the power of GPTScript’s tool execution. As an example, here’s a "chattable" tool for interacting with the GitHub CLI. This simple 26-line GPTScript gives you the ability to manage your GitHub repos via chat without ever leaving your terminal. Adding the Chat: true instruction is all it takes to turn this tool into a chat interface.

Description: A chatbot to help you with the GitHub CLI
Context: learn-github-cli
Tools: execute-gh-commands, github.com/gptscript-ai/browser
Chat: true

Use the GitHub CLI, gh, to accomplish the user's request. When the user starts this chat, just say hi and ask what you can help with. you dont need to guide them.

---
Name: execute-gh-commands
Description: Executes the supplied gh command
args: command: The gh command to execute, not including `gh` (ie "repo clone kubernetes/kubernets")

#!/usr/bin/env bash

gh ${command} 2>&1 || true

---
Name: learn-github-cli
Tools: sys.exec

#!/bin/bash

gh --help
gh repo --help
gh issue --help
gh pr --help

The GitHub CLI is very powerful, with many advanced features. This GPTScript lets you leverage those features without ever having to learn the CLI. To see a quick three-minute video of this tool in action, click here.

Global Model and Tools

Next, in addition to being able to define Tools and Model Name on a per-tool basis, you can define Global Tools and a Global Model Name. Any tool in your gpt file can have these instructions. Global Tools will be made available to all tools in the file. Global Model Name will be used for all tools in the current file unless a tool explicitly sets it’s own Model Name. This is a nice quality of life feature as it means you don’t have to continually repeat tools in each section of your gptscript. Here’s a quick example:

Description: Your friendly news aggregator
Tools: gamer-news, techie-news
Global Tools: github.com/gptscript-ai/browser

Do these steps in order. Don't do move on the the second until the first is done:
1. Get my curated list of gamer news
2. Get my curated list of techie news

---
Name: gamer-news
Description: Returns a curated list of the most interesting gamer news stories

Browse https://www.reddit.com/r/gaming/ and get the top three news stories

---
Name: techie-news
Description: Returns a curated list of the most interesting techie news

Browse https://news.ycombinator.com/news and get thetop three news storie

In the above example, the gamer-news and techie-news tools have access to the browser tool because it’s defined as a global tool at the top.

GPTScript fmt command

This is another nice little quality-of-life feature. Inspired by go fmt, the gptscript fmt command does something similar: formats your gptscripts! Usage is simple:

$ gptscript fmt -w news-generator.gpt

This will format and rewrite the new-generator.gpt file. If you omit the -w flag, the formatted output will just be sent to stdout.

Workspace Functions

Finally, we’ve introduced the concept of workspaces. This is a bit of an advanced feature, but it’s still worth explaining. A workspace is effectively a scratch directory that tools can use to read and write files without polluting the rest of your filesystem. A workspace will automatically be allocated any time you evoke a GPTscript, but it’s up to the script itself to leverage these new tools. Here they are:

Name: sys.workspace.ls
Description: Lists the contents of a directory relative to the current workspace
Model: gpt-4-turbo
Args: dir: The directory to list

---
Name: sys.workspace.read
Description: Reads the contents of a file relative to the current workspace
Model: gpt-4-turbo
Args: filename: The name of the file to read

---
Name: sys.workspace.write
Description: Write the contents to a file relative to the current workspace
Model: gpt-4-turbo
Args: content: The content to write
Args: filename: The name of the file to write to

When the script is finished, the workspace will be automatically cleaned up. You can override this behavior by adding the –workspace flag to your gptscript invocation. If you do so, the workspace will remain intact.

Wrapping up

That’s it for this overview of the v0.6 release. Try out the chat feature; it’s very fun and powerful. Feel free to check out the release notes for more details and join us on Discord if you have any questions or feedback.

Related Articles