Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error when knowledgebase is missing a description #839

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **BREAKING**: Removed `BedrockLlamaTokenizer`, use `SimpleTokenizer` instead.
- **BREAKING**: Removed `BedrockTitanTokenizer`, use `SimpleTokenizer` instead.
- **BREAKING**: Removed `OpenAiChatCompletionPromptDriver` as it uses the legacy [OpenAi Completions API](https://platform.openai.com/docs/api-reference/completions).
- Improved error message when `GriptapeCloudKnowledgeBaseClient` does not have a description set.
- Updated `AmazonBedrockPromptDriver` to use [Converse API](https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html).
- `Structure.before_run()` now automatically resolves asymmetrically defined parent/child relationships using the new `Structure.resolve_relationships()`.
- Updated `HuggingFaceHubPromptDriver` to use `transformers`'s `apply_chat_template`.
Expand Down
4 changes: 3 additions & 1 deletion griptape/tools/griptape_cloud_knowledge_base_client/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,6 @@ def _get_knowledge_base_description(self) -> str:
if "description" in response:
return response["description"]
else:
raise ValueError(f'Error getting Knowledge Base description: {response["message"]}')
raise ValueError(
f"No description found for Knowledge Base {self.knowledge_base_id}. Please set a description, or manually set the `GriptapeCloudKnowledgeBaseClient.description` attribute."
)
21 changes: 21 additions & 0 deletions tests/unit/tools/test_griptape_cloud_knowledge_base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ def client(self, mocker):
base_url="https://api.griptape.ai", api_key="foo bar", knowledge_base_id="1"
)

@pytest.fixture
def client_no_description(self, mocker):
from griptape.tools import GriptapeCloudKnowledgeBaseClient

mock_response = mocker.Mock()
mock_response.json.return_value = {}
mocker.patch("requests.get", return_value=mock_response)

return GriptapeCloudKnowledgeBaseClient(
base_url="https://api.griptape.ai", api_key="foo bar", knowledge_base_id="1"
)

def test_query(self, client):
assert isinstance(client.query({"values": {"query": "foo bar"}}), TextArtifact)

Expand All @@ -27,3 +39,12 @@ def test_get_knowledge_base_description(self, client):

client.description = "foo bar"
assert client._get_knowledge_base_description() == "foo bar"

def test_get_knowledge_base_description_error(self, client_no_description):
with pytest.raises(ValueError) as e:
client_no_description._get_knowledge_base_description()

assert (
str(e)
== f"No description found for Knowledge Base {client_no_description.knowledge_base_id}. Please set a description, or manually set the `GriptapeCloudKnowledgeBaseClient.description` attribute."
)
Loading