Skip to content

Commit e3cdc10

Browse files
zsimjeeirgolicShreyaRCalebCourierNefertiti  Rogers
authored
Dev (#299)
* Validators refactor (#214) * Pass metadata through guard, runner, to validator * Validator: Change interface - EventDetail => ValidationResult - (key, value, schema) => (value, metadata) * validators.Pydantic: New interface * validators.PydanticFieldValidator: New interface * validators: New interface for simple validators * validators: New interface for SQL-related validators * validators.Choice: New interface (pass schema through metadata) * validators.SimilarToDocument: New interface * validators.IsProfanityFree: New interface * validators.IsHighQualityTranslation: New interface * validators.EndsWith: New interface * validators.ExtractedSummarySentencesMatch: New interface * validators.ReadingTime: New interface * validators.ExtractiveSummary: New interface * validators.RemoveRedundantSentences: New interface * validators.SaliencyCheck: New interface * validators.QARelevanceLLMEval: New interface * format * Fix tests * validators.Extracted*: Change behavior, add test * validation.md: Hide Choice validator from docs * Avoid reassigning value when no validation occurs This is a bug in the main branch, which will be dealt with in a separate PR * ValidationResult.outcome: Fix literals * test_validators.test_summary_validators: Mock the embedding tests * bump version to v0.2.0-alpha.1 * Abstract validator running into ValidatorService (#228) * Crudely move field validation from datatypes/validators to ValidatorService * datatypes: validate => collect_validation * Remove unused params from collect_validation method signature, adjust logs * Remove Choice validator (handled by skeleton reask) * Fix embedding test import * Implement AsyncValidatorService, that runs multiprocess when guard is invoked asynchronously * test_async: Test multiprocessing * validator_service: Parallelize synchronous guard * format * test_guard: Test synchronous invocation multiprocessing * Run validators on the same field in parallel when possible * fixup tests * format * Add test for parallel validation on same field * Support calling chat models with chat history instead of single user message and instructions (#234) * Pass basemodel to sync and async runner calls (#221) * Pass basemodel to sync and async runner calls * remove model filters from using functions * json_utils: Handle value type error on skeleton check (#225) * [bug] support setting reasking instructions (#199) * add reask instructions * basic reasking instructions * schema: Remove templating functionality from instructions * Fix reask prompt compilation test * [minor] Fix rail tests * schema.get_reask_schema_and_prompt => get_reask_setup * Remove examples from json reask prompt (they are in instructions) * openai_completion_create: Add note on ignored instructions kwarg * test_python_rail: Adjust used constants to remove examples from prompt * constants: high_level_instructions => high_level_json_instructions * StringSchema: Set reask instructions to something basic * format --------- Co-authored-by: Rafael Irgolic <[email protected]> * make prompts optional in rail spec (#110) * make prompts and instructions optional * lint * enable sending chat history with guard call * fixing tests pt 1 * fixing tests pt 2 * fix tests * uncomment tests * remove temp files --------- Co-authored-by: rafael <[email protected]> * increment version * Add support and docs for cohere models (#237) * Add support and docs for cohere models * fix tests * fix list type * fixing list imports * fix tests for missing dependencies * fix tests * fix tests * fix bug where instructions are generated during reasking for completion models (#239) * Bug fixes in validator service (#243) * fix fn calling * functional tests with fixes in validator service * lint * add integration tests for string and pydantic with message history * autoformat --------- Co-authored-by: Caleb Courier <[email protected]> * Create schema-wise reask instructions (#245) * changes for setting and viewing custom reask templates * lint * version bump (#246) * init commit for string formatting changes * add formatting for instructions and prompt also * remove comments * Shreya/metadata bug fix (#259) * bug fix * fix tests * add provenance validators (#258) * Add provenance validators * fix prov v0 validator * cleanup --------- Co-authored-by: zsimjee <[email protected]> * version bump (#262) * linting fixes * bug fixes and autoformat * update import * update examples * allow passing api key as kwarg * lint fix * add api_base arg to embedding * lint fixes * change var name * bump version * version bump * updaate tests * lint fix * fix lint * lint fix * fix merge conflicts * updates for tests * update for passing unit tests and updates to examples * fix lint * add namespace changes for constants * lint fix * update last test * move out namespace template * lint * casting GUARDRAILS_PROCESS_COUNT to int * Remove `register_pydantic` and `script` tag (#280) * Remove `register_pydantic` decorator With failing test for nested pydantic validators * Remove script tag * Rewrite register_pydantic test into new Guard.from_pydantic * Remove script docs * Remove old pydantic docs * Remove unused imports (and format) * Docs: Validators refactor (#269) * start validators concept doc * finish validators content, sample google style docstring * mkdocs options * finish validator doc strings for key props and args, need to double check metadata * finish docs on metadata, separate validators and responses * autoformat * ignore line length on docstring * extra spaces * and -> an * update string formatting * update rail and outputs * fix prompt variables, escape prompt for langchain * update syntaxin docs, update constants in docstrings * lint fix * update syntax in notebook * fix syntax * String schema (#279) * add requirements.txt for setup * python native string schema * autoformat * lint fixes * descrition -> description * lint fix * update Rail classmethod name * JsonSchema.async_validate: Correctly instantiate SkeletonReask (#284) * Test Reasks w/ Message History (#247) * add reasks to message history tests * autoformat * == None -> is None * Choice discriminator change (#241) * Generate choice discriminator inside union instead of outside * Remove 'when' syntax from choice * test_schema_to_prompt: Dont test for choice transpilation * format * json_utils: Change verification_failed sentinel value from staticmethod to class * select_choice_based_on_action: Update for discriminator change * update outputs * update test * Full schema reask (#248) * Generate choice discriminator inside union instead of outside * Remove 'when' syntax from choice * test_schema_to_prompt: Dont test for choice transpilation * format * json_utils: Change verification_failed sentinel value from staticmethod to class * format * convert_pydantic_model_to_openai_fn: Drop extra fields * Implement full_schema_reask option in guard If using pydantic defaults to True, otherwise False * test_pydantic: Use full_schema_reask=False * guard: Fill out docstrings for __call__ and parse * run: Fail early on missing required metadata keys (#272) * prepend instructions to prompt (#281) * prepend instructions to prompt * lint, ignore venv --------- Co-authored-by: Shreya Rajpal <[email protected]> * Validators as functions (#249) * validators: Allow functions as validators * test functions as validators * test incorrect function validator * pydantic_utils: Validators are either classes or (validator, on_fail) tuples * pydantic_utils: Pydantic validators are reask validators * tests...pydantic_models: Change validator declarations to tuples * test_validators: Test tuple validator specifications * test_pydantic_utils: Fix test to access tuple * Fix kwargs issue while initialising Provenance validator (#288) * Fix kwargs issue while initialising Provenance validator * Add formatting * Caleb/test cov (#293) * add reasks to message history tests * autoformat * == None -> is None * start validator service unit tests * validate tests * start async validator unit tests * more tests * start more tests * more assertions * another test * fix tests * lint fixes * 0.2.0 Migration Guide (#291) * start migration guide * Outline * string format * 0-2-migration: Add pydantic instructions * 0-2-migration: Add choice change * langchain and string format * add regex * format * tab formatting * indentation * remove redundant section * validator updates --------- Co-authored-by: Rafael Irgolic <[email protected]> * Document field validation logs access (#286) * docs.logs: Add pointer to how to print logs * logs_utils: Refactor from dataclasses to pydantic * docs.logs: Simplify field validation logs access * Xml/Pydantic docs parity (#292) * chat models * still not working * select choice * extracting entities * bug free python plus bug fixes * no secrets example * valid sql and bug fix * vegan mac and cheese * trailing comma * valid chess move * translation * structured data * translation quality * remove script fix bug * lint fix * test coverage * merge cleanup branch * notebook updates * tweak prompt, remove interest_rates property * restructure files (#271) * start validators concept doc * finish validators content, sample google style docstring * mkdocs options * finish validator doc strings for key props and args, need to double check metadata * restructure files * finish docs on metadata, separate validators and responses * autoformat * ignore line length on docstring * extra spaces * and -> an * restructure leftnav WIP * install from gh, API ref * Add diag to guard * more guard skeleton * pydantic v1 * string schema * backoff/tenacity docs * last few tweaks * lint fix * fix mkdocs.yml merge * copy intro as index page for now * document __call__ vs parse * or -> at * formatting * format tabs * re-add migration guide, remove pydantic * fix string notation * Create examples_check.yml --------- Co-authored-by: Caleb Courier <[email protected]> * Num reask default (#295) * fix num_reasks defaulting * remove TODO * update rail string * Pass reask instructions for parsing (#296) * added custom reask instructions * fix tests * Docs restructure (#298) * start validators concept doc * finish validators content, sample google style docstring * mkdocs options * finish validator doc strings for key props and args, need to double check metadata * restructure files * finish docs on metadata, separate validators and responses * autoformat * ignore line length on docstring * extra spaces * and -> an * restructure leftnav WIP * install from gh, API ref * Add diag to guard * more guard skeleton * pydantic v1 * string schema * backoff/tenacity docs * last few tweaks * lint fix * fix mkdocs.yml merge * copy intro as index page for now * document __call__ vs parse * or -> at * formatting * format tabs * re-add migration guide, remove pydantic * fix string notation * Create examples_check.yml * tuple pydantic examples * add coverage for openai embeddings model selector * relocate embeddigns tests to the correct area * lint --------- Co-authored-by: Caleb Courier <[email protected]> * 0.2.0 version bump * lint version file * coverage * reask utils tests * lint fixes * json utils tests * lint fixes --------- Co-authored-by: rafael <[email protected]> Co-authored-by: Shreya Rajpal <[email protected]> Co-authored-by: Caleb Courier <[email protected]> Co-authored-by: Nefertiti Rogers <[email protected]> Co-authored-by: Nefertiti Rogers <[email protected]> Co-authored-by: Caleb Courier <[email protected]> Co-authored-by: Dmitry Matasov <[email protected]> Co-authored-by: Karan Acharya <[email protected]>
1 parent 9428a9b commit e3cdc10

File tree

166 files changed

+11126
-5195
lines changed

Some content is hidden

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

166 files changed

+11126
-5195
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: ubuntu-latest
2020
strategy:
2121
matrix:
22-
python-version: ['3.8', '3.9']
22+
python-version: ['3.8', '3.9', '3.10', '3.11']
2323

2424
steps:
2525
- uses: actions/checkout@v2
@@ -46,7 +46,8 @@ jobs:
4646
runs-on: ubuntu-latest
4747
strategy:
4848
matrix:
49-
python-version: ['3.8', '3.9']
49+
python-version: ['3.8', '3.9', '3.10', '3.11']
50+
dependencies: ['dev', 'full']
5051

5152
steps:
5253
- uses: actions/checkout@v2
@@ -63,15 +64,16 @@ jobs:
6364
- name: Install Dependencies
6465
run: |
6566
python -m pip install --upgrade pip
66-
make dev
67+
make ${{ matrix.dependencies }}
6768
6869
- name: Run Pytests
6970
run: |
7071
make test-cov
7172
7273
- name: Upload to codecov.io
73-
uses: codecov/codecov-action@v1
74+
uses: codecov/codecov-action@v3
7475
with:
76+
token: ${{ secrets.CODECOV_TOKEN }}
7577
file: ./coverage.xml
7678
flags: unittests
7779
name: codecov-umbrella

.github/workflows/examples_check.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Notebook Execution and Error Check
2+
3+
on:
4+
schedule:
5+
- cron: "0 0 * * *"
6+
workflow_dispatch: # This enables manual triggering
7+
8+
jobs:
9+
execute_notebooks:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout repository
14+
uses: actions/checkout@v2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: 3.x
20+
21+
- name: Install dependencies
22+
run: |
23+
pip install jupyter nbconvert
24+
25+
- name: Execute notebooks and check for errors
26+
run: |
27+
cd docs/examples
28+
for notebook in $(ls *.ipynb); do
29+
jupyter nbconvert --to notebook --execute "$notebook"
30+
if [ $? -ne 0 ]; then
31+
echo "Error found in $notebook"
32+
exit 1
33+
fi
34+
done

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ openai_api_key.txt
22
*__pycache__*
33
data/*
44
.vscode/*
5+
.venv/*
56
.DS_Store
67
*.ipynb_checkpoints/*
78
*.pyc
89
*.env
910
*.log
11+
*.venv
1012
settings.json
1113
site/*
1214
guardrails.log
@@ -16,4 +18,8 @@ dist/*
1618
*.rail_output*
1719
.idea/*
1820
.cache
19-
scratch/
21+
scratch/
22+
.coverage*
23+
test.db
24+
test.index
25+
htmlcov

CONTRIBUTING.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,16 @@ For convenience, consider [installing the pre-commit hooks](https://pre-commit.c
3535
5. Celebrate when your pull request is merged! Your changes will be available in the next Guardrails release.
3636

3737
Thank you for your contribution and happy coding!
38+
39+
## Documentation
40+
41+
Docs are served via mkdocs using the mkdocstring plugin. To serve docs locally, run the following
42+
43+
```bash
44+
# install dependencies
45+
pip install -e ".[dev]";
46+
47+
# serve docs
48+
mkdocs serve;
49+
```
50+
then navigate to `localhost:8000` in your browser.

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ test-basic:
1919
python -c "import guardrails.version as mversion"
2020

2121
test-cov:
22-
pytest tests/ --cov=./ --cov-report=xml
22+
pytest tests/ --cov=./guardrails/ --cov-report=xml
23+
24+
view-test-cov:
25+
pytest tests/ --cov=./guardrails/ --cov-report html && open htmlcov/index.html
2326

2427
docs-serve:
2528
mkdocs serve -a $(MKDOCS_SERVE_ADDR)
@@ -30,4 +33,7 @@ docs-deploy:
3033
dev:
3134
pip install -e ".[dev]"
3235

36+
full:
37+
pip install -e ".[all]"
38+
3339
all: autoformat lint docs test

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ Using `RAIL`, we:
105105
<prompt>
106106
Explain what a bank run is in a tweet.
107107

108-
@xml_prefix_prompt
108+
${gr.xml_prefix_prompt}
109109

110-
{output_schema}
110+
${output_schema}
111111

112-
@json_suffix_prompt_v2_wo_none
112+
${gr.json_suffix_prompt_v2_wo_none}
113113
</prompt>
114114
</rail>
115115
```

0 commit comments

Comments
 (0)