floop: typed EXPERT confidence + ANSWER bool input
The last floop signatures migrate to the typed-output law: - ExpertSignature.confidence: Confidence(str, Enum) high|medium|low, with guidance in the desc — out-of-set values are schema violations - AnswerSignature.unverified: real bool InputField (callers already passed bools; the old signature stringified them) - expert_draft/synthesize consume the typed values directly VERIFIED: suite 14/14 green (new tests/typed_expert.py: enum parses through the real adapter path, bad confidence raises, bool renders). The floop side of the typed migration is COMPLETE — knowledge signatures are the next (last) block.
This commit is contained in:
@@ -0,0 +1,90 @@
|
||||
"""Typed EXPERT + ANSWER tests (the last floop signatures): confidence is
|
||||
a closed enum; unverified is a real bool InputField.
|
||||
|
||||
No network; RawEngine returns raw text (DummyLM bypasses the adapter).
|
||||
Run: .venv/bin/python tests/typed_expert.py
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
import warnings
|
||||
warnings.filterwarnings("ignore")
|
||||
|
||||
import dspy
|
||||
from dspy._vendor.lm15 import Response, TextPart, Message, Usage
|
||||
from dspy.utils.exceptions import AdapterParseError
|
||||
|
||||
from floop.dspy_modules import FloopModules
|
||||
|
||||
|
||||
def _lm(scripted_raw: str) -> None:
|
||||
class RawEngine:
|
||||
def complete(self, request):
|
||||
return Response(
|
||||
id="x", model="t",
|
||||
message=Message(role="assistant",
|
||||
parts=(TextPart(text=scripted_raw),)),
|
||||
finish_reason="stop",
|
||||
usage=Usage(input_tokens=1, output_tokens=1, total_tokens=2))
|
||||
dspy.configure(lm=dspy.LM("openai/test", engine=RawEngine(), cache=False))
|
||||
|
||||
|
||||
def test_expert_confidence_enum():
|
||||
raw = '''[[ ## value ## ]]
|
||||
Mariano Rajoy
|
||||
|
||||
[[ ## source_quote ## ]]
|
||||
his predecessor Mariano Rajoy
|
||||
|
||||
[[ ## confidence ## ]]
|
||||
high
|
||||
|
||||
[[ ## completed ## ]]'''
|
||||
_lm(raw)
|
||||
out = FloopModules().expert_draft("Who was the President before Pedro Sanchez?",
|
||||
"knowledge", "E1: his predecessor Mariano Rajoy")
|
||||
assert out["value"] == "Mariano Rajoy" and out["confidence"] == "high", out
|
||||
print("ok: typed EXPERT parses confidence enum through the real path")
|
||||
|
||||
|
||||
def test_expert_bad_confidence_raises():
|
||||
raw = '''[[ ## value ## ]]
|
||||
42
|
||||
|
||||
[[ ## source_quote ## ]]
|
||||
|
||||
[[ ## confidence ## ]]
|
||||
certain
|
||||
|
||||
[[ ## completed ## ]]'''
|
||||
_lm(raw)
|
||||
try:
|
||||
FloopModules().expert_draft("q", "knowledge", "")
|
||||
raise AssertionError("bad confidence parsed — enum broken")
|
||||
except AdapterParseError:
|
||||
print("ok: confidence outside the enum raises AdapterParseError")
|
||||
|
||||
|
||||
def test_answer_bool_input():
|
||||
# the bool InputField renders as a plain value in the prompt and the
|
||||
# string answer parses; synthesize passes a real bool now
|
||||
raw = '''[[ ## final_answer ## ]]
|
||||
Mariano Rajoy (E1).
|
||||
|
||||
[[ ## completed ## ]]'''
|
||||
_lm(raw)
|
||||
ans = FloopModules().synthesize("Who was the President before Pedro Sanchez?",
|
||||
"E1: Mariano Rajoy", unverified=True)
|
||||
assert ans == "Mariano Rajoy (E1).", ans
|
||||
print("ok: ANSWER takes a bool unverified and parses through the real path")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_expert_confidence_enum()
|
||||
test_expert_bad_confidence_raises()
|
||||
test_answer_bool_input()
|
||||
print("\ntyped EXPERT+ANSWER tests passed")
|
||||
Reference in New Issue
Block a user