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.7.tar.gz (5.0 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.7-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: unitprompt-0.0.7.tar.gz
  • Upload date:
  • Size: 5.0 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.7.tar.gz
Algorithm Hash digest
SHA256 a0a0fe5a400f8fa8b933f09531371a92027bc35cc0c985a46595042fd0e63e07
MD5 f0292d4e67715d0b0ce95c3ef87604b1
BLAKE2b-256 3c1d50e868408826c5bbdb7444caccd558d9ce562edce9e43c97e795a386956d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: unitprompt-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 8.1 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0815aab4a2b10c7b5a2187bbb1cdfac5c06d2d3349afb7680b730c4737fb22e0
MD5 47641a0e12f63742781b774f36ce72c7
BLAKE2b-256 f78189c77a35a951732b56945545c6c6d2d53cd55b5d29c07496d578e8bb089b

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