CLI for the Griptape Framework and Cloud
Project description
Griptape Cloud CLI
The Griptape CLI is a command-line interface for interacting with features of Griptape Cloud. Today, it provides an emulator for Griptape Cloud Managed Structures, which allows you to run and test your Managed Structures locally.
Prerequisites
- A GitHub account.
- Python 3.11.
- Poetry for running the example client program.
- Linux operating system functionality. For Windows users, Griptape recommends the Windows Subsystem for Linux (WSL) for this functionality.
Installation
-
Install griptape-cli
pipx install griptape-cli
You can also install a pre-release version from GitHub.
git clone https://github.com/griptape-ai/griptape-cli.git
pipx install ./griptape-cli --force
-
Verify installation
gt --help
Skatepark Emulator
You can use the CLI to spin up Skatepark, a local emulator for Griptape Cloud Managed Structures. It exposes an API that is identical to the one you would interact with when running your Managed Structure in Griptape Cloud. Use Skatepark to develop, test, and validate that your program will operate as expected when deployed as a Griptape Cloud Managed Structure. Skatepark gives you confidence that when you bring your Structure into Griptape Cloud as a Managed Structure, it will continue to operate as expected, at scale.
-
Start by creating a new repository in your own Github account from the Managed Structure Template.
- Make sure you're logged in to GitHub.
- Go to the Managed Structure Template repo.
- Select the Use this template drop-down.
- Choose Create a new repository.
- Provide a name for the new repository and (optionally) a description.
- Press the Create repository button.
- You now have a repository in your own GitHub account that is a copy of the Managed Structure Template for you to begin working with.
-
Clone your newly-created repository to a directory in your local development environment so that you can begin authoring your own Griptape Cloud Managed Structure.
-
Start Skatepark.
gt skatepark start
-
Open a new terminal window. Navigate to the directory with the locally-cloned repository.
-
Register a Structure with Skatepark.
gt skatepark register --structure-config-file structure_config.yaml
This will result in the ID of the registered Structure. It is important to make note of this ID as it will be used to distinguish which Structure you want to run. You can register any number of Structures.
The example client program uses the environment variable
GT_STRUCTURE_ID
to determine which Structure to run. Set this environment variable to the Structure ID you registered in the previous step.export GT_STRUCTURE_ID={STRUCTURE_ID}
Or you can register and set the environment variable in one step.
export GT_STRUCTURE_ID=$(gt skatepark register --structure-config-file structure_config.yaml --tldr)
[!IMPORTANT] Structures registered with the Skatepark are not persisted across restarts. You will need to re-register the Structure each time you restart Skatepark.
-
Confirm that the Structure is registered.
gt skatepark list
You should see a list of registered Structures and the directories they point to, confirming that your Structure was properly registered
-
You can load environment variables into your Structure by creating an
.env
file in the directory of the Structure you registered.- Create a file named
.env
in the same directory that your Structure code is in. - Open the
.env
file in a text editor. - Copy the contents of
.env.structure.example
into the.env
file. This specifies all of the values necessary and explains how they are used. - The template expects an
OPENAI_API_KEY
environment variable by default to function. Add OPENAIAPI_KEY=_your OpenAI API Key here to the.env
file and save it. - As you expand on the template, you may add any other environment variables your Structure depends on to this file.
- Create a file named
-
Rebuild the structure to load in the new environment variable. Note that this is only required for changes to
.env
orrequirements.txt
. Code changes do not require a rebuild.gt skatepark build
-
Now that your Structure is registered and built, we want to be able to call it from within another program. The managed structure template offers an example client that can invoke your Structure. You have to configure the client with details on where to find the Structure in order for it to be called.
- Create a file named
.env
in theexample-client
directory. - Open the
.env
file in a text editor - Copy the contents of
.env.client.example
(located within theexample-client/
directory) into the.env
file. This specifies all of the values necessary and explains how they are used. - The client needs to know where the Structure is hosted, as specified in the
GT_CLOUD_BASE_URL
environment variable. When testing against the Skatepark emulator, we will use the default value address that Skatepark is running on. SetGT_CLOUD_BASE_URL=http://127.0.0.1:5000
. - The client needs to know which Structure it is attempting to invoke, as specified in the
GT_STRUCTURE_ID
environment variable. This is the same value you got when you registered the Structure with Skatepark in step 5. You can quickly get this value by typinggt skatepark list
to see the list of all registered Structures. Copy this value into GTSTRUCTURE_ID=_your Skatepark Structure ID here. - Save the
.env
file.
- Create a file named
-
The example client is configured, now you can use it to call Skatepark's API for running the Structure.
Navigate to the
example-client
directory.cd example-client
Install the dependencies required by the example client program.
poetry install --no-root
Run the example client program.
poetry run python client.py
You should see the result of the Structure answering
What is 123 * 34, 23 / 12.3, and 9 ^ 4
, indicating a successful run.
[!IMPORTANT] The client program is an example for how to interact with the Managed Structure's API. It is useful for testing your Managed Structure locally, but ultimately you will want to integrate your Managed Structure with your own application.
Simulating Structure Run Delay
By default, Skatepark adds a 2 second delay before transitioniong Structure Runs from the QUEUED
state to the RUNNING
state.
If you want to change this delay in order to test the behavior of your Structure when it is in the QUEUED
state, you can do so by setting the GT_SKATEPARK_QUEUE_DELAY
environment variable.
For example, a value of GT_SKATEPARK_QUEUE_DELAY=5
will cause Skatepark to wait 5 seconds before transitioning the Structure Run from QUEUED
to RUNNING
. Setting a value of GT_SKATEPARK_QUEUE_DELAY=0
will cause Skatepark to transition the Structure Run immediately.
Note that this environment variable must be set in the terminal where the Skatepark server is running, not in the terminal where the client program is run.
Documentation
Please refer to Griptape Docs
Development
poetry install
poetry run gt
Tests
poetry run pytest
Contributing
Thank you for considering contributing to Griptape! Before you start, please read the following guidelines.
Submitting Issues
If you have identified a bug, want to propose a new feature, or have a question, please submit an issue through our public issue tracker. Before submitting a new issue, please check the existing issues to ensure it hasn't been reported or discussed before.
Versioning
Griptape CLI is in constant development and its APIs and documentation are subject to change. Until we stabilize the API and release version 1.0.0, we will use minor versions (i.e., x.Y.z) to introduce features and breaking features, and patch versions (i.e., x.y.Z) for bug fixes.
License
Griptape CLI is available under the Apache 2.0 License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file griptape_cli-0.6.0.tar.gz
.
File metadata
- Download URL: griptape_cli-0.6.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.6 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a605d8ee561c196015e16d6fbacea0ab37253865734c8dcfe9dc60b81f2c716 |
|
MD5 | 2b9e8e48026cad3fa93389ba1e184284 |
|
BLAKE2b-256 | 658719c0ea49021c44cba95b87f95baecbcc3a968abd2b7ba8946ed77d31a415 |
File details
Details for the file griptape_cli-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: griptape_cli-0.6.0-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.11.6 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16258e59ee09e2b22449fb0c311d70b756d2e59f9af8efd06b2deaaf898d92c1 |
|
MD5 | 842e4191e8db55f5c08818358e0ad8ce |
|
BLAKE2b-256 | 6f986cf0c9cb4508ff946ad969d240a1e349ad235729c95128a7700f7234cb55 |