Skip to content

Commit

Permalink
Remove many instances of catching exceptions (#1101)
Browse files Browse the repository at this point in the history
  • Loading branch information
collindutter authored Aug 26, 2024
1 parent f2b529a commit 3c604af
Show file tree
Hide file tree
Showing 43 changed files with 253 additions and 381 deletions.
19 changes: 19 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,22 @@
This document provides instructions for migrating your codebase to accommodate breaking changes introduced in new versions of Griptape.

## 0.30.X to 0.31.X

### Exceptions Over `ErrorArtifact`s

Drivers, Loaders, and Engines will now raises exceptions rather than returning `ErrorArtifact`s.
Update any logic that expects `ErrorArtifact` to handle exceptions instead.

```python
# Before
artifacts = WebLoader().load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# After
try:
artifacts = WebLoader().load("https://www.griptape.ai")
except Exception as e:
raise e
```
4 changes: 0 additions & 4 deletions docs/examples/src/load_query_and_chat_marqo_1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os

from griptape import utils
from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import MarqoVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader
from griptape.structures import Agent
Expand All @@ -27,9 +26,6 @@
# Load artifacts from the web
artifacts = WebLoader().load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert the artifacts into the vector store
vector_store.upsert_text_artifacts(
{
Expand Down
3 changes: 0 additions & 3 deletions docs/examples/src/query_webpage_1.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import os

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import LocalVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader

vector_store = LocalVectorStoreDriver(embedding_driver=OpenAiEmbeddingDriver(api_key=os.environ["OPENAI_API_KEY"]))

artifacts = WebLoader(max_tokens=100).load("https://www.griptape.ai")
if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

for a in artifacts:
vector_store.upsert_text_artifact(a, namespace="griptape")
Expand Down
4 changes: 1 addition & 3 deletions docs/examples/src/query_webpage_astra_db_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts import ErrorArtifact
from griptape.drivers import (
AstraDbVectorStoreDriver,
OpenAiChatPromptDriver,
Expand Down Expand Up @@ -45,8 +44,7 @@
)

artifacts = WebLoader(max_tokens=256).load(input_blogpost)
if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

vector_store_driver.upsert_text_artifacts({namespace: artifacts})

rag_tool = RagTool(
Expand Down
3 changes: 0 additions & 3 deletions docs/examples/src/talk_to_a_pdf_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import LocalVectorStoreDriver, OpenAiChatPromptDriver, OpenAiEmbeddingDriver
from griptape.engines.rag import RagEngine
from griptape.engines.rag.modules import PromptResponseRagModule, VectorStoreRetrievalRagModule
Expand Down Expand Up @@ -32,8 +31,6 @@
)

artifacts = PdfLoader().load(response.content)
if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

vector_store.upsert_text_artifacts({namespace: artifacts})

Expand Down
4 changes: 0 additions & 4 deletions docs/examples/src/talk_to_a_webpage_1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import LocalVectorStoreDriver, OpenAiChatPromptDriver, OpenAiEmbeddingDriver
from griptape.engines.rag import RagEngine
from griptape.engines.rag.modules import PromptResponseRagModule, VectorStoreRetrievalRagModule
Expand Down Expand Up @@ -28,9 +27,6 @@

artifacts = WebLoader().load("https://en.wikipedia.org/wiki/Physics")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

vector_store_driver.upsert_text_artifacts({namespace: artifacts})

rag_tool = RagTool(
Expand Down
3 changes: 0 additions & 3 deletions docs/griptape-framework/drivers/src/vector_store_drivers_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts import ErrorArtifact
from griptape.drivers import LocalVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader

Expand All @@ -12,8 +11,6 @@
# Load Artifacts from the web
artifacts = WebLoader(max_tokens=100).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)
# Upsert Artifacts into the Vector Store Driver
[vector_store_driver.upsert_text_artifact(a, namespace="griptape") for a in artifacts]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import OpenAiEmbeddingDriver, QdrantVectorStoreDriver
from griptape.loaders import WebLoader

Expand All @@ -22,9 +21,6 @@
# Load Artifacts from the web
artifacts = WebLoader().load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Recreate Qdrant collection
vector_store_driver.client.recreate_collection(
collection_name=vector_store_driver.collection_name,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import AstraDbVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader

Expand All @@ -23,9 +22,6 @@
# Load Artifacts from the web
artifacts = WebLoader().load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
[vector_store_driver.upsert_text_artifact(a, namespace="griptape") for a in artifacts]

Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/drivers/src/vector_store_drivers_3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts import ErrorArtifact
from griptape.drivers import OpenAiEmbeddingDriver, PineconeVectorStoreDriver
from griptape.loaders import WebLoader

Expand All @@ -17,9 +16,6 @@
# Load Artifacts from the web
artifacts = WebLoader(max_tokens=100).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
[vector_store_driver.upsert_text_artifact(a, namespace="griptape") for a in artifacts]

Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/drivers/src/vector_store_drivers_4.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts import ErrorArtifact
from griptape.drivers import MarqoVectorStoreDriver, OpenAiChatPromptDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader

Expand All @@ -22,9 +21,6 @@
# Load Artifacts from the web
artifacts = WebLoader(max_tokens=200).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
vector_store_driver.upsert_text_artifacts(
{
Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/drivers/src/vector_store_drivers_5.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import MongoDbAtlasVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader

Expand Down Expand Up @@ -28,9 +27,6 @@
# Load Artifacts from the web
artifacts = WebLoader(max_tokens=200).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
vector_store_driver.upsert_text_artifacts(
{
Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/drivers/src/vector_store_drivers_6.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import AzureMongoDbVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader

Expand Down Expand Up @@ -28,9 +27,6 @@
# Load Artifacts from the web
artifacts = WebLoader(max_tokens=200).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
vector_store_driver.upsert_text_artifacts(
{
Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/drivers/src/vector_store_drivers_7.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import OpenAiEmbeddingDriver, RedisVectorStoreDriver
from griptape.loaders import WebLoader

Expand All @@ -18,9 +17,6 @@
# Load Artifacts from the web
artifacts = WebLoader(max_tokens=200).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
vector_store_driver.upsert_text_artifacts(
{
Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/drivers/src/vector_store_drivers_8.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import boto3

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import AmazonOpenSearchVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader

Expand All @@ -19,9 +18,6 @@
# Load Artifacts from the web
artifacts = WebLoader(max_tokens=200).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
vector_store_driver.upsert_text_artifacts(
{
Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/drivers/src/vector_store_drivers_9.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import OpenAiEmbeddingDriver, PgVectorVectorStoreDriver
from griptape.loaders import WebLoader

Expand All @@ -25,9 +24,6 @@
# Load Artifacts from the web
artifacts = WebLoader().load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

# Upsert Artifacts into the Vector Store Driver
vector_store_driver.upsert_text_artifacts(
{
Expand Down
3 changes: 0 additions & 3 deletions docs/griptape-framework/engines/src/rag_engines_1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from griptape.artifacts import ErrorArtifact
from griptape.drivers import LocalVectorStoreDriver, OpenAiChatPromptDriver, OpenAiEmbeddingDriver
from griptape.engines.rag import RagContext, RagEngine
from griptape.engines.rag.modules import PromptResponseRagModule, TranslateQueryRagModule, VectorStoreRetrievalRagModule
Expand All @@ -11,8 +10,6 @@
vector_store = LocalVectorStoreDriver(embedding_driver=OpenAiEmbeddingDriver())
artifacts = WebLoader(max_tokens=500).load("https://www.griptape.ai")

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

vector_store.upsert_text_artifacts(
{
Expand Down
4 changes: 0 additions & 4 deletions docs/griptape-framework/engines/src/summary_engines_1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import requests

from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import OpenAiChatPromptDriver
from griptape.engines import PromptSummaryEngine
from griptape.loaders import PdfLoader
Expand All @@ -12,9 +11,6 @@

artifacts = PdfLoader().load(response.content)

if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

text = "\n\n".join([a.value for a in artifacts])

engine.summarize_text(text)
3 changes: 0 additions & 3 deletions docs/griptape-tools/official-tools/src/vector_store_tool_1.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from griptape.artifacts.error_artifact import ErrorArtifact
from griptape.drivers import LocalVectorStoreDriver, OpenAiEmbeddingDriver
from griptape.loaders import WebLoader
from griptape.structures import Agent
Expand All @@ -9,8 +8,6 @@
)

artifacts = WebLoader().load("https://www.griptape.ai")
if isinstance(artifacts, ErrorArtifact):
raise Exception(artifacts.value)

vector_store_driver.upsert_text_artifacts({"griptape": artifacts})
vector_db = VectorStoreTool(
Expand Down
Loading

0 comments on commit 3c604af

Please sign in to comment.