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

Use safe get for async validate_dependents #481

Merged
merged 6 commits into from
Dec 7, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/scripts/run_notebooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cd docs/examples
# Function to process a notebook
process_notebook() {
notebook="$1"
invalid_notebooks=("valid_chess_moves.ipynb" "translation_with_quality_check.ipynb" "llamaindex-output-parsing.ipynb" "competitors_check.ipynb")
invalid_notebooks=("valid_chess_moves.ipynb" "translation_with_quality_check.ipynb" "llamaindex-output-parsing.ipynb")
if [[ ! " ${invalid_notebooks[@]} " =~ " ${notebook} " ]]; then
echo "Processing $notebook..."
poetry run jupyter nbconvert --to notebook --execute "$notebook"
Expand Down
6 changes: 3 additions & 3 deletions guardrails/document_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,21 +241,21 @@ class FallbackEphemeralDocumentStore:
def __init__(self):
raise ImportError(
"SQLAlchemy is required for EphemeralDocumentStore"
"Please install it using `pip install SqlAlchemy`"
"Please install it using `poetry add SqlAlchemy`"
)

class FallbackSQLDocument:
def __init__(self):
raise ImportError(
"SQLAlchemy is required for SQLDocument"
"Please install it using `pip install SqlAlchemy`"
"Please install it using `poetry add SqlAlchemy`"
)

class FallbackSQLMetadataStore:
def __init__(self):
raise ImportError(
"SQLAlchemy is required for SQLMetadataStore"
"Please install it using `pip install SqlAlchemy`"
"Please install it using `poetry add SqlAlchemy`"
)

EphemeralDocumentStore = FallbackEphemeralDocumentStore
Expand Down
6 changes: 3 additions & 3 deletions guardrails/embedding.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(
except ImportError:
raise ImportError(
f"`numpy` is required for `{self.__class__.__name__}` class."
"Please install it with `pip install numpy`."
"Please install it with `poetry add numpy`."
)

self._model = model
Expand Down Expand Up @@ -55,7 +55,7 @@ def _len_safe_get_embedding(
except ImportError:
raise ImportError(
f"`numpy` is required for `{self.__class__.__name__}` class."
"Please install it with `pip install numpy`."
"Please install it with `poetry add numpy`."
)

chunk_embeddings_list = []
Expand Down Expand Up @@ -179,7 +179,7 @@ def __init__(
except ImportError:
raise ImportError(
"The `manifest` package is not installed. "
"Install with `pip install manifest-ml`"
"Install with `poetry add manifest-ml`"
)
super().__init__(engine, encoding_name, max_tokens)
self._client_name = client_name
Expand Down
4 changes: 2 additions & 2 deletions guardrails/llm_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _invoke_llm(
except ImportError:
raise PromptCallableException(
"The `manifest` package is not installed. "
"Install with `pip install manifest-ml`"
"Install with `poetry add manifest-ml`"
)
client = cast(manifest.Manifest, client)
manifest_response = client.run(
Expand Down Expand Up @@ -469,7 +469,7 @@ async def invoke_llm(
except ImportError:
raise PromptCallableException(
"The `manifest` package is not installed. "
"Install with `pip install manifest-ml`"
"Install with `poetry add manifest-ml`"
)
client = cast(manifest.Manifest, client)
manifest_response = await client.arun_batch(
Expand Down
6 changes: 3 additions & 3 deletions guardrails/utils/docs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def sentence_split(text: str) -> t.List[str]:
except ImportError:
raise ImportError(
"nltk is required for sentence splitting. Please install it using "
"`pip install nltk`"
"`poetry add nltk`"
)

# Download the nltk punkt tokenizer if it's not already downloaded.
Expand Down Expand Up @@ -123,11 +123,11 @@ def get_chunks_from_text(

nltk_error = (
"nltk is required for sentence splitting. Please install it using "
"`pip install nltk`"
"`poetry add nltk`"
)
tiktoken_error = (
"tiktoken is required for token splitting. Please install it using "
"`pip install tiktoken`"
"`poetry add tiktoken`"
)

if chunk_strategy == "sentence":
Expand Down
2 changes: 1 addition & 1 deletion guardrails/utils/sql_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def __init__(self, schema_file: Optional[str], conn: Optional[str]) -> None:
if not _HAS_SQLALCHEMY:
raise ImportError(
"""The functionality requires sqlalchemy to be installed.
Please install it using `pip install SqlAlchemy`"""
Please install it using `poetry add SqlAlchemy`"""
)

if schema_file is not None and conn is None:
Expand Down
2 changes: 1 addition & 1 deletion guardrails/validator_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ async def validate_dependents(
iteration: Iteration,
):
async def process_child(child_setup):
child_value = value[child_setup.key]
child_value = safe_get(value, child_setup.key)
new_child_value, new_metadata = await self.async_validate(
child_value,
metadata,
Expand Down
2 changes: 1 addition & 1 deletion guardrails/validators/competitor_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Callable, Dict, List, Optional

from guardrails.logger import logger
from guardrails.validator_base import (
from guardrails.validators import (
FailResult,
PassResult,
ValidationResult,
Expand Down
2 changes: 1 addition & 1 deletion guardrails/vectordb/faiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

faiss_error = (
"`faiss` is required for using vectordb.faiss."
"Install it with `pip install faiss-cpu`."
"Install it with `poetry add faiss-cpu`."
)


Expand Down
Loading