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
Release history Release notifications | RSS feed
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.9.tar.gz
(5.1 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file unitprompt-0.0.9.tar.gz.
File metadata
- Download URL: unitprompt-0.0.9.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
956fa09b1c6e3b33075a2c56785e9b80d5ee1d4fede835e02231088c6ed73d15
|
|
| MD5 |
760688d7c8e600f3448198e29a6aeba4
|
|
| BLAKE2b-256 |
c16870e8d9ec22570941a9eea548615e2e263977086353800222e19500feaa44
|
File details
Details for the file unitprompt-0.0.9-py3-none-any.whl.
File metadata
- Download URL: unitprompt-0.0.9-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
daf9c9a5aa7fa9021f360a9eaefebe780904bf0845886dc3a79ea42673e4f6b6
|
|
| MD5 |
b336d454588bdcf43e3df978c5deb62f
|
|
| BLAKE2b-256 |
43a3d7d587903657b31eecdc535864c584411e1a829cb82f6498eeea8b36a073
|