Skip to main content

A custom pytest matcher that helps you test prompts

Project description

unitprompt - pytest

unitprompt is a pytest extension that provides custom matchers for unit testing LLM processes. This library helps ensure that your large language model (LLM) outputs are validated correctly in your tests.

Installation

pip install unitprompt

Usage

import pytest
from unitprompt import assert_is_latex, assert_conciseness
# mark as async because assert_conciseness requires an LLM call
@pytest.mark.asyncio
async def test_conciseness_fail():
    
    long_text = """
    First of all, you need to learn about the concept of sums. A sum is the result of adding two numbers together.
    This can be done in a variety of ways. There is the traditional method of writing the numbers one on top of the other and adding them together.

    In this instance you can take the first number, 3, and write it down. Then you can take the second number, 4, and write it down below the first number. You can then add the two numbers together to get the sum of 7.
    """
    
    with pytest.raises(pytest.fail.Exception):
        await assert_conciseness(long_text)

def test_uses_latex():
    latex_string = r'\\begin{document}\nHello, World!\n\\end{document}'
    assert_is_latex(latex_string)
    
def test_uses_latex_fail():
    with pytest.raises(pytest.fail.Exception):
        assert_is_latex(r'Plain text without any LaTeX')

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

unitprompt-0.0.8.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

unitprompt-0.0.8-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file unitprompt-0.0.8.tar.gz.

File metadata

  • Download URL: unitprompt-0.0.8.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1025-azure

File hashes

Hashes for unitprompt-0.0.8.tar.gz
Algorithm Hash digest
SHA256 9d48796a3dd2b22628091e9855f876cbdf4eadb5b219d86cfe0dcc7caace036d
MD5 e8ad84063a03b95454974fc6e33dafc5
BLAKE2b-256 92634c44b21aafbdeb39085c11a995e40fc9408677b5ea24d26c0ea16259ae30

See more details on using hashes here.

File details

Details for the file unitprompt-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: unitprompt-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.14 Linux/6.5.0-1025-azure

File hashes

Hashes for unitprompt-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 a4d0e95321b46b5b87f43afcdadfe2ff09631c9699758f8124fe4637e3187334
MD5 06e8c42be32999ff157d5f89b3724eef
BLAKE2b-256 81396313e150bb8ac8a6044d760aa49e00ab0c39612e16e6e15cabe47b9251ea

See more details on using hashes here.

Supported by

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