pytest-llm-confidence 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pytest_llm_confidence-0.1.0/LICENSE +21 -0
- pytest_llm_confidence-0.1.0/PKG-INFO +113 -0
- pytest_llm_confidence-0.1.0/README.md +88 -0
- pytest_llm_confidence-0.1.0/pyproject.toml +36 -0
- pytest_llm_confidence-0.1.0/setup.cfg +4 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence/__init__.py +14 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence/plugin.py +213 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence.egg-info/PKG-INFO +113 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence.egg-info/SOURCES.txt +12 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence.egg-info/dependency_links.txt +1 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence.egg-info/entry_points.txt +2 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence.egg-info/requires.txt +2 -0
- pytest_llm_confidence-0.1.0/src/pytest_llm_confidence.egg-info/top_level.txt +1 -0
- pytest_llm_confidence-0.1.0/tests/test_plugin.py +140 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Proprioceptive AI, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytest-llm-confidence
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: pytest plugin that fails a test when a language model wasn't sure of its answer. Reads token probabilities: no judge model, no extra API cost, deterministic.
|
|
5
|
+
Author-email: Proprioceptive AI <logan@proprioceptiveai.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://proprioceptiveai.com/products.html
|
|
8
|
+
Project-URL: Repository, https://github.com/Loganwins/proprioceptive-confidence
|
|
9
|
+
Project-URL: Issues, https://github.com/Loganwins/proprioceptive-confidence/issues
|
|
10
|
+
Project-URL: Proprioceptive Lens, https://pypi.org/project/proprioceptive-lens/
|
|
11
|
+
Keywords: pytest,llm,testing,evals,confidence,logprobs,hallucination,ollama,ci
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: Pytest
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Software Development :: Testing
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pytest>=7
|
|
23
|
+
Requires-Dist: proprioceptive-confidence>=0.1.0
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# pytest-llm-confidence
|
|
27
|
+
|
|
28
|
+
**Fail a test when the model wasn't sure of its answer.**
|
|
29
|
+
|
|
30
|
+
Most LLM test tools ask a second model to judge the first, which costs money, adds latency and changes from run to
|
|
31
|
+
run. `pytest-llm-confidence` reads the model's own token probabilities instead: no judge model, no extra API cost,
|
|
32
|
+
and the same response always gets the same verdict.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
$ pip install pytest-llm-confidence
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
# test_answers.py
|
|
40
|
+
def test_capital(llm_confidence):
|
|
41
|
+
ans = llm_confidence.ask("What is the capital of Australia? Answer with one word.")
|
|
42
|
+
assert ans.text == "Canberra"
|
|
43
|
+
llm_confidence.assert_confident(ans) # fails if any word was below 80%
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
$ pytest
|
|
48
|
+
...
|
|
49
|
+
FAILED test_answers.py::test_capital - ShakyAnswerError: model wasn't sure of its answer
|
|
50
|
+
(shaky: 1 word(s) below 80%: "Syd" at 41%)
|
|
51
|
+
answer: 'Sydney'
|
|
52
|
+
"Syd" at 41% (alternatives: "Can" 38%)
|
|
53
|
+
|
|
54
|
+
============================ LLM confidence ============================
|
|
55
|
+
SHAKY test_answers.py::test_capital lowest "Syd" at 41%
|
|
56
|
+
1 check(s), 1 shaky
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
*(Illustrative output; real numbers depend on your model.)*
|
|
60
|
+
|
|
61
|
+
## Works with your model
|
|
62
|
+
|
|
63
|
+
- **Ollama 0.12+** (default): `llm_confidence.ask` talks to `http://127.0.0.1:11434`.
|
|
64
|
+
- **Any OpenAI-compatible server that returns logprobs**: OpenAI, vLLM, llama.cpp, LM Studio:
|
|
65
|
+
`pytest --llm-confidence-api openai --llm-confidence-base-url http://127.0.0.1:8000/v1 --llm-confidence-model my-model`
|
|
66
|
+
- **Responses you already have:** `assert_confident(response)` accepts OpenAI-style responses requested with
|
|
67
|
+
`logprobs=True`, Ollama responses requested with `"logprobs": true`, or `(token, logprob)` pairs.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from pytest_llm_confidence import assert_confident
|
|
71
|
+
|
|
72
|
+
def test_my_pipeline():
|
|
73
|
+
response = my_app.call_model("...", logprobs=True)
|
|
74
|
+
assert_confident(response, threshold=0.9)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Settings
|
|
78
|
+
|
|
79
|
+
| Option | ini key | Default |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `--llm-confidence-threshold` | `llm_confidence_threshold` | `0.8` |
|
|
82
|
+
| `--llm-confidence-model` | `llm_confidence_model` | `llama3.2` |
|
|
83
|
+
| `--llm-confidence-api` | `llm_confidence_api` | `ollama` |
|
|
84
|
+
| `--llm-confidence-base-url` | `llm_confidence_base_url` | `$OLLAMA_HOST` or `http://127.0.0.1:11434` |
|
|
85
|
+
| `--llm-confidence-double-check` | `llm_confidence_double_check` | off |
|
|
86
|
+
| `--llm-confidence-strict` | `llm_confidence_strict` | off (skip when the server is down) |
|
|
87
|
+
| `--llm-confidence-report PATH` | `llm_confidence_report` | none (writes JSON for CI artifacts) |
|
|
88
|
+
|
|
89
|
+
Per test: `@pytest.mark.llm_confidence(threshold=0.95, double_check=True)`.
|
|
90
|
+
|
|
91
|
+
**CI-safe by default:** if the model server can't be reached, `llm_confidence.ask` skips the test instead of failing
|
|
92
|
+
it. Pass `--llm-confidence-strict` to make that a failure.
|
|
93
|
+
|
|
94
|
+
**Double-check:** with `double_check=True`, a shaky short answer is re-asked in full and `ans.double_check.agrees`
|
|
95
|
+
tells you whether the answer held up.
|
|
96
|
+
|
|
97
|
+
## Testing without a model
|
|
98
|
+
|
|
99
|
+
`proprioceptive_confidence.testing.FakeModelServer` serves scripted token probabilities over Ollama's and OpenAI's
|
|
100
|
+
APIs, so you can test your confidence handling in CI without a GPU.
|
|
101
|
+
|
|
102
|
+
## What it can't do
|
|
103
|
+
|
|
104
|
+
A model can be wrong and certain. This plugin catches *shaky* answers, not confident mistakes, so keep your
|
|
105
|
+
correctness assertions too.
|
|
106
|
+
|
|
107
|
+
## Related
|
|
108
|
+
|
|
109
|
+
- **proprioceptive-confidence**: the library this plugin uses, with LangChain and LiteLLM adapters.
|
|
110
|
+
- **proprioceptive-mcp**: let Claude Code, Cursor and other agents ask your local model and see how sure it was.
|
|
111
|
+
- **Proprioceptive Lens**: see every word's confidence live in a local app: `pip install proprioceptive-lens`.
|
|
112
|
+
|
|
113
|
+
MIT licensed. From [Proprioceptive AI](https://proprioceptiveai.com).
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# pytest-llm-confidence
|
|
2
|
+
|
|
3
|
+
**Fail a test when the model wasn't sure of its answer.**
|
|
4
|
+
|
|
5
|
+
Most LLM test tools ask a second model to judge the first, which costs money, adds latency and changes from run to
|
|
6
|
+
run. `pytest-llm-confidence` reads the model's own token probabilities instead: no judge model, no extra API cost,
|
|
7
|
+
and the same response always gets the same verdict.
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
$ pip install pytest-llm-confidence
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
# test_answers.py
|
|
15
|
+
def test_capital(llm_confidence):
|
|
16
|
+
ans = llm_confidence.ask("What is the capital of Australia? Answer with one word.")
|
|
17
|
+
assert ans.text == "Canberra"
|
|
18
|
+
llm_confidence.assert_confident(ans) # fails if any word was below 80%
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
$ pytest
|
|
23
|
+
...
|
|
24
|
+
FAILED test_answers.py::test_capital - ShakyAnswerError: model wasn't sure of its answer
|
|
25
|
+
(shaky: 1 word(s) below 80%: "Syd" at 41%)
|
|
26
|
+
answer: 'Sydney'
|
|
27
|
+
"Syd" at 41% (alternatives: "Can" 38%)
|
|
28
|
+
|
|
29
|
+
============================ LLM confidence ============================
|
|
30
|
+
SHAKY test_answers.py::test_capital lowest "Syd" at 41%
|
|
31
|
+
1 check(s), 1 shaky
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
*(Illustrative output; real numbers depend on your model.)*
|
|
35
|
+
|
|
36
|
+
## Works with your model
|
|
37
|
+
|
|
38
|
+
- **Ollama 0.12+** (default): `llm_confidence.ask` talks to `http://127.0.0.1:11434`.
|
|
39
|
+
- **Any OpenAI-compatible server that returns logprobs**: OpenAI, vLLM, llama.cpp, LM Studio:
|
|
40
|
+
`pytest --llm-confidence-api openai --llm-confidence-base-url http://127.0.0.1:8000/v1 --llm-confidence-model my-model`
|
|
41
|
+
- **Responses you already have:** `assert_confident(response)` accepts OpenAI-style responses requested with
|
|
42
|
+
`logprobs=True`, Ollama responses requested with `"logprobs": true`, or `(token, logprob)` pairs.
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from pytest_llm_confidence import assert_confident
|
|
46
|
+
|
|
47
|
+
def test_my_pipeline():
|
|
48
|
+
response = my_app.call_model("...", logprobs=True)
|
|
49
|
+
assert_confident(response, threshold=0.9)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Settings
|
|
53
|
+
|
|
54
|
+
| Option | ini key | Default |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| `--llm-confidence-threshold` | `llm_confidence_threshold` | `0.8` |
|
|
57
|
+
| `--llm-confidence-model` | `llm_confidence_model` | `llama3.2` |
|
|
58
|
+
| `--llm-confidence-api` | `llm_confidence_api` | `ollama` |
|
|
59
|
+
| `--llm-confidence-base-url` | `llm_confidence_base_url` | `$OLLAMA_HOST` or `http://127.0.0.1:11434` |
|
|
60
|
+
| `--llm-confidence-double-check` | `llm_confidence_double_check` | off |
|
|
61
|
+
| `--llm-confidence-strict` | `llm_confidence_strict` | off (skip when the server is down) |
|
|
62
|
+
| `--llm-confidence-report PATH` | `llm_confidence_report` | none (writes JSON for CI artifacts) |
|
|
63
|
+
|
|
64
|
+
Per test: `@pytest.mark.llm_confidence(threshold=0.95, double_check=True)`.
|
|
65
|
+
|
|
66
|
+
**CI-safe by default:** if the model server can't be reached, `llm_confidence.ask` skips the test instead of failing
|
|
67
|
+
it. Pass `--llm-confidence-strict` to make that a failure.
|
|
68
|
+
|
|
69
|
+
**Double-check:** with `double_check=True`, a shaky short answer is re-asked in full and `ans.double_check.agrees`
|
|
70
|
+
tells you whether the answer held up.
|
|
71
|
+
|
|
72
|
+
## Testing without a model
|
|
73
|
+
|
|
74
|
+
`proprioceptive_confidence.testing.FakeModelServer` serves scripted token probabilities over Ollama's and OpenAI's
|
|
75
|
+
APIs, so you can test your confidence handling in CI without a GPU.
|
|
76
|
+
|
|
77
|
+
## What it can't do
|
|
78
|
+
|
|
79
|
+
A model can be wrong and certain. This plugin catches *shaky* answers, not confident mistakes, so keep your
|
|
80
|
+
correctness assertions too.
|
|
81
|
+
|
|
82
|
+
## Related
|
|
83
|
+
|
|
84
|
+
- **proprioceptive-confidence**: the library this plugin uses, with LangChain and LiteLLM adapters.
|
|
85
|
+
- **proprioceptive-mcp**: let Claude Code, Cursor and other agents ask your local model and see how sure it was.
|
|
86
|
+
- **Proprioceptive Lens**: see every word's confidence live in a local app: `pip install proprioceptive-lens`.
|
|
87
|
+
|
|
88
|
+
MIT licensed. From [Proprioceptive AI](https://proprioceptiveai.com).
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "pytest-llm-confidence"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "pytest plugin that fails a test when a language model wasn't sure of its answer. Reads token probabilities: no judge model, no extra API cost, deterministic."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
dependencies = ["pytest>=7", "proprioceptive-confidence>=0.1.0"]
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
authors = [{ name = "Proprioceptive AI", email = "logan@proprioceptiveai.com" }]
|
|
15
|
+
keywords = ["pytest", "llm", "testing", "evals", "confidence", "logprobs", "hallucination", "ollama", "ci"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Framework :: Pytest",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Operating System :: OS Independent",
|
|
22
|
+
"Topic :: Software Development :: Testing",
|
|
23
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Homepage = "https://proprioceptiveai.com/products.html"
|
|
28
|
+
Repository = "https://github.com/Loganwins/proprioceptive-confidence"
|
|
29
|
+
Issues = "https://github.com/Loganwins/proprioceptive-confidence/issues"
|
|
30
|
+
"Proprioceptive Lens" = "https://pypi.org/project/proprioceptive-lens/"
|
|
31
|
+
|
|
32
|
+
[project.entry-points.pytest11]
|
|
33
|
+
llm_confidence = "pytest_llm_confidence.plugin"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["src"]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""pytest-llm-confidence: fail a test when the model wasn't sure of its answer.
|
|
2
|
+
|
|
3
|
+
def test_capital(llm_confidence):
|
|
4
|
+
ans = llm_confidence.ask("What is the capital of Australia? One word.")
|
|
5
|
+
llm_confidence.assert_confident(ans)
|
|
6
|
+
|
|
7
|
+
From Proprioceptive AI (https://proprioceptiveai.com).
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "0.1.0"
|
|
11
|
+
|
|
12
|
+
from .plugin import LLMConfidence, ShakyAnswerError, assert_confident # noqa: E402
|
|
13
|
+
|
|
14
|
+
__all__ = ["__version__", "LLMConfidence", "ShakyAnswerError", "assert_confident"]
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"""pytest-llm-confidence: fail a test when the model wasn't sure of its answer.
|
|
2
|
+
|
|
3
|
+
Reads the model's own token probabilities, so there is no judge model, no extra API
|
|
4
|
+
cost, and the same response always gives the same verdict.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from typing import Any, List, Optional
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
from proprioceptive_confidence import (
|
|
16
|
+
DEFAULT_THRESHOLD,
|
|
17
|
+
Answer,
|
|
18
|
+
ConfidenceClient,
|
|
19
|
+
ConfidenceError,
|
|
20
|
+
ConfidenceReport,
|
|
21
|
+
analyze,
|
|
22
|
+
)
|
|
23
|
+
from proprioceptive_confidence.core import pct, quote
|
|
24
|
+
|
|
25
|
+
LENS_LINE = "See every word's confidence live: pip install proprioceptive-lens (proprioceptiveai.com)"
|
|
26
|
+
_RECORDS_KEY = pytest.StashKey["List[Record]"]() if hasattr(pytest, "StashKey") else None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass
|
|
30
|
+
class Record:
|
|
31
|
+
nodeid: str
|
|
32
|
+
report: ConfidenceReport
|
|
33
|
+
passed: bool
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class ShakyAnswerError(AssertionError):
|
|
37
|
+
"""The model wasn't sure enough of its answer."""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _to_report(obj: Any, threshold: float) -> ConfidenceReport:
|
|
41
|
+
if isinstance(obj, Answer):
|
|
42
|
+
rep = obj.report
|
|
43
|
+
rep.threshold = threshold
|
|
44
|
+
return rep
|
|
45
|
+
return analyze(obj, threshold=threshold)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _failure_message(report: ConfidenceReport, label: Optional[str]) -> str:
|
|
49
|
+
head = f"{label}: " if label else ""
|
|
50
|
+
lines = [f"{head}model wasn't sure of its answer ({report.summary()})", f"answer: {report.text!r}"]
|
|
51
|
+
for t in sorted(report.shaky, key=lambda t: t.prob)[:8]:
|
|
52
|
+
alts = ", ".join(f"{quote(a)} {pct(p)}" for a, p in t.alternatives if a != t.text)[:120]
|
|
53
|
+
lines.append(f" {quote(t.text)} at {pct(t.prob)}" + (f" (alternatives: {alts})" if alts else ""))
|
|
54
|
+
return "\n".join(lines)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def assert_confident(response: Any, threshold: float = DEFAULT_THRESHOLD, msg: Optional[str] = None) -> ConfidenceReport:
|
|
58
|
+
"""Assert every word of a response was at or above `threshold` probability.
|
|
59
|
+
|
|
60
|
+
`response` can be an Answer, a ConfidenceReport, an OpenAI-style response
|
|
61
|
+
(requested with logprobs=True), an Ollama response (requested with
|
|
62
|
+
"logprobs": true), or a list of (token, logprob) pairs.
|
|
63
|
+
"""
|
|
64
|
+
report = _to_report(response, threshold)
|
|
65
|
+
if not report.tokens:
|
|
66
|
+
raise ShakyAnswerError(
|
|
67
|
+
"no token probabilities in the response: request it with logprobs=True "
|
|
68
|
+
"(OpenAI-compatible) or \"logprobs\": true (Ollama 0.12+)"
|
|
69
|
+
)
|
|
70
|
+
if not report.is_confident:
|
|
71
|
+
raise ShakyAnswerError(_failure_message(report, msg))
|
|
72
|
+
return report
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class LLMConfidence:
|
|
76
|
+
"""The `llm_confidence` fixture: ask a model, check responses, record results."""
|
|
77
|
+
|
|
78
|
+
def __init__(self, request: pytest.FixtureRequest) -> None:
|
|
79
|
+
self._request = request
|
|
80
|
+
cfg = request.config
|
|
81
|
+
marker = request.node.get_closest_marker("llm_confidence")
|
|
82
|
+
threshold = _opt(cfg, "threshold")
|
|
83
|
+
double_check = bool(_opt(cfg, "double_check"))
|
|
84
|
+
if marker is not None:
|
|
85
|
+
if marker.args:
|
|
86
|
+
threshold = float(marker.args[0])
|
|
87
|
+
threshold = float(marker.kwargs.get("threshold", threshold))
|
|
88
|
+
double_check = bool(marker.kwargs.get("double_check", double_check))
|
|
89
|
+
self.threshold = float(threshold)
|
|
90
|
+
self.double_check = double_check
|
|
91
|
+
self.strict = bool(_opt(cfg, "strict"))
|
|
92
|
+
self.client = ConfidenceClient(
|
|
93
|
+
model=_opt(cfg, "model") or None,
|
|
94
|
+
base_url=_opt(cfg, "base_url") or None,
|
|
95
|
+
api=_opt(cfg, "api") or None,
|
|
96
|
+
threshold=self.threshold,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
def _record(self, report: ConfidenceReport) -> None:
|
|
100
|
+
_records(self._request.config).append(Record(self._request.node.nodeid, report, report.is_confident))
|
|
101
|
+
|
|
102
|
+
def ask(self, prompt: str, model: Optional[str] = None, system: Optional[str] = None, double_check: Optional[bool] = None) -> Answer:
|
|
103
|
+
"""Ask the configured model. Skips the test if the model server isn't reachable
|
|
104
|
+
(use --llm-confidence-strict to fail instead)."""
|
|
105
|
+
dc = self.double_check if double_check is None else double_check
|
|
106
|
+
try:
|
|
107
|
+
ans = self.client.ask(prompt, model=model, system=system, double_check=dc)
|
|
108
|
+
except ConfidenceError as exc:
|
|
109
|
+
if self.strict:
|
|
110
|
+
pytest.fail(f"llm-confidence: {exc}")
|
|
111
|
+
pytest.skip(f"llm-confidence: {exc}")
|
|
112
|
+
self._record(ans.report)
|
|
113
|
+
return ans
|
|
114
|
+
|
|
115
|
+
def check(self, response: Any) -> ConfidenceReport:
|
|
116
|
+
"""Build and record a report for a response you already have."""
|
|
117
|
+
report = _to_report(response, self.threshold)
|
|
118
|
+
if report.tokens:
|
|
119
|
+
self._record(report)
|
|
120
|
+
return report
|
|
121
|
+
|
|
122
|
+
def assert_confident(self, response: Any, threshold: Optional[float] = None, msg: Optional[str] = None) -> ConfidenceReport:
|
|
123
|
+
th = self.threshold if threshold is None else threshold
|
|
124
|
+
report = _to_report(response, th)
|
|
125
|
+
if report.tokens and not any(r.report is report for r in _records(self._request.config)):
|
|
126
|
+
self._record(report)
|
|
127
|
+
return assert_confident(report, threshold=th, msg=msg)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
# -- plugin hooks -------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
_DEFAULTS = {"threshold": DEFAULT_THRESHOLD, "model": "", "api": "", "base_url": "", "strict": False, "double_check": False, "report": ""}
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def _opt(config: pytest.Config, name: str) -> Any:
|
|
136
|
+
val = config.getoption(f"llm_confidence_{name}", default=None)
|
|
137
|
+
if val not in (None, ""):
|
|
138
|
+
return val
|
|
139
|
+
ini = config.getini(f"llm_confidence_{name}")
|
|
140
|
+
if ini not in (None, "", []):
|
|
141
|
+
if name == "threshold":
|
|
142
|
+
return float(ini)
|
|
143
|
+
if name in ("strict", "double_check"):
|
|
144
|
+
return str(ini).lower() in ("1", "true", "yes", "on")
|
|
145
|
+
return ini
|
|
146
|
+
return _DEFAULTS[name]
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _records(config: pytest.Config) -> List[Record]:
|
|
150
|
+
if _RECORDS_KEY is not None:
|
|
151
|
+
return config.stash.setdefault(_RECORDS_KEY, [])
|
|
152
|
+
if not hasattr(config, "_llm_confidence_records"): # pragma: no cover - old pytest
|
|
153
|
+
config._llm_confidence_records = []
|
|
154
|
+
return config._llm_confidence_records # pragma: no cover
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def pytest_addoption(parser: pytest.Parser) -> None:
|
|
158
|
+
g = parser.getgroup("llm-confidence", "fail tests when a language model wasn't sure of its answer")
|
|
159
|
+
g.addoption("--llm-confidence-threshold", dest="llm_confidence_threshold", type=float, default=None,
|
|
160
|
+
help="probability below which a word counts as shaky (default 0.8)")
|
|
161
|
+
g.addoption("--llm-confidence-model", dest="llm_confidence_model", default=None, help="model for llm_confidence.ask (default llama3.2)")
|
|
162
|
+
g.addoption("--llm-confidence-api", dest="llm_confidence_api", choices=["ollama", "openai"], default=None,
|
|
163
|
+
help="server type for llm_confidence.ask (default ollama)")
|
|
164
|
+
g.addoption("--llm-confidence-base-url", dest="llm_confidence_base_url", default=None,
|
|
165
|
+
help="model server address (default $OLLAMA_HOST or http://127.0.0.1:11434)")
|
|
166
|
+
g.addoption("--llm-confidence-strict", dest="llm_confidence_strict", action="store_true", default=None,
|
|
167
|
+
help="fail instead of skip when the model server can't be reached")
|
|
168
|
+
g.addoption("--llm-confidence-double-check", dest="llm_confidence_double_check", action="store_true", default=None,
|
|
169
|
+
help="re-ask shaky short answers in full")
|
|
170
|
+
g.addoption("--llm-confidence-report", dest="llm_confidence_report", default=None,
|
|
171
|
+
help="write a JSON report of every confidence check to this path")
|
|
172
|
+
for name, help_ in [
|
|
173
|
+
("threshold", "default confidence threshold"), ("model", "default model"), ("api", "ollama or openai"),
|
|
174
|
+
("base_url", "model server address"), ("strict", "fail when the server can't be reached"),
|
|
175
|
+
("double_check", "re-ask shaky short answers"), ("report", "JSON report path"),
|
|
176
|
+
]:
|
|
177
|
+
parser.addini(f"llm_confidence_{name}", help_, default="")
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def pytest_configure(config: pytest.Config) -> None:
|
|
181
|
+
config.addinivalue_line(
|
|
182
|
+
"markers",
|
|
183
|
+
"llm_confidence(threshold=0.8, double_check=False): confidence settings for this test's llm_confidence checks",
|
|
184
|
+
)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
@pytest.fixture
|
|
188
|
+
def llm_confidence(request: pytest.FixtureRequest) -> LLMConfidence:
|
|
189
|
+
"""Ask a model and assert it was sure of its answer."""
|
|
190
|
+
return LLMConfidence(request)
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
def pytest_terminal_summary(terminalreporter, exitstatus, config) -> None:
|
|
194
|
+
records = _records(config)
|
|
195
|
+
if not records:
|
|
196
|
+
return
|
|
197
|
+
tr = terminalreporter
|
|
198
|
+
tr.write_sep("=", "LLM confidence")
|
|
199
|
+
shaky = 0
|
|
200
|
+
for r in records:
|
|
201
|
+
mark = "ok " if r.passed else "SHAKY"
|
|
202
|
+
shaky += 0 if r.passed else 1
|
|
203
|
+
weak = r.report.weakest
|
|
204
|
+
detail = f"lowest {quote(weak.text)} at {pct(weak.prob)}" if weak else "no tokens"
|
|
205
|
+
tr.write_line(f"{mark} {r.nodeid} {detail}")
|
|
206
|
+
tr.write_line(f"{len(records)} check(s), {shaky} shaky, threshold set per test (default {pct(_opt(config, 'threshold'))})")
|
|
207
|
+
tr.write_line(LENS_LINE)
|
|
208
|
+
path = _opt(config, "report")
|
|
209
|
+
if path:
|
|
210
|
+
out = [{"test": r.nodeid, "passed": r.passed, **r.report.to_dict()} for r in records]
|
|
211
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
212
|
+
json.dump({"checks": out}, fh, indent=2)
|
|
213
|
+
tr.write_line(f"wrote {path}")
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pytest-llm-confidence
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: pytest plugin that fails a test when a language model wasn't sure of its answer. Reads token probabilities: no judge model, no extra API cost, deterministic.
|
|
5
|
+
Author-email: Proprioceptive AI <logan@proprioceptiveai.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://proprioceptiveai.com/products.html
|
|
8
|
+
Project-URL: Repository, https://github.com/Loganwins/proprioceptive-confidence
|
|
9
|
+
Project-URL: Issues, https://github.com/Loganwins/proprioceptive-confidence/issues
|
|
10
|
+
Project-URL: Proprioceptive Lens, https://pypi.org/project/proprioceptive-lens/
|
|
11
|
+
Keywords: pytest,llm,testing,evals,confidence,logprobs,hallucination,ollama,ci
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Framework :: Pytest
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Software Development :: Testing
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: pytest>=7
|
|
23
|
+
Requires-Dist: proprioceptive-confidence>=0.1.0
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# pytest-llm-confidence
|
|
27
|
+
|
|
28
|
+
**Fail a test when the model wasn't sure of its answer.**
|
|
29
|
+
|
|
30
|
+
Most LLM test tools ask a second model to judge the first, which costs money, adds latency and changes from run to
|
|
31
|
+
run. `pytest-llm-confidence` reads the model's own token probabilities instead: no judge model, no extra API cost,
|
|
32
|
+
and the same response always gets the same verdict.
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
$ pip install pytest-llm-confidence
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
# test_answers.py
|
|
40
|
+
def test_capital(llm_confidence):
|
|
41
|
+
ans = llm_confidence.ask("What is the capital of Australia? Answer with one word.")
|
|
42
|
+
assert ans.text == "Canberra"
|
|
43
|
+
llm_confidence.assert_confident(ans) # fails if any word was below 80%
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
$ pytest
|
|
48
|
+
...
|
|
49
|
+
FAILED test_answers.py::test_capital - ShakyAnswerError: model wasn't sure of its answer
|
|
50
|
+
(shaky: 1 word(s) below 80%: "Syd" at 41%)
|
|
51
|
+
answer: 'Sydney'
|
|
52
|
+
"Syd" at 41% (alternatives: "Can" 38%)
|
|
53
|
+
|
|
54
|
+
============================ LLM confidence ============================
|
|
55
|
+
SHAKY test_answers.py::test_capital lowest "Syd" at 41%
|
|
56
|
+
1 check(s), 1 shaky
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
*(Illustrative output; real numbers depend on your model.)*
|
|
60
|
+
|
|
61
|
+
## Works with your model
|
|
62
|
+
|
|
63
|
+
- **Ollama 0.12+** (default): `llm_confidence.ask` talks to `http://127.0.0.1:11434`.
|
|
64
|
+
- **Any OpenAI-compatible server that returns logprobs**: OpenAI, vLLM, llama.cpp, LM Studio:
|
|
65
|
+
`pytest --llm-confidence-api openai --llm-confidence-base-url http://127.0.0.1:8000/v1 --llm-confidence-model my-model`
|
|
66
|
+
- **Responses you already have:** `assert_confident(response)` accepts OpenAI-style responses requested with
|
|
67
|
+
`logprobs=True`, Ollama responses requested with `"logprobs": true`, or `(token, logprob)` pairs.
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from pytest_llm_confidence import assert_confident
|
|
71
|
+
|
|
72
|
+
def test_my_pipeline():
|
|
73
|
+
response = my_app.call_model("...", logprobs=True)
|
|
74
|
+
assert_confident(response, threshold=0.9)
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Settings
|
|
78
|
+
|
|
79
|
+
| Option | ini key | Default |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `--llm-confidence-threshold` | `llm_confidence_threshold` | `0.8` |
|
|
82
|
+
| `--llm-confidence-model` | `llm_confidence_model` | `llama3.2` |
|
|
83
|
+
| `--llm-confidence-api` | `llm_confidence_api` | `ollama` |
|
|
84
|
+
| `--llm-confidence-base-url` | `llm_confidence_base_url` | `$OLLAMA_HOST` or `http://127.0.0.1:11434` |
|
|
85
|
+
| `--llm-confidence-double-check` | `llm_confidence_double_check` | off |
|
|
86
|
+
| `--llm-confidence-strict` | `llm_confidence_strict` | off (skip when the server is down) |
|
|
87
|
+
| `--llm-confidence-report PATH` | `llm_confidence_report` | none (writes JSON for CI artifacts) |
|
|
88
|
+
|
|
89
|
+
Per test: `@pytest.mark.llm_confidence(threshold=0.95, double_check=True)`.
|
|
90
|
+
|
|
91
|
+
**CI-safe by default:** if the model server can't be reached, `llm_confidence.ask` skips the test instead of failing
|
|
92
|
+
it. Pass `--llm-confidence-strict` to make that a failure.
|
|
93
|
+
|
|
94
|
+
**Double-check:** with `double_check=True`, a shaky short answer is re-asked in full and `ans.double_check.agrees`
|
|
95
|
+
tells you whether the answer held up.
|
|
96
|
+
|
|
97
|
+
## Testing without a model
|
|
98
|
+
|
|
99
|
+
`proprioceptive_confidence.testing.FakeModelServer` serves scripted token probabilities over Ollama's and OpenAI's
|
|
100
|
+
APIs, so you can test your confidence handling in CI without a GPU.
|
|
101
|
+
|
|
102
|
+
## What it can't do
|
|
103
|
+
|
|
104
|
+
A model can be wrong and certain. This plugin catches *shaky* answers, not confident mistakes, so keep your
|
|
105
|
+
correctness assertions too.
|
|
106
|
+
|
|
107
|
+
## Related
|
|
108
|
+
|
|
109
|
+
- **proprioceptive-confidence**: the library this plugin uses, with LangChain and LiteLLM adapters.
|
|
110
|
+
- **proprioceptive-mcp**: let Claude Code, Cursor and other agents ask your local model and see how sure it was.
|
|
111
|
+
- **Proprioceptive Lens**: see every word's confidence live in a local app: `pip install proprioceptive-lens`.
|
|
112
|
+
|
|
113
|
+
MIT licensed. From [Proprioceptive AI](https://proprioceptiveai.com).
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/pytest_llm_confidence/__init__.py
|
|
5
|
+
src/pytest_llm_confidence/plugin.py
|
|
6
|
+
src/pytest_llm_confidence.egg-info/PKG-INFO
|
|
7
|
+
src/pytest_llm_confidence.egg-info/SOURCES.txt
|
|
8
|
+
src/pytest_llm_confidence.egg-info/dependency_links.txt
|
|
9
|
+
src/pytest_llm_confidence.egg-info/entry_points.txt
|
|
10
|
+
src/pytest_llm_confidence.egg-info/requires.txt
|
|
11
|
+
src/pytest_llm_confidence.egg-info/top_level.txt
|
|
12
|
+
tests/test_plugin.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pytest_llm_confidence
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import json
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
|
|
5
|
+
from proprioceptive_confidence.testing import FakeModelServer
|
|
6
|
+
|
|
7
|
+
pytest_plugins = "pytester"
|
|
8
|
+
|
|
9
|
+
ANSWERS = {
|
|
10
|
+
"complete sentence": [("The", 0.99), (" capital", 0.99), (" is", 0.99), (" Canberra", 0.97), (".", 0.99)],
|
|
11
|
+
"australia": [("Syd", 0.41), ("ney", 0.99)],
|
|
12
|
+
"france": [("Paris", 0.98)],
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@pytest.fixture
|
|
17
|
+
def server():
|
|
18
|
+
with FakeModelServer(answers=ANSWERS) as srv:
|
|
19
|
+
yield srv
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_confident_answer_passes(pytester, server):
|
|
23
|
+
pytester.makepyfile(
|
|
24
|
+
"""
|
|
25
|
+
def test_it(llm_confidence):
|
|
26
|
+
ans = llm_confidence.ask("Capital of France?")
|
|
27
|
+
assert ans.text == "Paris"
|
|
28
|
+
llm_confidence.assert_confident(ans)
|
|
29
|
+
"""
|
|
30
|
+
)
|
|
31
|
+
res = pytester.runpytest("--llm-confidence-base-url", server.url, "-p", "no:cacheprovider")
|
|
32
|
+
res.assert_outcomes(passed=1)
|
|
33
|
+
res.stdout.fnmatch_lines(["*LLM confidence*", "ok *test_it*lowest \"Paris\" at 98%*", "*pip install proprioceptive-lens*"])
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_shaky_answer_fails_with_readable_message(pytester, server):
|
|
37
|
+
pytester.makepyfile(
|
|
38
|
+
"""
|
|
39
|
+
def test_it(llm_confidence):
|
|
40
|
+
ans = llm_confidence.ask("Capital of Australia?")
|
|
41
|
+
llm_confidence.assert_confident(ans)
|
|
42
|
+
"""
|
|
43
|
+
)
|
|
44
|
+
res = pytester.runpytest("--llm-confidence-base-url", server.url)
|
|
45
|
+
res.assert_outcomes(failed=1)
|
|
46
|
+
res.stdout.fnmatch_lines(["*ShakyAnswerError*", "*\"Syd\" at 41%*", "SHAKY *test_it*"])
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_marker_threshold_and_double_check(pytester, server):
|
|
50
|
+
pytester.makepyfile(
|
|
51
|
+
"""
|
|
52
|
+
import pytest
|
|
53
|
+
|
|
54
|
+
@pytest.mark.llm_confidence(threshold=0.3, double_check=True)
|
|
55
|
+
def test_low_bar(llm_confidence):
|
|
56
|
+
ans = llm_confidence.ask("Capital of Australia?")
|
|
57
|
+
llm_confidence.assert_confident(ans)
|
|
58
|
+
assert ans.double_check is None # confident at 0.3, so no re-ask
|
|
59
|
+
|
|
60
|
+
@pytest.mark.llm_confidence(0.99, double_check=True)
|
|
61
|
+
def test_high_bar(llm_confidence):
|
|
62
|
+
ans = llm_confidence.ask("Capital of Australia?")
|
|
63
|
+
assert ans.double_check is not None
|
|
64
|
+
assert ans.double_check.agrees is False # 'Sydney' vs 'The capital is Canberra.'
|
|
65
|
+
"""
|
|
66
|
+
)
|
|
67
|
+
res = pytester.runpytest("--llm-confidence-base-url", server.url)
|
|
68
|
+
res.assert_outcomes(passed=2)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_skips_when_server_unreachable_and_strict_fails(pytester):
|
|
72
|
+
pytester.makepyfile(
|
|
73
|
+
"""
|
|
74
|
+
def test_it(llm_confidence):
|
|
75
|
+
llm_confidence.ask("hello")
|
|
76
|
+
"""
|
|
77
|
+
)
|
|
78
|
+
res = pytester.runpytest("--llm-confidence-base-url", "http://127.0.0.1:9")
|
|
79
|
+
res.assert_outcomes(skipped=1)
|
|
80
|
+
res = pytester.runpytest("--llm-confidence-base-url", "http://127.0.0.1:9", "--llm-confidence-strict")
|
|
81
|
+
res.assert_outcomes(failed=1)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_plain_assert_helper_and_json_report(pytester, tmp_path):
|
|
85
|
+
report_path = tmp_path / "conf.json"
|
|
86
|
+
pytester.makepyfile(
|
|
87
|
+
"""
|
|
88
|
+
import math
|
|
89
|
+
import pytest
|
|
90
|
+
from pytest_llm_confidence import assert_confident, ShakyAnswerError
|
|
91
|
+
|
|
92
|
+
RESP = {"choices": [{"message": {"content": "1904"}, "logprobs": {"content": [
|
|
93
|
+
{"token": "190", "logprob": math.log(0.66)}, {"token": "4", "logprob": math.log(0.97)}]}}]}
|
|
94
|
+
|
|
95
|
+
def test_helper_raises():
|
|
96
|
+
with pytest.raises(ShakyAnswerError, match='"190" at 66%'):
|
|
97
|
+
assert_confident(RESP)
|
|
98
|
+
|
|
99
|
+
def test_helper_passes_with_lower_threshold():
|
|
100
|
+
assert_confident(RESP, threshold=0.5)
|
|
101
|
+
|
|
102
|
+
def test_no_logprobs_is_explained():
|
|
103
|
+
with pytest.raises(ShakyAnswerError, match="no token probabilities"):
|
|
104
|
+
assert_confident({"choices": [{"message": {"content": "x"}}]})
|
|
105
|
+
|
|
106
|
+
def test_check_records(llm_confidence):
|
|
107
|
+
rep = llm_confidence.check(RESP)
|
|
108
|
+
assert not rep.is_confident
|
|
109
|
+
"""
|
|
110
|
+
)
|
|
111
|
+
res = pytester.runpytest("--llm-confidence-report", str(report_path))
|
|
112
|
+
res.assert_outcomes(passed=4)
|
|
113
|
+
data = json.loads(report_path.read_text())
|
|
114
|
+
assert data["checks"][0]["is_confident"] is False
|
|
115
|
+
assert data["checks"][0]["shaky"][0]["text"] == "190"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_ini_settings(pytester, server):
|
|
119
|
+
pytester.makeini(
|
|
120
|
+
f"""
|
|
121
|
+
[pytest]
|
|
122
|
+
llm_confidence_base_url = {server.url}
|
|
123
|
+
llm_confidence_threshold = 0.3
|
|
124
|
+
"""
|
|
125
|
+
)
|
|
126
|
+
pytester.makepyfile(
|
|
127
|
+
"""
|
|
128
|
+
def test_it(llm_confidence):
|
|
129
|
+
assert llm_confidence.threshold == 0.3
|
|
130
|
+
llm_confidence.assert_confident(llm_confidence.ask("Capital of Australia?"))
|
|
131
|
+
"""
|
|
132
|
+
)
|
|
133
|
+
pytester.runpytest().assert_outcomes(passed=1)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_no_summary_when_plugin_unused(pytester):
|
|
137
|
+
pytester.makepyfile("def test_x():\n assert True\n")
|
|
138
|
+
res = pytester.runpytest()
|
|
139
|
+
res.assert_outcomes(passed=1)
|
|
140
|
+
assert "LLM confidence" not in res.stdout.str()
|