Skip to content

Commit 106a94c

Browse files
authored
Merge branch 'guardrails-ai:main' into main
2 parents f9710ad + bc92da3 commit 106a94c

File tree

228 files changed

+16097
-7045
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

228 files changed

+16097
-7045
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99
branches:
1010
- main
1111
- dev
12-
- "0.3.0"
1312

1413
# Allows you to run this workflow manually from the Actions tab
1514
workflow_dispatch:
@@ -21,17 +20,17 @@ jobs:
2120
matrix:
2221
python-version: ["3.8", "3.9", "3.10", "3.11"]
2322
steps:
24-
- uses: actions/checkout@v2
23+
- uses: actions/checkout@v4
2524
- name: Set up Python ${{ matrix.python-version }}
26-
uses: actions/setup-python@v2
25+
uses: actions/setup-python@v5
2726
with:
2827
python-version: ${{ matrix.python-version }}
2928

30-
- name: Poetry cache
31-
uses: actions/cache@v3
32-
with:
33-
path: ~/.cache/pypoetry
34-
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
29+
# - name: Poetry cache
30+
# uses: actions/cache@v3
31+
# with:
32+
# path: ~/.cache/pypoetry
33+
# key: poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}
3534

3635
- name: Install Poetry
3736
uses: snok/install-poetry@v1
@@ -53,17 +52,17 @@ jobs:
5352
pydantic-version: ["1.10.9", "2.4.2"]
5453
openai-version: ["0.28.1", "1.2.4"]
5554
steps:
56-
- uses: actions/checkout@v2
55+
- uses: actions/checkout@v4
5756
- name: Set up Python ${{ matrix.python-version }}
58-
uses: actions/setup-python@v2
57+
uses: actions/setup-python@v5
5958
with:
6059
python-version: ${{ matrix.python-version }}
6160

62-
- name: Poetry cache
63-
uses: actions/cache@v3
64-
with:
65-
path: ~/.cache/pypoetry
66-
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}-${{ matrix.pydantic-version }}
61+
# - name: Poetry cache
62+
# uses: actions/cache@v3
63+
# with:
64+
# path: ~/.cache/pypoetry
65+
# key: poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}-${{ matrix.pydantic-version }}
6766

6867
- name: Install Poetry
6968
uses: snok/install-poetry@v1
@@ -75,28 +74,12 @@ jobs:
7574
poetry run pip install pydantic==${{ matrix.pydantic-version }}
7675
poetry run pip install openai==${{ matrix.openai-version }}
7776
78-
- if: matrix.pydantic-version == '2.4.2' && matrix.openai-version == '0.28.1'
79-
name: Static analysis with pyright (ignoring pydantic v1 and openai v1)
80-
run: |
81-
make type-pydantic-v2-openai-v0
82-
83-
- if: matrix.pydantic-version == '1.10.9' && matrix.openai-version == '0.28.1'
84-
name: Static analysis with mypy (ignoring pydantic v2 and openai v1)
85-
run: |
86-
make type-pydantic-v1-openai-v0
87-
88-
- if: matrix.pydantic-version == '2.4.2' && matrix.openai-version == '1.2.4'
89-
name: Static analysis with pyright (ignoring pydantic v1 and openai v0)
90-
run: |
91-
make type-pydantic-v2-openai-v1
92-
93-
- if: matrix.pydantic-version == '1.10.9' && matrix.openai-version == '1.2.4'
94-
name: Static analysis with mypy (ignoring pydantic v2 and openai v0)
77+
- name: Static analysis with pyright
9578
run: |
96-
make type-pydantic-v1-openai-v1
79+
make type
9780
9881
Pytests:
99-
runs-on: ubuntu-latest
82+
runs-on: LargeBois
10083
strategy:
10184
matrix:
10285
python-version: ["3.8", "3.9", "3.10", "3.11"]
@@ -106,17 +89,17 @@ jobs:
10689
pydantic-version: ["1.10.9", "2.4.2"]
10790
openai-version: ["0.28.1", "1.2.4"]
10891
steps:
109-
- uses: actions/checkout@v2
92+
- uses: actions/checkout@v4
11093
- name: Set up Python ${{ matrix.python-version }}
111-
uses: actions/setup-python@v2
94+
uses: actions/setup-python@v5
11295
with:
11396
python-version: ${{ matrix.python-version }}
11497

115-
- name: Poetry cache
116-
uses: actions/cache@v3
117-
with:
118-
path: ~/.cache/pypoetry
119-
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}-${{ matrix.pydantic-version }}-${{ matrix.openai-version }}
98+
# - name: Poetry cache
99+
# uses: actions/cache@v3
100+
# with:
101+
# path: ~/.cache/pypoetry
102+
# key: poetry-cache-${{ runner.os }}-${{ matrix.python-version }}-${{ env.POETRY_VERSION }}-${{ matrix.pydantic-version }}-${{ matrix.openai-version }}
120103

121104
- name: Install Poetry
122105
uses: snok/install-poetry@v1
@@ -138,51 +121,4 @@ jobs:
138121
file: ./coverage.xml
139122
flags: unittests
140123
name: codecov-umbrella
141-
fail_ci_if_error: true
142-
143-
Notebooks:
144-
runs-on: ubuntu-latest
145-
needs: [Linting, Typing, Pytests]
146-
strategy:
147-
matrix:
148-
# this line is automatically generated by the script in .github/workflows/scripts/update_notebook_matrix.sh
149-
notebook: ["bug_free_python_code.ipynb","check_for_pii.ipynb","competitors_check.ipynb","extracting_entities.ipynb","generate_structured_data.ipynb","generate_structured_data_cohere.ipynb","guardrails_with_chat_models.ipynb","input_validation.ipynb","llamaindex-output-parsing.ipynb","no_secrets_in_generated_text.ipynb","provenance.ipynb","recipe_generation.ipynb","regex_validation.ipynb","response_is_on_topic.ipynb","secrets_detection.ipynb","select_choice_based_on_action.ipynb","streaming.ipynb","syntax_error_free_sql.ipynb","text_summarization_quality.ipynb","toxic_language.ipynb","translation_to_specific_language.ipynb","translation_with_quality_check.ipynb","valid_chess_moves.ipynb","value_within_distribution.ipynb"]
150-
env:
151-
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
152-
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
153-
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
154-
NLTK_DATA: /tmp/nltk_data
155-
steps:
156-
- name: Checkout repository
157-
uses: actions/checkout@v2
158-
- name: Set up Python
159-
uses: actions/setup-python@v4
160-
with:
161-
python-version: 3.11.x
162-
- name: Install Poetry
163-
uses: snok/install-poetry@v1
164-
with:
165-
virtualenvs-create: true
166-
virtualenvs-in-project: true
167-
installer-parallel: true
168-
- name: Load cached venv
169-
uses: actions/cache@v3
170-
with:
171-
path: .venv
172-
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
173-
- name: Install dependencies
174-
run: |
175-
make full;
176-
poetry add "openai>=1.2.4" jupyter nbconvert cohere;
177-
- name: Check for pypdfium2
178-
run: poetry run pip show pypdfium2
179-
- name: Huggingface Hub Login
180-
run: poetry run huggingface-cli login --token $HUGGINGFACE_API_KEY
181-
- name: download nltk data
182-
run: |
183-
mkdir /tmp/nltk_data;
184-
poetry run python -m nltk.downloader -d /tmp/nltk_data punkt;
185-
- name: Use venv
186-
run: source .venv/bin/activate
187-
- name: Execute notebooks and check for errors
188-
run: bash ./.github/workflows/scripts/run_notebooks.sh ${{ matrix.notebook }}
124+
fail_ci_if_error: true

.github/workflows/examples_check.yml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name: Notebook Execution and Error Check
33
on:
44
schedule:
55
- cron: "0 0 * * *"
6+
push:
7+
branches:
8+
- main
9+
- dev
610
workflow_dispatch: # This enables manual triggering
711

812
jobs:
@@ -19,16 +23,16 @@ jobs:
1923
NLTK_DATA: /tmp/nltk_data
2024
steps:
2125
- name: Checkout repository
22-
uses: actions/checkout@v2
26+
uses: actions/checkout@v4
2327
- name: Set up Python
24-
uses: actions/setup-python@v2
28+
uses: actions/setup-python@v5
2529
with:
2630
python-version: 3.11.x
27-
- name: Poetry cache
28-
uses: actions/cache@v3
29-
with:
30-
path: ~/.cache/pypoetry
31-
key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
31+
# - name: Poetry cache
32+
# uses: actions/cache@v3
33+
# with:
34+
# path: ~/.cache/pypoetry
35+
# key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
3236
- name: Install Poetry
3337
uses: snok/install-poetry@v1
3438
with:
@@ -48,7 +52,7 @@ jobs:
4852
mkdir /tmp/nltk_data;
4953
poetry run python -m nltk.downloader -d /tmp/nltk_data punkt;
5054
- name: Use venv
51-
run: source $VENV
55+
run: source .venv/bin/activate
5256
- name: Execute notebooks and check for errors
5357
run: bash ./.github/workflows/scripts/run_notebooks.sh ${{ matrix.notebook }}
5458

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Notebook Execution and Error Check
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch: # This enables manual triggering
8+
9+
jobs:
10+
install_from_hub:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Set up Python
14+
uses: actions/setup-python@v5
15+
with:
16+
python-version: 3.11.x
17+
- name: pip install from main
18+
run: pip install git+https://github.com/guardrails-ai/guardrails.git@main
19+
- name: Install PII validator
20+
run: guardrails hub install hub://guardrails/detect_pii
21+
- name: Verify PII validator is addressable
22+
run: echo 'from guardrails.hub import DetectPII' | python

.github/workflows/release_version.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
- name: Upload to PyPI
3232
env:
3333
PYPI_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
34-
run: poetry publish --build -u shreyar -p $PYPI_PASSWORD
34+
run: poetry publish --build -u __token__ -p $PYPI_PASSWORD

.github/workflows/scripts/update_notebook_matrix.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,4 @@ notebook_names="${notebook_names%,}]"
1616

1717
# find line that begins with "notebook:" and replace it with notebook: $notebook_names
1818
sed "s/notebook: \[.*\]/notebook: $notebook_names/" .github/workflows/examples_check.yml > .github/workflows/examples_check.yml.tmp
19-
mv .github/workflows/examples_check.yml.tmp .github/workflows/examples_check.yml
20-
21-
sed "s/notebook: \[.*\]/notebook: $notebook_names/" .github/workflows/ci.yml > .github/workflows/ci.yml.tmp
22-
mv .github/workflows/ci.yml.tmp .github/workflows/ci.yml
19+
mv .github/workflows/examples_check.yml.tmp .github/workflows/examples_check.yml

.isort.cfg

Lines changed: 0 additions & 7 deletions
This file was deleted.

CNAME

Lines changed: 0 additions & 1 deletion
This file was deleted.

CONTRIBUTING.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Follow these steps before committing your changes:
2020

2121
1. Ensure tests pass: `make test`
2222
2. Format your code: `make autoformat`
23-
3. Update documentation if needed. Docs are located in the `docs` directory. You can serve docs using `mkdocs serve`.
23+
3. Run static analysis: `make type`
24+
4. Update documentation if needed. Docs are located in the `docs` directory. You can serve docs using `mkdocs serve`.
2425

2526
### Optional: Pre-Commit Hooks
2627

@@ -38,13 +39,16 @@ Thank you for your contribution and happy coding!
3839

3940
## Documentation
4041

41-
Docs are served via mkdocs using the mkdocstring plugin. To serve docs locally, run the following
42+
Docs are served via docusaurus. To serve docs locally, run the following
4243

4344
```bash
4445
# install dependencies
45-
pip install -e ".[dev]";
46+
pip install -e ".[dev]"
4647

47-
# serve docs
48-
mkdocs serve;
48+
# install npm dependencies
49+
npm i
50+
51+
# serve the docs
52+
npm run start
4953
```
50-
then navigate to `localhost:8000` in your browser.
54+
then navigate to `localhost:3000` in your browser.

MANIFEST.in

Lines changed: 0 additions & 6 deletions
This file was deleted.

Makefile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
MKDOCS_SERVE_ADDR ?= localhost:8000 # Default address for mkdocs serve, format: <host>:<port>, override with `make docs-serve MKDOCS_SERVE_ADDR=<host>:<port>`
22

3+
# Extract major package versions for OpenAI and Pydantic
4+
OPENAI_VERSION_MAJOR := $(shell poetry run python -c 'import openai; print(openai.__version__.split(".")[0])')
5+
PYDANTIC_VERSION_MAJOR := $(shell poetry run python -c 'import pydantic; print(pydantic.__version__.split(".")[0])')
6+
7+
# Construct the typing command using only major versions
8+
TYPING_CMD := type-pydantic-v$(PYDANTIC_VERSION_MAJOR)-openai-v$(OPENAI_VERSION_MAJOR)
9+
310
autoformat:
411
poetry run black guardrails/ tests/
512
poetry run isort --atomic guardrails/ tests/
613
poetry run docformatter --in-place --recursive guardrails tests
714

15+
.PHONY: type
816
type:
9-
poetry run pyright guardrails/
17+
@make $(TYPING_CMD)
1018

1119
type-pydantic-v1-openai-v0:
1220
echo '{"exclude": ["guardrails/utils/pydantic_utils/v2.py", "guardrails/utils/openai_utils/v1.py"]}' > pyrightconfig.json

0 commit comments

Comments
 (0)