Skip to main content

Make sure AI model outputs are consistent

Project description

tests

release

consisTent is a full blows testing framework for prompts. The goal of consisTent is to create reproducible tests for LLM based applications regardless of the FM used.

Installation

pip install consistent

Concepts

consisTent comes with 2 types of validators (testers)

syntactic validators

This type of validators is used to do static assertions of the LLM output. for example validating if the output is in a certain JSON format and assert the schema. You can also use syntactic validators to assert something is a valid piece of code (JS or Python are supported at the moment)

Syntactic validators are used to assert the FORM of the response

example

consisTent.JsValidator().validate('console.log("Im a JS program!")')

consisTent.PyValidator().validate('print("Im a python program!")')

consisTent.JsonValidator().validate('"question": {"is this a valid JSON?"}')

syntactic validators

This type of validators is used to assert the quality of the response with more "soft" parameters for example, check if something is factually correct, check for hallucinations, check for labels like "funny"/"interesting" etc... another type of semantic validator is the semantic consistency validator where you provide a seed of validated input and a threshold, and the test will assert the semantic distance of the new output from the seed cluster.

Semantic validators are used to assert the CONTENT of the response

example

import consisTent

seed = [
    "the cat sat on the mat",
    "the feline layed on the carpet",
]


consisTent.ConsistencyValidator(
    seed_size=2,
    consistency_threshold=0.5,
).validate(
    seed=seed,
    model_output="the dog sat on the mat",
)

Label Test

OPENAI_KEY = "XXXXXXXXXXXXXXX"

consisTent.LabelsValidator(openai_key=OPENAI_KEY).validate(
    labels=[
        "funny",
        "short",
        "about rabbits",
    ],
    model_output="What do you call a rabbit that tells jokes? A funny bunny!",
)

facts validation

OPENAI_KEY = "XXXXXXXXXXXXXXX"

consisTent.FactsValidator(openai_key=OPENAI_KEY).validate(
    facts=["this car weighs 1000KG"],
    model_output="I can lift this car",
)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

consistent-0.0.9.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

consistent-0.0.9-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file consistent-0.0.9.tar.gz.

File metadata

  • Download URL: consistent-0.0.9.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for consistent-0.0.9.tar.gz
Algorithm Hash digest
SHA256 ca161f06541688dac3ad4cbb3eac4f61b7ac640265454be993ca3c9d2a5080bd
MD5 a756d773d8c229d9d0753d97070aba61
BLAKE2b-256 9694504e6e79c1498daa6a9109ecd45af0e87fa4476c10eba0e1242fb298d4d9

See more details on using hashes here.

File details

Details for the file consistent-0.0.9-py3-none-any.whl.

File metadata

  • Download URL: consistent-0.0.9-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for consistent-0.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 584fec43e748c56924415fe9dbd07b4019f1c03a50f9aa49f218a645e9dd5033
MD5 57f799ca09f4ccbe26efa103e9246460
BLAKE2b-256 2291587db457f4ea9f2462d5fe3d3cb6b58194aca2e004e50e66217df6222439

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page