hermes(agent): accept bounded raw Jetson votes
All checks were successful
Tests / Declarative: Post Actions passed: 224
All checks were successful
Tests / Declarative: Post Actions passed: 224
This commit is contained in:
parent
5d4cb71b90
commit
2f5780ebf9
@ -276,6 +276,17 @@ def _classifier_input(text: str) -> str:
|
|||||||
return text[:400] + "\n...\n" + text[-595:]
|
return text[:400] + "\n...\n" + text[-595:]
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_scalar_vote(content: Any, codes: tuple[str, ...]) -> str | None:
|
||||||
|
"""Accept Ollama's raw or JSON-string rendering of one bounded vote."""
|
||||||
|
raw = str(content or "").strip()
|
||||||
|
try:
|
||||||
|
value = json.loads(raw)
|
||||||
|
except (TypeError, ValueError, json.JSONDecodeError):
|
||||||
|
value = raw
|
||||||
|
value = str(value or "").strip().upper()
|
||||||
|
return value if value in codes else None
|
||||||
|
|
||||||
|
|
||||||
def _jetson_scalar(
|
def _jetson_scalar(
|
||||||
text: str, prompt: str, codes: tuple[str, ...], timeout: float
|
text: str, prompt: str, codes: tuple[str, ...], timeout: float
|
||||||
) -> tuple[str | None, int]:
|
) -> tuple[str | None, int]:
|
||||||
@ -300,12 +311,13 @@ def _jetson_scalar(
|
|||||||
try:
|
try:
|
||||||
with urllib.request.urlopen(request, timeout=timeout) as response:
|
with urllib.request.urlopen(request, timeout=timeout) as response:
|
||||||
envelope = json.load(response)
|
envelope = json.load(response)
|
||||||
value = json.loads(envelope.get("message", {}).get("content", ""))
|
value = _parse_scalar_vote(
|
||||||
|
envelope.get("message", {}).get("content", ""), codes
|
||||||
|
)
|
||||||
except (OSError, TimeoutError, ValueError, TypeError, json.JSONDecodeError):
|
except (OSError, TimeoutError, ValueError, TypeError, json.JSONDecodeError):
|
||||||
return None, round((time.monotonic() - started) * 1000)
|
return None, round((time.monotonic() - started) * 1000)
|
||||||
value = str(value or "").strip().upper()
|
|
||||||
latency_ms = round((time.monotonic() - started) * 1000)
|
latency_ms = round((time.monotonic() - started) * 1000)
|
||||||
return (value if value in codes else None), latency_ms
|
return value, latency_ms
|
||||||
|
|
||||||
|
|
||||||
def _validated_local_route(
|
def _validated_local_route(
|
||||||
|
|||||||
@ -135,6 +135,15 @@ def test_local_classifier_accepts_only_bounded_route_decisions():
|
|||||||
assert (partial.provider, partial.effort) == ("codex", "medium")
|
assert (partial.provider, partial.effort) == ("codex", "medium")
|
||||||
|
|
||||||
|
|
||||||
|
def test_scalar_vote_accepts_raw_and_json_strings_but_remains_bounded():
|
||||||
|
codes = ("C", "A")
|
||||||
|
|
||||||
|
assert router._parse_scalar_vote("C", codes) == "C"
|
||||||
|
assert router._parse_scalar_vote('"A"', codes) == "A"
|
||||||
|
assert router._parse_scalar_vote(" codex ", codes) is None
|
||||||
|
assert router._parse_scalar_vote("C\nA", codes) is None
|
||||||
|
|
||||||
|
|
||||||
def test_jetson_requests_separate_bounded_provider_and_effort_votes(monkeypatch):
|
def test_jetson_requests_separate_bounded_provider_and_effort_votes(monkeypatch):
|
||||||
calls = []
|
calls = []
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user