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
34 changes: 27 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,18 @@ jobs:
# Setup Virtual Environment
python3 -m venv ./.venv
source .venv/bin/activate
poetry install --extras dev

if [ "${{ matrix.python-version }}" == "3.9" ];
then
pip install .[dev]
else
poetry install --extras dev
fi

- name: Check license
run: |
source .venv/bin/activate
.venv/bin/pip install greenlet
.venv/bin/pip install greenlet setuptools
.venv/bin/liccheck
Linting:
runs-on: ubuntu-latest
Expand All @@ -60,12 +66,16 @@ jobs:
uses: snok/install-poetry@v1

- name: Install Dependencies
# TODO: fix errors so that we can run `make dev` instead
run: |
# Setup Virtual Environment
python3 -m venv ./.venv
source .venv/bin/activate
make full
if [ "${{ matrix.python-version }}" == "3.9" ];
then
pip install .[dev]
else
make dev
fi

- name: Lint with ruff
run: |
Expand All @@ -88,12 +98,16 @@ jobs:
uses: snok/install-poetry@v1

- name: Install Dependencies
# TODO: fix errors so that we can run `make dev` instead
run: |
# Setup Virtual Environment
python3 -m venv ./.venv
source .venv/bin/activate
make full
if [ "${{ matrix.python-version }}" == "3.9" ];
then
pip install .[dev,sql,vectordb,manifest,anthropic,huggingface,api,databricks,uv,llama]
else
make full
fi

- name: Static analysis with pyright
run: |
Expand Down Expand Up @@ -130,7 +144,13 @@ jobs:
python3 -m venv ./.venv
source .venv/bin/activate

make full
if [ "${{ matrix.python-version }}" == "3.9" ];
then
pip install .[dev,sql,vectordb,manifest,anthropic,huggingface,api,databricks,uv,llama]
else
make full
fi

if [ "${{ matrix.python-version }}" == "3.12" ]; then
echo "Installing latest langchain-core and langsmith from PyPI"
pip install "langchain-core>=0.2" "langsmith<0.2.0,>=0.1.75"
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/server_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ on:
jobs:
build-test-server:
runs-on: ubuntu-latest
strategy:
matrix:
tag: ["fastapi", "flask"]
steps:
- name: Check out head
uses: actions/checkout@v3
uses: actions/checkout@v5
with:
persist-credentials: false

Expand All @@ -29,17 +32,17 @@ jobs:
uses: docker/build-push-action@v6
with:
context: .
file: server_ci/Dockerfile
file: server_ci/Dockerfile.${{ matrix.tag }}
platforms: linux/amd64
push: false
tags: guardrails:${{ github.sha }}
tags: guardrails:${{ matrix.tag }}
load: true
build-args: |
GUARDRAILS_TOKEN=${{ secrets.GUARDRAILS_API_KEY }}

- name: Start Docker container
run: |
docker run -d --name guardrails-container -p 8000:8000 -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} guardrails:${{ github.sha }}
docker run -d --name guardrails-container -p 8000:8000 -e OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} guardrails:${{ matrix.tag }}

- name: Wait for Docker container to be ready
run: |
Expand All @@ -54,7 +57,7 @@ jobs:

- name: Run Pytest
run: |
pip install pytest openai guardrails-ai
pip install pytest pytest-asyncio openai guardrails-ai
pytest server_ci/tests
docker stop guardrails-container
docker rm guardrails-container
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
MKDOCS_SERVE_ADDR ?= localhost:8000 # Default address for mkdocs serve, format: <host>:<port>, override with `make docs-serve MKDOCS_SERVE_ADDR=<host>:<port>`

autoformat:
poetry run ruff check guardrails/ tests/ --fix
poetry run ruff format guardrails/ tests/
poetry run docformatter --in-place --recursive guardrails tests
ruff check guardrails/ tests/ --fix
ruff format guardrails/ tests/
docformatter --in-place --recursive guardrails tests

.PHONY: type
type:
poetry run pyright guardrails/
pyright guardrails/

lint:
poetry run ruff check guardrails/ tests/
poetry run ruff format guardrails/ tests/ --check
ruff check guardrails/ tests/
ruff format guardrails/ tests/ --check

test:
poetry run pytest tests/
pytest tests/

test-basic:
set -e
python -c "import guardrails as gd"
python -c "import guardrails.version as mversion"

test-cov:
poetry run pytest tests/ --cov=./guardrails/ --cov-report=xml
pytest tests/ --cov=./guardrails/ --cov-report=xml

view-test-cov:
poetry run pytest tests/ --cov=./guardrails/ --cov-report html && open htmlcov/index.html
pytest tests/ --cov=./guardrails/ --cov-report html && open htmlcov/index.html

view-test-cov-file:
poetry run pytest tests/unit_tests/test_logger.py --cov=./guardrails/ --cov-report html && open htmlcov/index.html
pytest tests/unit_tests/test_logger.py --cov=./guardrails/ --cov-report html && open htmlcov/index.html

docs-serve:
poetry run mkdocs serve -a $(MKDOCS_SERVE_ADDR)
Expand All @@ -37,7 +37,7 @@ docs-deploy:
poetry run mkdocs gh-deploy

dev:
poetry install
poetry install --extras "dev"
poetry run pre-commit install

full:
Expand Down
10 changes: 9 additions & 1 deletion guardrails/api_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import sys
from typing import Any, Iterator, Optional

import requests
Expand Down Expand Up @@ -37,8 +38,15 @@ def __init__(self, base_url: Optional[str] = None, api_key: Optional[str] = None
api_key if api_key is not None else os.environ.get("GUARDRAILS_API_KEY", "")
)
self.timeout = 300

_api_key = (
self.api_key
if sys.version_info.minor < 10
else {"ApiKeyAuth": self.api_key}
)

self._api_client = ApiClient(
configuration=Configuration(api_key=self.api_key, host=self.base_url)
configuration=Configuration(api_key=_api_key, host=self.base_url) # type: ignore
)
self._guard_api = GuardApi(self._api_client)
self._validate_api = ValidateApi(self._api_client)
Expand Down
Loading