-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_inference.py
More file actions
68 lines (61 loc) · 2.3 KB
/
Copy pathcheck_inference.py
File metadata and controls
68 lines (61 loc) · 2.3 KB
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
63
64
65
66
67
68
from __future__ import annotations
from database_setup import configured_environment
from hearsay_api.inference import (
DeterministicInferenceProvider,
ModalInferenceProvider,
RumorRetellingRequest,
SafeInferenceProvider,
)
def main() -> int:
environment = configured_environment()
modal_url = environment.get("MODAL_PROXY_URL")
token_id = environment.get("MODAL_PROXY_TOKEN_ID")
token_secret = environment.get("MODAL_PROXY_TOKEN_SECRET")
model_id = environment.get(
"HEARSAY_MODAL_MODEL",
"thinkingmachines/Inkling-NVFP4",
)
request = RumorRetellingRequest(
original_claim="The newcomer challenged Bram's shipment price in market row.",
speaker_id="bram",
listener_id="pip",
trust=0.6,
context="A public dispute in Greyhaven.",
)
if modal_url and token_id and token_secret:
provider = ModalInferenceProvider(
base_url=modal_url,
token_id=token_id,
token_secret=token_secret,
model_id=model_id,
timeout_seconds=45,
)
safe_provider = SafeInferenceProvider(
primary=provider,
max_attempts=2,
)
inference = safe_provider.retell_rumor(request)
if inference.fallback_used:
raise RuntimeError(
"Modal did not produce a safe structured rumor after bounded retries "
f"({inference.fallback_reason})."
)
if not inference.value.retold_claim.strip() or not (
inference.value.semantic_position.model_dump(exclude_none=True)
):
raise RuntimeError("Modal returned an incomplete structured rumor.")
print(
"Modal structured-output probe passed "
f"with provider '{provider.provider_id}' and model '{provider.model_id}'."
)
return 0
provider = DeterministicInferenceProvider()
result = provider.retell_rumor(request)
if not result.retold_claim.strip() or not result.semantic_position.model_dump(
exclude_none=True
):
raise RuntimeError("Deterministic structured-output fixture is incomplete.")
print("Modal is not configured; deterministic structured-output fixture passed.")
return 0
if __name__ == "__main__":
raise SystemExit(main())