-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom configuration example with the new langkit/container api
- Loading branch information
Showing
11 changed files
with
3,890 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,6 @@ | ||
# FROM whylabs/whylogs:py-llm-1.0.1 | ||
FROM whylabs/whylogs:py-llm-latest | ||
|
||
# Copy our custom config code | ||
COPY ./whylogs_config /opt/whylogs-container/whylogs_container/whylogs_config/ | ||
|
This file contains 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,46 @@ | ||
.PHONY: help requirements build run all clean lint lint-fix format format-fix fix test | ||
|
||
CONTAINER_NAME = langkit_configuration_example | ||
|
||
all: build | ||
|
||
install: | ||
poetry install | ||
|
||
build: | ||
docker build --platform=linux/amd64 . -t $(CONTAINER_NAME) | ||
|
||
test: | ||
poetry run pytest -vvv ./test | ||
|
||
run: | ||
docker run -it --platform=linux/amd64 --rm -p 127.0.0.1:8000:8000 --env-file local.env $(CONTAINER_NAME) | ||
|
||
debug: | ||
docker run -it --platform=linux/amd64 --entrypoint /bin/bash $(CONTAINER_NAME) | ||
|
||
clean: | ||
rm -rf requirements.txt | ||
|
||
lint: ## Check for type issues with pyright | ||
@{ echo "Running pyright\n"; poetry run pyright; PYRIGHT_EXIT_CODE=$$?; } ; \ | ||
{ echo "\nRunning ruff check\n"; poetry run ruff check; RUFF_EXIT_CODE=$$?; } ; \ | ||
exit $$(($$PYRIGHT_EXIT_CODE + $$RUFF_EXIT_CODE)) | ||
|
||
lint-fix: | ||
poetry run ruff check --fix | ||
|
||
format: ## Check for formatting issues | ||
poetry run ruff format --check | ||
|
||
format-fix: ## Fix formatting issues | ||
poetry run ruff format | ||
|
||
fix: lint-fix format-fix ## Fix all linting and formatting issues | ||
|
||
help: ## Show this help message. | ||
@echo 'usage: make [target] ...' | ||
@echo | ||
@echo 'targets:' | ||
@egrep '^(.+)\:(.*) ##\ (.+)' ${MAKEFILE_LIST} | sed -s 's/:\(.*\)##/: ##/' | column -t -c 2 -s ':#' | ||
|
This file contains 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,101 @@ | ||
# Custom Langkit Container | ||
|
||
Sample project that demonstrates how to build a custom container based on Langkit that performs prompt/response validation and profiling | ||
with WhyLabs. | ||
|
||
## Setup | ||
|
||
Make sure you have [poetry](https://python-poetry.org/) and docker installed. If you want to use your own model id in this demo then make | ||
sure to update `whylogs_config/config.yaml` with your model id. | ||
|
||
```bash | ||
# If you're just running through the demo, you don't need the dev dependencies | ||
poetry install --without-dev --no-root | ||
``` | ||
|
||
|
||
|
||
## Building | ||
|
||
Build the docker container by using make. This will create a container tagged `custom-llm-container`. | ||
|
||
```bash | ||
make | ||
``` | ||
|
||
## Running | ||
|
||
```bash | ||
make run | ||
``` | ||
|
||
With a `local.env` file with your WhyLabs credentials. | ||
|
||
``` | ||
# Generated at https://hub.whylabsapp.com/settings/access-tokens | ||
WHYLABS_API_KEY=<api key> | ||
CONTAINER_PASSWORD=password | ||
# Set based on your model type in WhyLabs. Daily is the default. | ||
DEFAULT_WHYLABS_DATASET_CADENCE=DAILY | ||
# Upload profiles every five minutes | ||
DEFAULT_WHYLABS_UPLOAD_CADENCE=M | ||
DEFAULT_WHYLABS_UPLOAD_INTERVAL=5 | ||
``` | ||
|
||
## Making Requests | ||
|
||
When the container is running, visit `http://localhost:8000/docs` (if you're running locally) for endpoint documentation and request | ||
snippets. The [llm validate](http://localhost:8000/docs#/default/validate_llm_validate_llm_post) endpoint is the one you probably want to | ||
use. | ||
|
||
Here are some sample requests that will trigger the validation rules that the container is configured for. Requests will have a 200 response | ||
code when no validation are triggered, and a 400 when at least one is triggered. The response is a report of failed validations like the | ||
following. | ||
|
||
```json | ||
{ | ||
"failures": [ | ||
{ | ||
"prompt_id": "0085d3ff-8482-4e08-8e16-16dab8d5a2d1", | ||
"validator_name": "textstat_validator", | ||
"failed_metric": "textstat_prompt", | ||
"value": "201", | ||
"timestamp": null, | ||
"is_valid": false | ||
} | ||
] | ||
} | ||
``` | ||
|
||
### Response Toxicity | ||
|
||
```bash | ||
curl -X 'POST' -H "X-API-Key: password" -H "Content-Type: application/octet-stream" 'http://localhost:8000/validate/llm' --data-raw '{ | ||
"datasetId": "model-124", | ||
"prompt": "Hi there!", | ||
"response": "Thats a stupid prompt." | ||
}' | ||
``` | ||
|
||
### Prompt Toxicity | ||
|
||
```bash | ||
curl -X 'POST' -H "X-API-Key: password" -H "Content-Type: application/octet-stream" 'http://localhost:8000/validate/llm' --data-raw '{ | ||
"datasetId": "model-124", | ||
"prompt": "This chat sucks.", | ||
"response": "Im sorry you feel that way." | ||
}' | ||
``` | ||
|
||
### Character Count Exceeded | ||
|
||
```bash | ||
curl -X 'POST' -H "X-API-Key: password" -H "Content-Type: application/octet-stream" 'http://localhost:8000/validate/llm' --data-raw '{ | ||
"datasetId": "model-124", | ||
"prompt": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | ||
"response": "Im sorry you feel that way." | ||
}' | ||
|
||
``` |
This file contains 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,12 @@ | ||
WHYLABS_API_KEY=vRLv6grHgg.hDbeVjN6k49R3Ii4durZ0bjRyuTzFeE51zqOuDIzZcG5F6zy09mD4:org-JpsdM6 | ||
CONTAINER_PASSWORD=password | ||
|
||
# Set based on your model type. Daily is the default. | ||
DEFAULT_WHYLABS_DATASET_CADENCE=DAILY | ||
|
||
# Upload profiles every five minutes | ||
DEFAULT_WHYLABS_UPLOAD_CADENCE=M | ||
DEFAULT_WHYLABS_UPLOAD_INTERVAL=5 | ||
|
||
LOG_LEVEL=DEBUG | ||
FAIL_STARTUP_WITHOUT_CONFIG=True |
Oops, something went wrong.