mirror of
https://github.com/norandom/OpenUltraSAST.git
synced 2026-10-18 20:49:28 +00:00
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:
co-authored by
Claude Opus 5
parent
289648338c
commit
944df86d12
@@ -68,10 +68,29 @@ class OpenRouterChatClient:
|
||||
messages: Sequence[Mapping[str, object]],
|
||||
tools: Sequence[Mapping[str, object]] | None = None,
|
||||
timeout_seconds: int = 60,
|
||||
extra_body: Mapping[str, object] | None = None,
|
||||
) -> dict[str, object]:
|
||||
"""The assistant message of the reply, provider fields included (a reasoning field is kept for the caller to replay)."""
|
||||
payload = self.complete_chat_raw(
|
||||
model=model, messages=messages, tools=tools, timeout_seconds=timeout_seconds, extra_body=extra_body
|
||||
)
|
||||
return _extract_message(payload)
|
||||
|
||||
def complete_chat_raw(
|
||||
self,
|
||||
*,
|
||||
model: str,
|
||||
messages: Sequence[Mapping[str, object]],
|
||||
tools: Sequence[Mapping[str, object]] | None = None,
|
||||
timeout_seconds: int = 60,
|
||||
extra_body: Mapping[str, object] | None = None,
|
||||
) -> dict[str, object]:
|
||||
"""The whole response payload, so a caller can read `usage` for cost accounting."""
|
||||
body: dict[str, object] = {"model": model, "messages": list(messages), "temperature": 0}
|
||||
if tools:
|
||||
body["tools"] = list(tools)
|
||||
for key, value in (extra_body or {}).items():
|
||||
body[key] = value
|
||||
payload = json.dumps(body).encode()
|
||||
request = urllib.request.Request(
|
||||
f"{self.base_url.rstrip('/')}/chat/completions",
|
||||
@@ -88,10 +107,9 @@ class OpenRouterChatClient:
|
||||
return cast(dict[str, object], json.loads(response.read().decode()))
|
||||
|
||||
try:
|
||||
response_payload = call_with_retry(_do, attempts=self.max_attempts, base_delay=self.retry_base_delay)
|
||||
return call_with_retry(_do, attempts=self.max_attempts, base_delay=self.retry_base_delay)
|
||||
except (urllib.error.URLError, TimeoutError, json.JSONDecodeError) as exc:
|
||||
raise OpenRouterError(f"OpenRouter chat request failed: {exc}") from exc
|
||||
return _extract_message(response_payload)
|
||||
|
||||
def complete_json(self, *, model: str, messages: list[dict[str, str]], timeout_seconds: int = 60) -> object:
|
||||
message = self.complete_chat(model=model, messages=messages, timeout_seconds=timeout_seconds)
|
||||
|
||||
Reference in New Issue
Block a user