Skip to content
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
89 changes: 47 additions & 42 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"rich>=13.6.0,<15.0.0",
"pydantic>=2.0.0, <3.0",
"typer>=0.9.0,<0.16",
"click<8.2.0", # TODO: Upgrade typer range and test cli before allowing >=8.2.0
"tenacity>=8.1.0,<10.0.0",
"rstr>=3.2.2,<4.0.0",
"typing-extensions>=4.8.0,<5.0.0",
Expand Down Expand Up @@ -96,8 +97,7 @@ docs-build = [
"pydoc-markdown==4.8.2"
]
huggingface = [
# Blocked from upgrading further by jsonformer
"transformers>=4.38.0,<4.49.0",
"transformers>=4.38.0,<5.0.0",
"torch>=2.1.1,<3.0.0",
"guardrails-jsonformer>=0.13.1,<1.0.0"
]
Expand Down Expand Up @@ -206,4 +206,5 @@ dependencies = true # to load [tool.poetry.dependencies]
[tool.liccheck.authorized_packages]
aiocache = "0.12.3" # BSD 3-Clause
aiohappyeyeballs = "2.4.3" # Python Software Foundation
guardrails-api = "*" # Modified ELSSTIC
guardrails-api = "*" # Modified ELSSTIC
pondpond = "1.4.1" # Apache 2.0
30 changes: 30 additions & 0 deletions server_ci/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
.coverage
.coverage.MacBook-Pro.local.75130.XUoRtLxx
.dockerignore
.docusaurus
.git
.github
.gitignore
.idea
.pre-commit-config.yaml
.pytest_cache
.python-version
.ruff_cache
.venv
.vscode
build
codecov.yml
CONTRIBUTING.md
docs
docs-build
docs-graveyard
DOCS.md
docusaurus
htmlcov
make.bat
mlartifacts
mlruns
node_modules
package-lock.json
package.json
tests
14 changes: 4 additions & 10 deletions server_ci/Dockerfile.fastapi
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.12-slim
# New LiteLLM version has a dependency on madoka which requires g++ to build the wheel
FROM python:3.12

ARG GUARDRAILS_TOKEN
ARG GUARDRAILS_TEMPLATE="guard-template.json"
Expand All @@ -19,9 +20,6 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN pipx install poetry

# Ensure poetry is available in the PATH
ENV PATH="/root/.local/bin:$PATH"

# Copy the entrypoint script
Expand All @@ -30,13 +28,9 @@ COPY ../ /app/guardrails

# Install guardrails, the guardrails API, and gunicorn
# openai optional. only used for integration testing
RUN pip install "uvicorn[standard]" "guardrails-api>=0.1.0a1" "guardrails-api-client>=0.4.0a2" --no-cache-dir

WORKDIR /app/guardrails

RUN poetry install
RUN pip install "uvicorn[standard]" --no-cache-dir

RUN pip install ./
RUN pip install "/app/guardrails[api]"

RUN guardrails configure --enable-metrics --enable-remote-inferencing --token $GUARDRAILS_TOKEN

Expand Down
9 changes: 4 additions & 5 deletions server_ci/Dockerfile.flask
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
FROM python:3.12-slim
# New LiteLLM version has a dependency on madoka which requires g++ to build the wheel
FROM python:3.12

ARG GUARDRAILS_TOKEN
ARG GUARDRAILS_TEMPLATE="guard-template.json"
Expand All @@ -19,17 +20,15 @@ RUN apt-get update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN pipx install poetry

# Ensure poetry is available in the PATH
ENV PATH="/root/.local/bin:$PATH"

# Copy the entrypoint script
COPY /server_ci/flask-entry.sh /app/flask-entry.sh

# Install guardrails, the guardrails API, and gunicorn
# openai optional. only used for integration testing
RUN pip install "gunicorn[gthread]>=22.0.0,<23" "guardrails-api>=0.0.5,<0.1.0" "guardrails-ai==0.5.15" "guardrails-api-client>=0.3.0,<0.4.0"
# Lock click version to what's compatible with typer==0.12.5
RUN pip install "click==8.1.8" "gunicorn[gthread]>=22.0.0,<23" "guardrails-ai[api]==0.5.15"

RUN guardrails configure --enable-metrics --enable-remote-inferencing --token $GUARDRAILS_TOKEN

Expand Down
10 changes: 6 additions & 4 deletions tests/integration_tests/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class Foo(BaseModel):
assert isinstance(validated_output["bez"][0], str)


@pytest.mark.skip(reason="Random model infinitely recurses on complex struct. Use GPT2")
@if_transformers_installed
def test_hugging_face_pipeline_complex_schema():
# NOTE: This is the real GPT-2 model.
from transformers import pipeline

model = pipeline("text-generation", "gpt2")
model = pipeline("text-generation", "distilgpt2")

class MultiNum(BaseModel):
whole: int
Expand All @@ -73,10 +73,12 @@ class Tricky(BaseModel):
foo: MultiNum

g = Guard.for_pydantic(Tricky, output_formatter="jsonformer")
response = g(model, prompt="Sample:")
response = g(model, messages=[{"content": "Sample:", "role": "user"}])
out = response.validated_output
assert isinstance(out, dict)
assert "foo" in out
assert isinstance(out["foo"], dict)
assert isinstance(out["foo"]["whole"], int | float)
assert isinstance(out["foo"]["whole"], int) or isinstance(
out["foo"]["whole"], float
)
assert isinstance(out["foo"]["frac"], float)
4 changes: 2 additions & 2 deletions tests/unit_tests/test_llm_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,11 +360,11 @@ def mock_os_environ_get(key, *args):
reason="transformers is not installed",
)
def test_get_llm_ask_hugging_face_model(mocker):
from transformers import PreTrainedModel
from transformers import PreTrainedModel, GenerationMixin

from guardrails.llm_providers import HuggingFaceModelCallable

class MockModel(PreTrainedModel):
class MockModel(PreTrainedModel, GenerationMixin):
_modules: Any

def __init__(self, *args, **kwargs):
Expand Down