Skip to content
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

Add test for empty string on toxicity #142

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions langkit/tests/test_toxicity.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
from logging import getLogger
import whylogs as why
import pytest


TEST_LOGGER = getLogger(__name__)


@pytest.mark.load
def test_toxicity():
from langkit import toxicity # noqa
Expand All @@ -28,3 +32,34 @@ def test_toxicity_long_response(long_response):
text_schema = udf_schema()
profile = why.log(long_response, schema=text_schema).profile()
assert profile


@pytest.mark.load
def test_empty_toxicity():
from langkit import toxicity # noqa
from whylogs.experimental.core.udf_schema import udf_schema

text_schema = udf_schema()
test_prompt = "hi."
test_response = ""
test_message = {"prompt": test_prompt, "response": test_response}
profile = why.log(test_message, schema=text_schema).profile()
prompt_score = (
profile.view()
.get_column("prompt.toxicity")
.get_metric("distribution")
.to_summary_dict()["mean"]
)
response_score = (
profile.view()
.get_column("response.toxicity")
.get_metric("distribution")
.to_summary_dict()["mean"]
)

TEST_LOGGER.info(f"running toxicity metrics on {test_message}")
TEST_LOGGER.info(
f"prompt score is: {prompt_score} and response score is: {response_score}"
)
assert prompt_score < 0.1
assert response_score < 0.1