File size: 1,650 Bytes
638c806
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations

from conftest import as_mapping, call_with_supported_kwargs, resolve_callable, text_blob


CLASSIFIER_MODULES = (
    "promptboost.classifier",
    "promptboost.classification",
    "promptboost.rules.classifier",
    "promptboost.core",
)

CLASSIFIER_FUNCS = (
    "classify_prompt",
    "classify",
    "classify_task",
    "classify_raw_prompt",
)


def _classify(raw_prompt: str):
    classify = resolve_callable(CLASSIFIER_MODULES, CLASSIFIER_FUNCS)
    return call_with_supported_kwargs(
        classify,
        raw_prompt=raw_prompt,
        prompt=raw_prompt,
        text=raw_prompt,
        content=raw_prompt,
    )


def test_classifier_identifies_coding_debug_prompts():
    result = _classify(
        "Fix a failing pytest suite in a FastAPI project and keep the public API stable."
    )

    blob = text_blob(result)
    assert any(
        label in blob
        for label in ("coding", "code", "software", "debug", "test", "pytest")
    )

    mapping = as_mapping(result)
    if mapping:
        assert any(
            key in mapping
            for key in ("category", "task_type", "labels", "tags", "intent", "kind")
        )


def test_classifier_distinguishes_document_summary_from_coding():
    coding = _classify("Repair a Python CLI bug and add regression tests.")
    document = _classify(
        "Summarize a long leadership PDF into grounded Markdown sections with citations."
    )

    assert text_blob(coding) != text_blob(document)
    assert any(
        label in text_blob(document)
        for label in ("summary", "summar", "document", "pdf", "writing", "analysis")
    )