Skip to content

Commit

Permalink
Merge pull request #836 from guardrails-ai/0.5.0-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
zsimjee authored Jul 17, 2024
2 parents fb845be + 90c1e17 commit 5770ea6
Show file tree
Hide file tree
Showing 410 changed files with 33,077 additions and 27,659 deletions.
62 changes: 30 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
- main
- dev
- feat/*
- 0.*.*

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -19,106 +20,103 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# - name: Poetry cache
# uses: actions/cache@v3
# with:
# path: ~/.cache/pypoetry
# key: poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}

- name: Install Poetry
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
- name: Lint with ruff
run: |
source .venv/bin/activate
make lint
Typing:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
pydantic-version: ["==1.10.9", ">=2.x"]
openai-version: [">=1.x"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# - name: Poetry cache
# uses: actions/cache@v3
# with:
# path: ~/.cache/pypoetry
# key: poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}-${{ matrix.pydantic-version }}

- name: Install Poetry
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
poetry run pip install "pydantic${{ matrix.pydantic-version }}"
poetry run pip install "openai${{ matrix.openai-version }}"
- name: Static analysis with pyright
run: |
source .venv/bin/activate
make type
Pytests:
runs-on: LargeBois
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
# TODO: fix errors so that we can run both `make dev` and `make full`
# dependencies: ['dev', 'full']
dependencies: ["full"]
pydantic-version: ["==1.10.9", ">=2.x"]
openai-version: [">=1.x"]
# dependencies: ["full"]
steps:
- uses: actions/checkout@v4

- name: Create .guardrailsrc
run: |
echo 'id="SYSTEM TESTING"' > ~/.guardrailsrc
echo 'no_metrics=false' >> ~/.guardrailsrc
echo 'enable_metrics=false' >> ~/.guardrailsrc
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

# - name: Poetry cache
# uses: actions/cache@v3
# with:
# path: ~/.cache/pypoetry
# key: poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}-${{ matrix.pydantic-version }}-${{ matrix.openai-version }}

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install Dependencies
run: |
make ${{ matrix.dependencies }}
poetry run pip install "pydantic${{ matrix.pydantic-version }}"
poetry run pip install "openai${{ matrix.openai-version }}"
# Setup Virtual Environment
python3 -m venv ./.venv
source .venv/bin/activate
make full
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"
fi
- name: Run Pytests
run: |
source .venv/bin/activate
echo "langchain-core version:"
pip show langchain-core
echo "langsmith version:"
pip show langsmith
make test-cov
- name: Upload to codecov.io
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/examples_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
NLTK_DATA: /tmp/nltk_data
steps:
- name: Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scripts/run_notebooks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ cd docs/examples
notebook="$1"

# Check if the notebook should be processed
invalid_notebooks=("valid_chess_moves.ipynb" "llamaindex-output-parsing.ipynb" "competitors_check.ipynb")
invalid_notebooks=("llamaindex-output-parsing.ipynb" "competitors_check.ipynb" "guardrails_server.ipynb" "valid_chess_moves.ipynb")
if [[ ! " ${invalid_notebooks[@]} " =~ " ${notebook} " ]]; then
echo "Processing $notebook..."
# poetry run jupyter nbconvert --to notebook --execute "$notebook"
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,10 @@ docusaurus/examples-toc.json
.python-version
static/docs
docusaurus/static/docs
*/bin/*
*/etc/*
*/lib/*
*/lib64/*
*/include/*
*/share/*
pyvenv.cfg
39 changes: 12 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,40 +1,13 @@
MKDOCS_SERVE_ADDR ?= localhost:8000 # Default address for mkdocs serve, format: <host>:<port>, override with `make docs-serve MKDOCS_SERVE_ADDR=<host>:<port>`

# Extract major package versions for OpenAI and Pydantic
OPENAI_VERSION_MAJOR := $(shell poetry run python -c 'import openai; print(openai.__version__.split(".")[0])')
PYDANTIC_VERSION_MAJOR := $(shell poetry run python -c 'import pydantic; print(pydantic.__version__.split(".")[0])')

# Construct the typing command using only major versions
TYPING_CMD := type-pydantic-v$(PYDANTIC_VERSION_MAJOR)-openai-v$(OPENAI_VERSION_MAJOR)

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

.PHONY: type
type:
@make $(TYPING_CMD)

type-pydantic-v1-openai-v0:
echo '{"reportDeprecated": true, "exclude": ["guardrails/utils/pydantic_utils/v2.py", "guardrails/utils/openai_utils/v1.py"]}' > pyrightconfig.json
poetry run pyright guardrails/
rm pyrightconfig.json

type-pydantic-v1-openai-v1:
echo '{"reportDeprecated": true, "exclude": ["guardrails/utils/pydantic_utils/v2.py", "guardrails/utils/openai_utils/v0.py"]}' > pyrightconfig.json
poetry run pyright guardrails/
rm pyrightconfig.json

type-pydantic-v2-openai-v0:
echo '{"reportDeprecated": true, "exclude": ["guardrails/utils/pydantic_utils/v1.py", "guardrails/utils/openai_utils/v1.py"]}' > pyrightconfig.json
poetry run pyright guardrails/
rm pyrightconfig.json

type-pydantic-v2-openai-v1:
echo '{"reportDeprecated": true, "exclude": ["guardrails/utils/pydantic_utils/v1.py", "guardrails/utils/openai_utils/v0.py"]}' > pyrightconfig.json
poetry run pyright guardrails/
rm pyrightconfig.json

lint:
poetry run ruff check guardrails/ tests/
Expand Down Expand Up @@ -85,3 +58,15 @@ precommit:
pyright guardrails/
make lint
./.github/workflows/scripts/update_notebook_matrix.sh

refresh:
echo "Removing old virtual environment"
rm -rf ./.venv;
echo "Creating new virtual environment"
python3 -m venv ./.venv;
echo "Sourcing and installing"
source ./.venv/bin/activate && make full;

update-lock:
poetry lock --no-update

1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/.quarto/
lib64
22 changes: 22 additions & 0 deletions docs/api_reference/async_guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!-- ::: my_library.my_module.my_class -->


::: guardrails.guard.AsyncGuard
options:
members:
- "__init__"
- "from_rail"
- "from_rail_string"
- "from_pydantic"
- "from_string"
- "configure"
- "use"
- "use_many"
- "__call__"
- "parse"
- "validate"
- "error_spans_in_output"
- "json_function_calling_tool"
- "to_dict"
- "from_dict"
- "to_runnable"
13 changes: 1 addition & 12 deletions docs/api_reference/data_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,5 @@
::: guardrails.datatypes
options:
filters:
- "!get_validators"
- "!registry"
- "!DataType"
- "!register_type"
- "!Scalar"
- "!set_children"
- "!validate"
- "!from_str"
- "!from_xml"
- "!model"
- "!validators"
- "!to_object_element"
- "!types_registry"
show_bases: true
7 changes: 7 additions & 0 deletions docs/api_reference/errors.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!-- ::: my_library.my_module.my_class -->


::: guardrails.errors
options:
members:
- "ValidationError"
10 changes: 9 additions & 1 deletion docs/api_reference/guard.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@
::: guardrails.guard.Guard
options:
members:
- "__init__"
- "from_rail"
- "from_rail_string"
- "from_pydantic"
- "from_string"
- "configure"
- "use"
- "use_many"
- "__call__"
- "parse"
- "state"
- "validate"
- "error_spans_in_output"
- "json_function_calling_tool"
- "to_dict"
- "from_dict"
- "to_runnable"
13 changes: 0 additions & 13 deletions docs/api_reference/rail.md

This file was deleted.

1 change: 0 additions & 1 deletion docs/api_reference/schema.md

This file was deleted.

1 change: 1 addition & 0 deletions docs/api_reference/types.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
::: guardrails.types
18 changes: 0 additions & 18 deletions docs/api_reference/validators.md

This file was deleted.

Loading

0 comments on commit 5770ea6

Please sign in to comment.