Skip to content

Commit

Permalink
Merge pull request #808 from guardrails-ai/0.4.5-dev
Browse files Browse the repository at this point in the history
v0.4.5
  • Loading branch information
zsimjee authored Jun 6, 2024
2 parents f45bb83 + e7c5517 commit 3265a1c
Show file tree
Hide file tree
Showing 49 changed files with 3,464 additions and 1,793 deletions.
17 changes: 9 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
branches:
- main
- dev
- feat/*

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down Expand Up @@ -49,8 +50,8 @@ jobs:
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
pydantic-version: ["1.10.9", "2.4.2"]
openai-version: ["1.30.1"]
pydantic-version: ["==1.10.9", ">=2.x"]
openai-version: [">=1.x"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand All @@ -71,8 +72,8 @@ jobs:
# TODO: fix errors so that we can run `make dev` instead
run: |
make full
poetry run pip install pydantic==${{ matrix.pydantic-version }}
poetry run pip install openai==${{ matrix.openai-version }}
poetry run pip install "pydantic${{ matrix.pydantic-version }}"
poetry run pip install "openai${{ matrix.openai-version }}"
- name: Static analysis with pyright
run: |
Expand All @@ -86,8 +87,8 @@ jobs:
# 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.4.2"]
openai-version: ["1.30.1"]
pydantic-version: ["==1.10.9", ">=2.x"]
openai-version: [">=1.x"]
steps:
- uses: actions/checkout@v4

Expand All @@ -113,8 +114,8 @@ jobs:
- name: Install Dependencies
run: |
make ${{ matrix.dependencies }}
poetry run pip install pydantic==${{ matrix.pydantic-version }}
poetry run pip install openai==${{ matrix.openai-version }}
poetry run pip install "pydantic${{ matrix.pydantic-version }}"
poetry run pip install "openai${{ matrix.openai-version }}"
- name: Run Pytests
run: |
Expand Down
44 changes: 23 additions & 21 deletions .github/workflows/examples_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
# this line is automatically generated by the script in .github/workflows/scripts/update_notebook_matrix.sh
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"]
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","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"]
env:
COHERE_API_KEY: ${{ secrets.COHERE_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
Expand All @@ -24,6 +24,9 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Create .guardrailsrc
run: |
echo 'id="SYSTEM TESTING"' > ~/.guardrailsrc
Expand All @@ -32,31 +35,30 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: 3.11.x
# - name: Poetry cache
# uses: actions/cache@v3
# with:
# path: ~/.cache/pypoetry
# key: poetry-cache-${{ runner.os }}-${{ steps.setup_python.outputs.python-version }}-${{ env.POETRY_VERSION }}
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Install dependencies
run: |
make full;
poetry add "openai>=1.2.4" jupyter nbconvert cohere==5.3.2;
- name: Check for pypdfium2
run: poetry run pip show pypdfium2
# Setup Virtual Environment
python3 -m venv ./.venv
source .venv/bin/activate
# Install the current branch
pip install .
# Install extra stuff for notebook runs
pip install "huggingface_hub[cli]" jupyter nbconvert cohere==5.3.2
pip install nltk
- name: Huggingface Hub Login
run: poetry run huggingface-cli login --token $HUGGINGFACE_API_KEY
run: |
source .venv/bin/activate
huggingface-cli login --token $HUGGINGFACE_API_KEY
- name: download nltk data
run: |
source .venv/bin/activate
mkdir /tmp/nltk_data;
poetry run python -m nltk.downloader -d /tmp/nltk_data punkt;
- name: Use venv
run: source .venv/bin/activate
python -m nltk.downloader -d /tmp/nltk_data punkt;
- name: Execute notebooks and check for errors
run: bash ./.github/workflows/scripts/run_notebooks.sh ${{ matrix.notebook }}
run: |
source .venv/bin/activate
bash ./.github/workflows/scripts/run_notebooks.sh ${{ matrix.notebook }}
2 changes: 1 addition & 1 deletion .github/workflows/install_from_hub.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Notebook Execution and Error Check
name: Install from Hub

on:
push:
Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/scripts/run_notebooks.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/bin/bash
export NLTK_DATA=/tmp/nltk_data;

# Remove the local guardrails directory and use the installed version
rm -rf ./guardrails

# Navigate to notebooks
cd docs/examples

# Get the notebook name from the matrix variable
Expand All @@ -10,10 +14,12 @@ notebook="$1"
invalid_notebooks=("valid_chess_moves.ipynb" "llamaindex-output-parsing.ipynb" "competitors_check.ipynb")
if [[ ! " ${invalid_notebooks[@]} " =~ " ${notebook} " ]]; then
echo "Processing $notebook..."
poetry run jupyter nbconvert --to notebook --execute "$notebook"
# poetry run jupyter nbconvert --to notebook --execute "$notebook"
jupyter nbconvert --to notebook --execute "$notebook"
if [ $? -ne 0 ]; then
echo "Error found in $notebook"
echo "Error in $notebook. See logs for details." >> errors.txt
exit 1
fi
fi

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ precommit:
# pytest -x -q --no-summary
pyright guardrails/
make lint
./github/workflows/scripts/update_notebook_matrix.sh
./.github/workflows/scripts/update_notebook_matrix.sh
25 changes: 10 additions & 15 deletions docs/examples/bug_free_python_code.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Note: you may need to restart the kernel to use updated packages.\n",
"Note: you may need to restart the kernel to use updated packages.\n",
"Installing hub:\u001b[35m/\u001b[0m\u001b[35m/reflex/\u001b[0m\u001b[95mvalid_python...\u001b[0m\n",
"✅Successfully installed reflex/valid_python!\n",
"\n",
Expand All @@ -47,15 +45,12 @@
}
],
"source": [
"%pip install guardrails-ai -q\n",
"%pip install pydantic -q\n",
"\n",
"!guardrails hub install hub://reflex/valid_python --quiet"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -93,7 +88,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -111,7 +106,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -128,7 +123,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -209,7 +204,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -239,7 +234,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 9,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -284,7 +279,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 10,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -356,7 +351,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 11,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -398,7 +393,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.0"
"version": "3.11.9"
},
"orig_nbformat": 4,
"vscode": {
Expand Down
Loading

0 comments on commit 3265a1c

Please sign in to comment.