Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter committed Aug 12, 2024
2 parents f77d8e8 + 43f25d3 commit 688bc98
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 84 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING**: Moved ruleset and metadata ingestion from standalone modules to `PromptResponseRagModule`.
- `BaseTask.add_parent/child` will now call `self.structure.add_task` if possible.

## [0.29.1] - 2024-08-02

### Changed
- Remove `BaseTextArtifact`, revert `CsvRowArtifact` to subclass `TextArtifact`.

### Fixed
- Missing extra for `drivers-text-to-speech-elevenlabs`.

## [0.29.0] - 2024-07-30

### Added
Expand Down
4 changes: 3 additions & 1 deletion docs/griptape-cloud/index.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Griptape Cloud

Griptape Cloud is a managed platform for running AI-powered agents, pipelines, and workflows.
Griptape Cloud provides managed services for your AI app stack. Deploy and scale end-to-end solutions, from LLM-powered data prep and retrieval to AI agents, pipelines and workflows.

To get started with AI Structures in the Cloud, check out the [managed-structure-template](https://github.com/griptape-ai/managed-structure-template) or deploy one of the [griptape-sample-structures](https://github.com/griptape-ai/griptape-sample-structures/tree/main).
56 changes: 56 additions & 0 deletions docs/griptape-cloud/structures/structure-config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Overview

Structure repositories require a configuration file which informs Griptape Cloud of your Managed Structure's dependencies and how it needs to build and run.

## Structure Config File Schema

The schema for the configuration file is as follows:

```yaml
version: 1.0
runtime: python3
runtime_version: 3.11
build:
pre_build_install_script: scripts/my-pre-build-install-script.sh
post_build_install_script: scripts/my-post-build-install-script.sh
requirements_file: requirements.txt
cache_build_dependencies:
enabled: false
watched_files:
- requirements.txt
- scripts/my-pre-build-install-script.sh
- scripts/my-post-build-install-script.sh
run:
main_file: structure.py
```
### Configuration Fields
#### version
The Structure Config schema version number.
#### runtime
The runtime environment to use for the Structure.
#### runtime_version
The specific version of the runtime environment for the Structure.
#### build (OPTIONAL)
The build-time configuration for the Structure.
* **pre_build_install_script** - The path to your pre_build_install_script, for running during the Structure build prior to dependency installation. This path is relative to the structure configuration file. Or absolute from the repository root if a forward slash is used: `/my-pre-build-install-script.sh`.
* **post_build_install_script** - The path to your post_build_install_script, for running during the Structure build after dependency installation. This path is relative to the structure configuration file. Or absolute from the repository root if a forward slash is used: `/my-post-build-install-script.sh`.
* **requirements_file** - The path to your Structure's requirements.txt file.
* **cache_build_dependencies** - Defines the configuration for caching build dependencies in order to speed up Deployments
* **enabled** - Defines whether the build dependency caching is on or off
* **watched_files** - Defines the particular files that will trigger cache invalidation, resulting in a full rebuild of the Structure and dependencies

#### run (REQUIRED)

The run-time configuration for the Structure.

* **main_file** - Specifies the path to the entry point file of the Managed Structure. This path is relative to the structure_config.yaml. Or absolute from the repository root if a forward slash is used: `/structure.py`.
3 changes: 3 additions & 0 deletions docs/griptape-framework/drivers/text-to-speech-drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Provide a Driver when building an [Engine](../engines/audio-engines.md), then pa

The [Eleven Labs Text to Speech Driver](../../reference/griptape/drivers/text_to_speech/elevenlabs_text_to_speech_driver.md) provides support for text-to-speech models hosted by Eleven Labs. This Driver supports configurations specific to Eleven Labs, like voice selection and output format.

!!! info
This driver requires the `drivers-text-to-speech-elevenlabs` [extra](../index.md#extras).

```python
--8<-- "docs/griptape-framework/drivers/src/text_to_speech_drivers_1.py"
```
Expand Down
2 changes: 0 additions & 2 deletions griptape/artifacts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from .base_artifact import BaseArtifact
from .base_text_artifact import BaseTextArtifact
from .error_artifact import ErrorArtifact
from .info_artifact import InfoArtifact
from .text_artifact import TextArtifact
Expand All @@ -16,7 +15,6 @@

__all__ = [
"BaseArtifact",
"BaseTextArtifact",
"ErrorArtifact",
"InfoArtifact",
"TextArtifact",
Expand Down
34 changes: 0 additions & 34 deletions griptape/artifacts/base_text_artifact.py

This file was deleted.

4 changes: 2 additions & 2 deletions griptape/artifacts/csv_row_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

from attrs import define, field

from griptape.artifacts import BaseArtifact, BaseTextArtifact
from griptape.artifacts import BaseArtifact, TextArtifact


@define
class CsvRowArtifact(BaseTextArtifact):
class CsvRowArtifact(TextArtifact):
value: dict[str, str] = field(converter=BaseArtifact.value_to_dict, metadata={"serializable": True})
delimiter: str = field(default=",", kw_only=True, metadata={"serializable": True})

Expand Down
28 changes: 24 additions & 4 deletions griptape/artifacts/text_artifact.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,41 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

from attrs import define, field

from griptape.artifacts import BaseTextArtifact
from griptape.artifacts import BaseArtifact

if TYPE_CHECKING:
from griptape.artifacts import BaseArtifact
from griptape.drivers import BaseEmbeddingDriver
from griptape.tokenizers import BaseTokenizer


@define
class TextArtifact(BaseTextArtifact):
class TextArtifact(BaseArtifact):
value: str = field(converter=str, metadata={"serializable": True})
encoding: str = field(default="utf-8", kw_only=True)
encoding_error_handler: str = field(default="strict", kw_only=True)
_embedding: list[float] = field(factory=list, kw_only=True)

@property
def embedding(self) -> Optional[list[float]]:
return None if len(self._embedding) == 0 else self._embedding

def __add__(self, other: BaseArtifact) -> TextArtifact:
return TextArtifact(self.value + other.value)

def __bool__(self) -> bool:
return bool(self.value.strip())

def generate_embedding(self, driver: BaseEmbeddingDriver) -> Optional[list[float]]:
self._embedding.clear()
self._embedding.extend(driver.embed_string(str(self.value)))

return self.embedding

def token_count(self, tokenizer: BaseTokenizer) -> int:
return tokenizer.count_tokens(str(self.value))

def to_bytes(self) -> bytes:
return str(self.value).encode(encoding=self.encoding, errors=self.encoding_error_handler)
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ nav:
- Overview: "index.md"
- Contributing: "contributing.md"
- Cloud:
- Overview: "griptape-cloud/index.md"
- Cloud API:
- API Reference: "griptape-cloud/api/api-reference.md"
- Structures:
- Structure Config: "griptape-cloud/structures/structure-config.md"
- Framework:
- Overview: "griptape-framework/index.md"
- Structures:
Expand Down
5 changes: 2 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "griptape"
version = "0.29.0"
version = "0.29.1"
description = "Modular Python framework for LLM workflows, tools, memory, and data."
authors = ["Griptape <[email protected]>"]
license = "Apache 2.0"
Expand Down Expand Up @@ -116,6 +116,8 @@ drivers-event-listener-amazon-sqs = ["boto3"]
drivers-event-listener-amazon-iot = ["boto3"]
drivers-event-listener-pusher = ["pusher"]

drivers-text-to-speech-elevenlabs = ["elevenlabs"]

drivers-rerank-cohere = ["cohere"]

drivers-observability-opentelemetry = [
Expand Down
35 changes: 0 additions & 35 deletions tests/unit/artifacts/test_base_text_artifact.py

This file was deleted.

4 changes: 2 additions & 2 deletions tests/unit/artifacts/test_list_artifact.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from griptape.artifacts import BaseTextArtifact, BlobArtifact, CsvRowArtifact, ListArtifact, TextArtifact
from griptape.artifacts import BlobArtifact, CsvRowArtifact, ListArtifact, TextArtifact


class TestListArtifact:
Expand Down Expand Up @@ -32,7 +32,7 @@ def test_child_type(self):

def test_is_type(self):
assert ListArtifact([TextArtifact("foo")]).is_type(TextArtifact)
assert ListArtifact([CsvRowArtifact({"foo": "bar"})]).is_type(BaseTextArtifact)
assert ListArtifact([CsvRowArtifact({"foo": "bar"})]).is_type(TextArtifact)
assert ListArtifact([CsvRowArtifact({"foo": "bar"})]).is_type(CsvRowArtifact)

def test_has_items(self):
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/artifacts/test_text_artifact.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import json

import pytest

from griptape.artifacts import BaseArtifact, TextArtifact
from griptape.tokenizers import OpenAiTokenizer
from tests.mocks.mock_embedding_driver import MockEmbeddingDriver


class TestTextArtifact:
Expand Down Expand Up @@ -36,3 +40,31 @@ def test_meta(self):

meta = {"foo": "bar"}
assert TextArtifact("foo", meta=meta).meta == meta

def test_generate_embedding(self):
assert TextArtifact("foobar").generate_embedding(MockEmbeddingDriver()) == [0, 1]

def test_embedding(self):
artifact = TextArtifact("foobar")

assert artifact.embedding is None
assert artifact.generate_embedding(MockEmbeddingDriver()) == [0, 1]
assert artifact.embedding == [0, 1]

def test_to_bytes_encoding(self):
assert (
TextArtifact("ß", name="foobar.txt", encoding="ascii", encoding_error_handler="backslashreplace").to_bytes()
== b"\\xdf"
)

def test_to_bytes_encoding_error(self):
with pytest.raises(ValueError):
assert TextArtifact("ß", encoding="ascii").to_bytes()

def test_token_count(self):
assert (
TextArtifact("foobarbaz").token_count(
OpenAiTokenizer(model=OpenAiTokenizer.DEFAULT_OPENAI_GPT_3_CHAT_MODEL)
)
== 2
)

0 comments on commit 688bc98

Please sign in to comment.