Skip to content

Commit

Permalink
Fix docs, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Aug 13, 2024
1 parent 410f7d3 commit 684eeec
Show file tree
Hide file tree
Showing 12 changed files with 53 additions and 26 deletions.
4 changes: 2 additions & 2 deletions docs/griptape-framework/data/artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ Each blob has a [name](../../reference/griptape/artifacts/base_artifact.md#gript

## Image

An [ImageArtifact](../../reference/griptape/artifacts/image_artifact.md) is used for passing images back to the LLM. In addition to binary image data, an Image Artifact includes image metadata like MIME type, dimensions, and prompt and model information for images returned by [image generation Drivers](../drivers/image-generation-drivers.md). It inherits from [BlobArtifact](#blobartifact).
An [ImageArtifact](../../reference/griptape/artifacts/image_artifact.md) is used for passing images back to the LLM. In addition to binary image data, an Image Artifact includes image metadata like MIME type, dimensions, and prompt and model information for images returned by [image generation Drivers](../drivers/image-generation-drivers.md). It inherits from [BlobArtifact](#blob).

## Audio

An [AudioArtifact](../../reference/griptape/artifacts/audio_artifact.md) allows the Framework to interact with audio content. An Audio Artifact includes binary audio content as well as metadata like format, duration, and prompt and model information for audio returned generative models. It inherits from [BlobArtifact](#blobartifact).
An [AudioArtifact](../../reference/griptape/artifacts/audio_artifact.md) allows the Framework to interact with audio content. An Audio Artifact includes binary audio content as well as metadata like format, duration, and prompt and model information for audio returned generative models. It inherits from [BlobArtifact](#blob).

## Boolean

Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/data/loaders.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Inherits from the [TextLoader](../../reference/griptape/loaders/text_loader.md)
!!! info
This driver requires the `loaders-image` [extra](../index.md#extras).

The Image Loader is used to load an image as an [ImageArtifact](./artifacts.md#imageartifact). The Loader operates on image bytes that can be sourced from files on disk, downloaded images, or images in memory.
The Image Loader is used to load an image as an [ImageArtifact](./artifacts.md#image). The Loader operates on image bytes that can be sourced from files on disk, downloaded images, or images in memory.

```python
--8<-- "docs/griptape-framework/data/src/loaders_7.py"
Expand Down Expand Up @@ -104,7 +104,7 @@ Can be used to load email from an imap server:
!!! info
This driver requires the `loaders-audio` [extra](../index.md#extras).

The [Audio Loader](../../reference/griptape/loaders/audio_loader.md) is used to load audio content as an [AudioArtifact](./artifacts.md#audioartifact). The Loader operates on audio bytes that can be sourced from files on disk, downloaded audio, or audio in memory.
The [Audio Loader](../../reference/griptape/loaders/audio_loader.md) is used to load audio content as an [AudioArtifact](./artifacts.md#audio). The Loader operates on audio bytes that can be sourced from files on disk, downloaded audio, or audio in memory.

The Loader will load audio in its native format and populates the resulting Artifact's `format` field by making a best-effort guess of the underlying audio format using the `filetype` package.

Expand Down
8 changes: 4 additions & 4 deletions docs/griptape-framework/structures/task-memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ This is an example of [not providing a Task Memory compatible Tool](#not-providi

## Prompt Summary Client

The [PromptSummaryTool](../../griptape-tools/official-tools/prompt-summary-client.md) is a Tool that allows an Agent to summarize the Artifacts in Task Memory. It has the following methods:
The [PromptSummaryTool](../../griptape-tools/official-tools/prompt-summary-tool.md) is a Tool that allows an Agent to summarize the Artifacts in Task Memory. It has the following methods:

Let's add `PromptSummaryTool` to the Agent and run the same task.
Note that on the `PromptSummaryTool` we've set `off_prompt` to `False` so that the results of the query can be returned directly to the LLM.
Expand Down Expand Up @@ -273,9 +273,9 @@ As seen in the previous example, certain Tools are designed to read directly fro

Today, these include:

- [PromptSummaryTool](../../griptape-tools/official-tools/prompt-summary-client.md)
- [ExtractionTool](../../griptape-tools/official-tools/extraction-client.md)
- [RagClient](../../griptape-tools/official-tools/rag-client.md)
- [PromptSummaryTool](../../griptape-tools/official-tools/prompt-summary-tool.md)
- [ExtractionTool](../../griptape-tools/official-tools/extraction-tool.md)
- [RagClient](../../griptape-tools/official-tools/rag-tool.md)
- [FileManagerTool](../../griptape-tools/official-tools/file-manager.md)

## Task Memory Considerations
Expand Down
4 changes: 2 additions & 2 deletions docs/griptape-framework/structures/tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ This task takes a python function, and authors can elect to return a custom arti

To generate an image, use one of the following [Image Generation Tasks](../../reference/griptape/tasks/index.md). All Image Generation Tasks accept an [Image Generation Engine](../engines/image-generation-engines.md) configured to use an [Image Generation Driver](../drivers/image-generation-drivers.md).

All successful Image Generation Tasks will always output an [Image Artifact](../data/artifacts.md#imageartifact). Each task can be configured to additionally write the generated image to disk by providing either the `output_file` or `output_dir` field. The `output_file` field supports file names in the current directory (`my_image.png`), relative directory prefixes (`images/my_image.png`), or absolute paths (`/usr/var/my_image.png`). By setting `output_dir`, the task will generate a file name and place the image in the requested directory.
All successful Image Generation Tasks will always output an [Image Artifact](../data/artifacts.md#image). Each task can be configured to additionally write the generated image to disk by providing either the `output_file` or `output_dir` field. The `output_file` field supports file names in the current directory (`my_image.png`), relative directory prefixes (`images/my_image.png`), or absolute paths (`/usr/var/my_image.png`). By setting `output_dir`, the task will generate a file name and place the image in the requested directory.

### Prompt Image Generation Task

Expand Down Expand Up @@ -342,7 +342,7 @@ The [Outpainting Image Generation Task](../../reference/griptape/tasks/outpainti

The [Image Query Task](../../reference/griptape/tasks/image_query_task.md) performs a natural language query on one or more input images. This Task uses an [Image Query Engine](../engines/image-query-engines.md) configured with an [Image Query Driver](../drivers/image-query-drivers.md) to perform the query. The functionality provided by this Task depend on the capabilities of the model provided by the Driver.

This Task accepts two inputs: a query (represented by either a string or a [Text Artifact](../data/artifacts.md#textartifact)) and a list of [Image Artifacts](../data/artifacts.md#imageartifact) or a Callable returning these two values.
This Task accepts two inputs: a query (represented by either a string or a [Text Artifact](../data/artifacts.md#textartifact)) and a list of [Image Artifacts](../data/artifacts.md#image) or a Callable returning these two values.

```python
--8<-- "docs/griptape-framework/structures/src/tasks_15.py"
Expand Down
2 changes: 1 addition & 1 deletion docs/griptape-framework/structures/workflows.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ search:

A [Workflow](../../reference/griptape/structures/workflow.md) is a non-sequential DAG that can be used for complex concurrent scenarios with tasks having multiple inputs.

You can access the final output of the Workflow by using the [output](../../reference/griptape/structures/agent.md#griptape.structures.structure.Structure.output) attribute.
You can access the final output of the Workflow by using the [output](../../reference/griptape/structures/structure.md#griptape.structures.structure.Structure.output) attribute.

## Context

Expand Down
6 changes: 2 additions & 4 deletions docs/griptape-tools/official-tools/extraction-client.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
The [RagClient](../../reference/griptape/tools/rag_client/tool.md) enables LLMs to query modular RAG engines.

Here is an example of how it can be used with a local vector store driver:
The [ExractionTool](../../reference/griptape/tools/extraction/tool.md) enables LLMs to extract structured data from unstructured data.

```python
--8<-- "docs/griptape-tools/official-tools/src/rag_client_1.py"
--8<-- "docs/griptape-tools/official-tools/src/rag_tool_1.py"
```
```
[08/12/24 15:58:03] INFO ToolkitTask 43b3d209a83c470d8371b7ef4af175b4
Expand Down
4 changes: 1 addition & 3 deletions docs/griptape-tools/official-tools/prompt-summary-client.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
The [RagClient](../../reference/griptape/tools/rag_client/tool.md) enables LLMs to query modular RAG engines.

Here is an example of how it can be used with a local vector store driver:
The [PromptSummaryTool](../../reference/griptape/tools/prompt_summary/tool.md) enables LLMs summarize text data.

```python
--8<-- "docs/griptape-tools/official-tools/src/prompt_summary_tool_1.py"
Expand Down
10 changes: 5 additions & 5 deletions griptape/tools/query/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ class QueryTool(BaseTool, RuleMixin):
)
def query(self, params: dict) -> BaseArtifact:
query = params["values"]["query"]
summary = params["values"]["content"]
content = params["values"]["content"]

if isinstance(summary, str):
text_artifacts = [TextArtifact(summary)]
if isinstance(content, str):
text_artifacts = [TextArtifact(content)]
else:
memory = self.find_input_memory(summary["memory_name"])
artifact_namespace = summary["artifact_namespace"]
memory = self.find_input_memory(content["memory_name"])
artifact_namespace = content["artifact_namespace"]

if memory is not None:
artifacts = memory.load_artifacts(artifact_namespace)
Expand Down
6 changes: 3 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ nav:
- Audio Transcription: "griptape-tools/official-tools/audio-transcription-tool.md"
- Griptape Cloud Knowledge Base: "griptape-tools/official-tools/griptape-cloud-knowledge-base-tool.md"
- Rag: "griptape-tools/official-tools/rag-tool.md"
- Extraction: "griptape-tools/official-tools/extraction-client.md"
- Query: "griptape-tools/official-tools/query-client.md"
- Prompt Summary: "griptape-tools/official-tools/prompt-summary-client.md"
- Extraction: "griptape-tools/official-tools/extraction-tool.md"
- Query: "griptape-tools/official-tools/query-tool.md"
- Prompt Summary: "griptape-tools/official-tools/prompt-summary-tool.md"
- Custom Tools:
- Building Custom Tools: "griptape-tools/custom-tools/index.md"
- Recipes:
Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions tests/unit/tools/test_query_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest

from griptape.tools.query.tool import QueryTool
from tests.utils import defaults


class TestQueryTool:
@pytest.fixture()
def tool(self):
return QueryTool(input_memory=[defaults.text_task_memory("TestMemory")])

def test_query_str(self, tool):
assert tool.query({"values": {"query": "test", "content": "foo"}}).value[0].value == "mock output"

def test_query_artifacts(self, tool):
assert (
tool.query(
{
"values": {
"query": "test",
"content": {
"memory_name": tool.input_memory[0].name,
"artifact_namespace": "test",
},
}
}
)
.value[0]
.value
== "mock output"
)

0 comments on commit 684eeec

Please sign in to comment.