feat(learning-harness): chat endpoint independent of embeddings, with the DeepSeek adapter

Task 1.2. Detectors, the classifier's model tier, the proposer and the judge
resolve one chat endpoint: an explicit override first, then the scripted client
flag, then an endpoint named in the config, then DeepSeek, then OpenRouter.
Prove-order retrieval keeps its own embedding endpoint untouched, because the
chat provider we default to offers none.

The adapter handles the provider's documented quirks: thinking is on by default
there and silently ignores temperature, so it is disabled explicitly; the
reasoning field is kept on the reply for the caller to replay across tool turns;
JSON mode has no schema and occasionally returns empty content, so one retry is
built in, never a loop; token log-probabilities are requested only when the
caller wants them, and their mean is what lets the classifier abstain.

Cost comes from the provider's own usage fields, cache hits priced separately,
and a model with no recorded price reports no cost rather than a made-up one.
The endpoint record deliberately holds no key, so it is safe to journal.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01T7XD7x5KonMdmGRkp63EQG
This commit is contained in:
Marius Ciepluch
2026-09-06 09:10:19 +02:00
co-authored by Claude Opus 5
parent 289648338c
commit 944df86d12
5 changed files with 452 additions and 3 deletions
+20 -1
View File
@@ -101,6 +101,8 @@ class ToolCall:
class ChatResponse:
content: str | None = None
tool_calls: tuple[ToolCall, ...] = ()
reasoning: str | None = None # provider chain-of-thought; replayed on tool turns, never shown or scored
mean_logprob: float | None = None # averaged token log-probability when the caller asked for it
class ChatClient(Protocol):
@@ -198,7 +200,24 @@ def chat_response_from_message(message: Mapping[str, object]) -> ChatResponse:
parsed = _tool_call_from_openrouter(item, index)
if parsed is not None:
calls.append(parsed)
return ChatResponse(content=text, tool_calls=tuple(calls))
reasoning = message.get("reasoning_content") or message.get("reasoning")
return ChatResponse(
content=text,
tool_calls=tuple(calls),
reasoning=reasoning if isinstance(reasoning, str) and reasoning else None,
mean_logprob=_mean_logprob(message.get("logprobs")),
)
def _mean_logprob(payload: object) -> float | None:
"""The mean token log-probability of a reply, used by the classifier to abstain when it is unsure."""
if not isinstance(payload, Mapping):
return None
tokens = payload.get("content")
if not isinstance(tokens, Sequence) or isinstance(tokens, str | bytes):
return None
values = [float(item["logprob"]) for item in tokens if isinstance(item, Mapping) and isinstance(item.get("logprob"), int | float)]
return sum(values) / len(values) if values else None
def _tool_call_from_openrouter(item: object, index: int) -> ToolCall | None: