-
Notifications
You must be signed in to change notification settings - Fork 2
Add Guardrails API endpoints, validator configs and test infrastructure #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
50ab489
Setup repo and added bearer token based auth. #2
rkritika1508 a85ed62
Added .env.example file and updated the documentation #2
rkritika1508 e792dfa
Resolved comments #2
rkritika1508 1c6e74e
updated env in config #2
rkritika1508 3f1d2b1
Added validators
rkritika1508 a55d032
Added 3 validators and input guardrail api
rkritika1508 464da1c
Removed validator_cls from validator config and simplified code
rkritika1508 7a57b94
Fixed BanList issue and refactored code
rkritika1508 7043a5e
feat: add GET endpoint for validatorS
dennyabrain 518e066
Refactored API to get list of all validators
rkritika1508 d7828b2
Added docker setup
rkritika1508 a5a1bf1
Resolved comments
rkritika1508 e89ae6a
Fixed few comments
rkritika1508 f306ce9
Removed redundant files and fixed comments
rkritika1508 4b88f4b
Added unit tests
rkritika1508 56c0d32
feat: configure alembic; add db models and migration for request and …
dennyabrain a6ced05
Added more unit tests
rkritika1508 9183140
Made minor fixes
rkritika1508 8e0b61d
Added Guardrails AI setup steps in backend readme
rkritika1508 00f2f8a
Added integration tests and refactored file structure
rkritika1508 954d939
Added more integration tests
rkritika1508 8b24c43
Addressed documentation comments
rkritika1508 cd95c8d
Updated test scripts
rkritika1508 d66de4b
chore: testing session data in controller
dennyabrain 8785bb5
feat: add crud class for request log (wip)
dennyabrain 76a05cf
fixed env file
rkritika1508 9bffe5c
feat: database changes to log request and response to /input endpoint
dennyabrain 01b10f7
feat: add db logging for /output
dennyabrain ea4c348
updated config
rkritika1508 41bb7a0
Fixed unit tests based on new schema
rkritika1508 0847c37
Updated gitignore
rkritika1508 3932717
Updated PII remover
rkritika1508 dc3024d
Resolved comments
rkritika1508 e06dc86
Resolved comment
rkritika1508 f6df183
Updated unit tests
rkritika1508 4c64be5
Updated env fetching
rkritika1508 f5bb4be
updated route
rkritika1508 42f1817
updated setup
rkritika1508 86834a8
Resolved comments
rkritika1508 415c02b
updated ut
rkritika1508 966c0f3
Addressed comments
rkritika1508 5fbaa53
Resolved comment
rkritika1508 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| DOMAIN=localhost | ||
|
|
||
| ENVIRONMENT=development | ||
|
|
||
| PROJECT_NAME="Kaapi-Guardrails" | ||
| STACK_NAME=Kaapi-Guardrails | ||
|
|
||
| # API Base URL for cron scripts (defaults to http://localhost:8000 if not set) | ||
| API_BASE_URL=http://localhost:8000 | ||
|
|
||
| # Postgres | ||
| POSTGRES_SERVER=localhost | ||
| POSTGRES_PORT=5432 | ||
| POSTGRES_DB=kaapi-guardrails | ||
| POSTGRES_USER=postgres | ||
| POSTGRES_PASSWORD=postgres | ||
|
|
||
| SENTRY_DSN= | ||
|
|
||
| # Configure these with your own Docker registry images | ||
|
|
||
| DOCKER_IMAGE_BACKEND=kaapi-guardrails-backend | ||
|
|
||
| # Callback Timeouts (in seconds) | ||
| CALLBACK_CONNECT_TIMEOUT=3 | ||
| CALLBACK_READ_TIMEOUT=10 | ||
|
|
||
| # require as a env if you want to use doc transformation | ||
| OPENAI_API_KEY="<ADD-KEY>" | ||
| GUARDRAILS_HUB_API_KEY="<ADD-KEY>" | ||
| AUTH_TOKEN="<ADD-TOKEN>" | ||
rkritika1508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| DOMAIN=localhost | ||
rkritika1508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ENVIRONMENT=testing | ||
|
|
||
| PROJECT_NAME="Kaapi-Guardrails" | ||
| STACK_NAME=Kaapi-Guardrails | ||
|
|
||
| # API Base URL for cron scripts (defaults to http://localhost:8000 if not set) | ||
| API_BASE_URL=http://localhost:8000 | ||
|
|
||
| # Postgres | ||
| POSTGRES_SERVER=localhost | ||
| POSTGRES_PORT=5432 | ||
| POSTGRES_DB=kaapi-guardrails | ||
| POSTGRES_USER=postgres | ||
| POSTGRES_PASSWORD=postgres | ||
rkritika1508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| SENTRY_DSN= | ||
|
|
||
| # Configure these with your own Docker registry images | ||
|
|
||
| DOCKER_IMAGE_BACKEND=kaapi-guardrails-backend | ||
|
|
||
| # Callback Timeouts (in seconds) | ||
| CALLBACK_CONNECT_TIMEOUT=3 | ||
| CALLBACK_READ_TIMEOUT=10 | ||
|
|
||
| # require as a env if you want to use doc transformation | ||
| OPENAI_API_KEY="<ADD-KEY>" | ||
| GUARDRAILS_HUB_API_KEY="<ADD-KEY>" | ||
| AUTH_TOKEN="<ADD-TOKEN>" | ||
rkritika1508 marked this conversation as resolved.
Show resolved
Hide resolved
rkritika1508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| DOMAIN=localhost | ||
|
|
||
| ENVIRONMENT=testing | ||
|
|
||
| PROJECT_NAME="Kaapi-Guardrails" | ||
| STACK_NAME=Kaapi-Guardrails | ||
|
|
||
| # API Base URL for cron scripts (defaults to http://localhost:8000 if not set) | ||
| API_BASE_URL=http://localhost:8000 | ||
|
|
||
| # Postgres | ||
| POSTGRES_SERVER=localhost | ||
| POSTGRES_PORT=5432 | ||
| POSTGRES_DB=kaapi-guardrails | ||
| POSTGRES_USER=postgres | ||
| POSTGRES_PASSWORD=postgres | ||
|
|
||
| SENTRY_DSN= | ||
|
|
||
| # Configure these with your own Docker registry images | ||
|
|
||
| DOCKER_IMAGE_BACKEND=kaapi-guardrails-backend | ||
|
|
||
| # Callback Timeouts (in seconds) | ||
| CALLBACK_CONNECT_TIMEOUT=3 | ||
| CALLBACK_READ_TIMEOUT=10 | ||
|
|
||
| # require as a env if you want to use doc transformation | ||
| OPENAI_API_KEY="<ADD-KEY>" | ||
| GUARDRAILS_HUB_API_KEY="<ADD-KEY>" | ||
| AUTH_TOKEN="<ADD-TOKEN>" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| __pycache__ | ||
| app.egg-info | ||
| *.pyc | ||
| .mypy_cache | ||
| .coverage | ||
| htmlcov | ||
| .cache | ||
| .venv | ||
| .DS_Store | ||
| .env | ||
| .env.test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,84 @@ | ||
| # kaapi-guardrails | ||
| A repo for our experiments with Guardrails so can be integrated with Kaapi | ||
|
|
||
| # Kaapi Guardrails | ||
|
|
||
| [](https://www.gnu.org/licenses/agpl-3.0) | ||
|  | ||
|  | ||
| [](https://img.shields.io/github/commit-activity/m/ProjectTech4DevAI/kaapi-guardrails) | ||
rkritika1508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ## Pre-requisites | ||
|
|
||
| - [docker](https://docs.docker.com/get-started/get-docker/) Docker | ||
| - [uv](https://docs.astral.sh/uv/) for Python package and environment management. | ||
|
|
||
rkritika1508 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ## Project Setup | ||
|
|
||
| You can **just fork or clone** this repository and use it as is. | ||
|
|
||
| ✨ It just works. ✨ | ||
|
|
||
| ### Configure | ||
|
|
||
| Create env file using example file | ||
|
|
||
| ```bash | ||
| cp .env.example .env | ||
| ``` | ||
|
|
||
| You can then update configs in the `.env` files to customize your configurations. | ||
|
|
||
| ⚠️ Some services depend on these environment variables being set correctly. Missing or invalid values may cause startup issues. | ||
|
|
||
| ## Bootstrap & development mode | ||
|
|
||
| You have two options to start this dockerized setup, depending on whether you want to reset the database: | ||
| ### Option A: Run migrations & seed data (will reset DB) | ||
|
|
||
| Use the prestart profile to automatically run database migrations and seed data. | ||
| This profile also resets the database, so use it only when you want a fresh start. | ||
| ```bash | ||
| docker compose --profile prestart up | ||
| ``` | ||
|
|
||
| ### Option B: Start normally without resetting DB | ||
|
|
||
| If you don't want to reset the database, start the project directly: | ||
| ```bash | ||
| docker compose watch | ||
| ``` | ||
| This will start all services in watch mode for development — ideal for local iterations. | ||
|
|
||
| ### Rebuilding Images | ||
|
|
||
| ```bash | ||
| docker compose up --build -d | ||
| ``` | ||
|
|
||
| This is also necessary when: | ||
| - Dependencies change in `pyproject.toml` or `uv.lock` | ||
| - You modify Dockerfile configurations | ||
| - Changes aren't being reflected in the running containers | ||
|
|
||
| ## Backend Development | ||
|
|
||
| Backend docs: [backend/README.md](./backend/README.md). | ||
|
|
||
| ## Deployment | ||
|
|
||
| Deployment docs: [deployment.md](./deployment.md). | ||
|
|
||
| ## Development | ||
|
|
||
| General development docs: [development.md](./development.md). | ||
|
|
||
| This includes using Docker Compose, custom local domains, `.env` configurations, etc. | ||
|
|
||
| ## Release Notes | ||
|
|
||
| Check the file [release-notes.md](./release-notes.md). | ||
|
|
||
| ## Credits | ||
|
|
||
| This project was created using [full-stack-fastapi-template](https://github.com/fastapi/full-stack-fastapi-template). A big thank you to the team for creating and maintaining the template!!! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| FROM python:3.10 | ||
|
|
||
| ENV PYTHONUNBUFFERED=1 | ||
|
|
||
| WORKDIR /app/ | ||
|
|
||
| # Install uv | ||
| # Ref: https://docs.astral.sh/uv/guides/integration/docker/#installing-uv | ||
| COPY --from=ghcr.io/astral-sh/uv:0.5.11 /uv /uvx /bin/ | ||
|
|
||
| # Place executables in the environment at the front of the path | ||
| # Ref: https://docs.astral.sh/uv/guides/integration/docker/#using-the-environment | ||
| ENV PATH="/app/.venv/bin:$PATH" | ||
|
|
||
| # Compile bytecode | ||
| # Ref: https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode | ||
| ENV UV_COMPILE_BYTECODE=1 | ||
|
|
||
| # uv Cache | ||
| # Ref: https://docs.astral.sh/uv/guides/integration/docker/#caching | ||
| ENV UV_LINK_MODE=copy | ||
|
|
||
| # Install dependencies | ||
| # Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| --mount=type=bind,source=uv.lock,target=uv.lock \ | ||
| --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | ||
| uv sync --frozen --no-install-project | ||
|
|
||
| ENV PYTHONPATH=/app | ||
| RUN apt-get update && apt-get install -y jq && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| COPY ./scripts /app/scripts | ||
| RUN chmod +x /app/scripts/*.sh | ||
|
|
||
| COPY ./pyproject.toml ./uv.lock ./alembic.ini /app/ | ||
|
|
||
| COPY ./app /app/app | ||
| COPY ./tests /app/tests | ||
|
|
||
| # Sync the project | ||
| # Ref: https://docs.astral.sh/uv/guides/integration/docker/#intermediate-layers | ||
| RUN --mount=type=cache,target=/root/.cache/uv \ | ||
| uv sync | ||
|
|
||
| # ------------------------------- | ||
| # Entrypoint (runtime setup) | ||
| # ------------------------------- | ||
| ENTRYPOINT ["/app/scripts/entrypoint.sh"] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.