From 684eeece574c3afbd92a3f0d55f748c0990fd7c1 Mon Sep 17 00:00:00 2001 From: Collin Dutter Date: Tue, 13 Aug 2024 16:13:50 -0700 Subject: [PATCH] Fix docs, add tests --- docs/griptape-framework/data/artifacts.md | 4 +-- docs/griptape-framework/data/loaders.md | 4 +-- .../structures/task-memory.md | 8 ++--- docs/griptape-framework/structures/tasks.md | 4 +-- .../structures/workflows.md | 2 +- .../official-tools/extraction-client.md | 6 ++-- .../official-tools/prompt-summary-client.md | 4 +-- griptape/tools/query/tool.py | 10 +++--- mkdocs.yml | 6 ++-- ...tion_client.py => test_extraction_tool.py} | 0 ..._client.py => test_prompt_summary_tool.py} | 0 tests/unit/tools/test_query_tool.py | 31 +++++++++++++++++++ 12 files changed, 53 insertions(+), 26 deletions(-) rename tests/unit/tools/{test_extraction_client.py => test_extraction_tool.py} (100%) rename tests/unit/tools/{test_prompt_summary_client.py => test_prompt_summary_tool.py} (100%) create mode 100644 tests/unit/tools/test_query_tool.py diff --git a/docs/griptape-framework/data/artifacts.md b/docs/griptape-framework/data/artifacts.md index 065e36123..7cff2c21d 100644 --- a/docs/griptape-framework/data/artifacts.md +++ b/docs/griptape-framework/data/artifacts.md @@ -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 diff --git a/docs/griptape-framework/data/loaders.md b/docs/griptape-framework/data/loaders.md index 82d97f494..914fdee2a 100644 --- a/docs/griptape-framework/data/loaders.md +++ b/docs/griptape-framework/data/loaders.md @@ -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" @@ -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. diff --git a/docs/griptape-framework/structures/task-memory.md b/docs/griptape-framework/structures/task-memory.md index 0d479a36b..cc50be322 100644 --- a/docs/griptape-framework/structures/task-memory.md +++ b/docs/griptape-framework/structures/task-memory.md @@ -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. @@ -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 diff --git a/docs/griptape-framework/structures/tasks.md b/docs/griptape-framework/structures/tasks.md index 0cf601220..40dff8f8d 100644 --- a/docs/griptape-framework/structures/tasks.md +++ b/docs/griptape-framework/structures/tasks.md @@ -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 @@ -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" diff --git a/docs/griptape-framework/structures/workflows.md b/docs/griptape-framework/structures/workflows.md index 5f7c271fc..a346639f9 100644 --- a/docs/griptape-framework/structures/workflows.md +++ b/docs/griptape-framework/structures/workflows.md @@ -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 diff --git a/docs/griptape-tools/official-tools/extraction-client.md b/docs/griptape-tools/official-tools/extraction-client.md index d4dc8aa31..9779bfc5b 100644 --- a/docs/griptape-tools/official-tools/extraction-client.md +++ b/docs/griptape-tools/official-tools/extraction-client.md @@ -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 diff --git a/docs/griptape-tools/official-tools/prompt-summary-client.md b/docs/griptape-tools/official-tools/prompt-summary-client.md index 2315114eb..7afecf57b 100644 --- a/docs/griptape-tools/official-tools/prompt-summary-client.md +++ b/docs/griptape-tools/official-tools/prompt-summary-client.md @@ -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" diff --git a/griptape/tools/query/tool.py b/griptape/tools/query/tool.py index 5b4e29c29..3ecc63bca 100644 --- a/griptape/tools/query/tool.py +++ b/griptape/tools/query/tool.py @@ -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) diff --git a/mkdocs.yml b/mkdocs.yml index 68f5c2dfb..da68fb29c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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: diff --git a/tests/unit/tools/test_extraction_client.py b/tests/unit/tools/test_extraction_tool.py similarity index 100% rename from tests/unit/tools/test_extraction_client.py rename to tests/unit/tools/test_extraction_tool.py diff --git a/tests/unit/tools/test_prompt_summary_client.py b/tests/unit/tools/test_prompt_summary_tool.py similarity index 100% rename from tests/unit/tools/test_prompt_summary_client.py rename to tests/unit/tools/test_prompt_summary_tool.py diff --git a/tests/unit/tools/test_query_tool.py b/tests/unit/tools/test_query_tool.py new file mode 100644 index 000000000..dcbee16cf --- /dev/null +++ b/tests/unit/tools/test_query_tool.py @@ -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" + )