New Features in Griptape Framework 1.3

We are excited to announce the release of version 1.3 of the Griptape Framework. The 1.3 release includes a host of new features and adds many capabilities that have been requested by Griptape customers and members of the open source community. Let’s drop in and explore some of the new features added in this release.

Future Changes to the drivers Namespace

First up, we need to let you know that in order to simplify the process for implementing new drivers, and make it easier for community members to contribute new drivers to the Griptape Framework, the griptape.drivers namespace is being deprecated. 

In future, you will need to use provider-specific namespaces such as griptape.drivers.prompt.openai instead. Please update your applications to remove the deprecated namespace to avoid issues with imports in future releases. If you want to learn more about the reasons for this change please check out this discussion over in the Griptape GitHub organization.

Support for OpenAI Reasoning Models

Developers using the Griptape Framework have told us that they are excited and impatient to put the latest models to work in their applications. With the 1.3 release, the Griptape Framework supports o1 and o3 reasoning models from OpenAI. To use these models in your applications, set the model attribute of the OpenAiChatPromptDriver to your desired reasoning model with prompt_driver=OpenAiChatPromptDriver(model="o3-mini") or use the o1/o1-mini options when creating an instance of OpenAiChatPromptDriver.

Support for Audio Input and Output in the OpenAIChatPromptDriver

Support for audio input and output with OpenAI models has been a common request from developers in VFX and videogame studios that are using Griptape. 1.3 includes support for audio with models such as gpt-4o-audio-preview. Using audio within your applications is simple. To use audio: Import the AudioLoader from griptape.loaders, then Set the modalities to audio and text with modalities=["audio", "text"], and the desired audio attributes on your OpenAiChatPromptDriver instance. Check out the code sample below for a complete example. I got some fun results with this one.

Before:

After:

1from griptape.drivers.prompt.openai import OpenAiChatPromptDriver
2from griptape.loaders import AudioLoader
3from griptape.structures import Agent
4
5driver = OpenAiChatPromptDriver(
6   model="gpt-4o-audio-preview",
7   modalities=["audio", "text"],
8   audio={"voice": "sage", "format": "mp3"},
9)
10
11audio_file = AudioLoader().load("sample_files/griptape.mp3")
12agent = Agent(prompt_driver=driver)
13result = agent.run(
14   ["Can you transcribe this audio but give it some flair and humor?", audio_file]
15)
16AudioLoader().save("sample_files/griptape_output.mp3", result.output)

Auto configuration when running Structures in Griptape Cloud

If you’ve looked at the Sample Applications that the team at Griptape have created to show how to use the Griptape Framework together with Griptape Cloud, you might have noticed that some boilerplate code has previously been required to integrate the Structures in those applications with the services in Griptape Cloud, such as the event listener and the observability features.

With the 1.3 release, we are simplifying this with the addition of a new GriptapeCloudStructure utility. This utility will automatically configure the eventbus with the GriptapeCloudEventListenerDriver and makes it simple for you to add observability to your applications that have components running as Structures in Griptape Cloud. For code that you might want to run in Griptape Cloud that isn’t Structures (Griptape Cloud can be used as a general purpose serverless execution environment for Python code), the  GriptapeCloudStructure utility will take care of flushing the EventBus. In addition, setting context.output will automatically set the output that is published when execution completes. 

Note that for a Griptape Framework Structure, such as an Agent, Pipeline, or Workflow, you don't need to set context.output. You can simply run the Structure and the GriptapeCloudStructure class will take care of that for you.

The code sample below shows the syntax that you should use with the new GriptapeCloudStructure utility.

1from griptape.structures import Agent
2from griptape.utils import GriptapeCloudStructure
3
4# `GriptapeCloudStructure` will configure the EventBus with `GriptapeCloudEventListenerDriver`
5with GriptapeCloudStructure():
6   Agent().run("Hello there!")
7
8# `observe=True` will add on Observability. Opt-in since it requires extra dependencies. 
9# This requires the drivers-observability-griptape-cloud extra
10with GriptapeCloudStructure(observe=True):
11   Agent().run("Hello there!")
12
13# For non-Structure code, `GriptapeCloudStructure` will take care of flushing the EventBus.
14# And `context.output` will automatically set the output.
15with GriptapeCloudStructure(observe=True) as context:
16   triple_foo = "foo" * 3
17   context.output = triple_foo

Reduced cost, latency & complexity when reranking RAG results

Reranking is a technique used in retrieval augmentation-generation (RAG) applications to ensure that the results returned from a RAG query are provided in descending order of their relevance to the original query. It can significantly improve the relevance of the initial query results that are presented to the users of RAG applications and is therefore a popular technique among developers building these types of applications. 

In earlier versions of the Griptape Framework prior to 1.3, reranking was provided using Cohere’s Rerank Model. This is a powerful model, but using it required developers to signup for Cohere, generate APIs, and import these into their Griptape Framework applications to use the CohereRerankDriver. The 1.3 release of the Griptape Framework introduces a LocalRerankDriver, which uses a simple relatedness calculation to compare the search query with each of the results returned from the query, and returns a list of artifacts in descending order of their relatedness.

The code sample below shows a simple example of using the LocalRerankDriver. In this example, we provide a list of terms in the form of text artifacts, but in production use this list would be the results from your RAG query.

1from griptape.artifacts import TextArtifact
2from griptape.drivers.rerank.local import LocalRerankDriver
3
4rerank_driver = LocalRerankDriver()
5
6artifacts = rerank_driver.run(
7   "What is the capital of France?",
8   [
9       TextArtifact("Hotdog"),
10       TextArtifact("San Francisco"),
11       TextArtifact("Paris"),
12       TextArtifact("Baguette"),
13       TextArtifact("French Hotdog"),
14   ],
15)
16for artifact in artifacts:
17   print(artifact.value)

I recommend you try this sample, and see how the provided terms rank on their relatedness to the example search query, "What is the capital of France?". The results are interesting. 

Further improvements to Structured Output with support for pydantic.BaseModels

We’ve progressed further in our quest to add robust structured output capabilities in the 1.3 release. This release adds support for the most widely used Python data validation library as a mechanism for defining schemas for structured output. You can now use pydantic.BaseModels anywhere you might previously have used a schema.Schema object. 

With this addition, when using pydantic.BaseModels, Structured Output will return an object which is an instance of the model you created. This means you get all the autocompletion and type hinting capabilities that come with using objects and models. This is a significant improvement over using schema.Schema, which is constrained to creating a dictionary. We recommend that you update your applications to take advantage of pydantic.BaseModels wherever you are using Structured Output.

Improvements to the DateTimeTool

One of the most common shortcomings of LLMs is their lack of awareness about the current state of the world. Their training data ends at a specific point in time and without tools to add capabilities to the models, they can’t answer apparently simple questions such as “What is today’s date?”, or even my favorite question “How many days is it until Christmas?”.

In the 1.3 release, we have improved the Griptape DateTimeTool with additional functionality (adding the DateTimeTool.add_timedelta and DateTimeTool.get_datetime_diff functions) to make it better at providing models with the information that they need to answer questions like this accurately.

‍Other changes & fixes in Griptape 1.3

For a full list of the all the fixes included in the Griptape 1.3 release, please head over to the CHANGELOG for the Griptape Framework at https://github.com/griptape-ai/griptape/blob/main/CHANGELOG.md

‍How to get started

Griptape Framework 1.3 is available on PyPi now and you can download it with pip, poetry, or another Python package manager of your choice. As always, we would love to hear your feedback on the changes and new features. If you want to ask any questions about the other features in this release or learn more about structured output, please head over to the Griptape Discord.