feat: add fraud detection validator

This commit is contained in:
Dobromir Popov
2026-06-29 09:46:22 +03:00
parent a2aa22fc08
commit 39f6f23c83
9 changed files with 511 additions and 6 deletions

View File

@@ -147,10 +147,10 @@ class _GatewayHandler(http.server.BaseHTTPRequestHandler):
text = node_resp["text"]
model = body.get("model", "stub-model")
session_id = str(uuid.uuid4())
if server.contracts is not None and route_nodes:
api_key = _api_key_from_authorization(self.headers.get("Authorization"))
if api_key:
session_id = str(uuid.uuid4())
tokens = max(1, _estimate_token_count(messages, text))
for node in route_nodes:
wallet_address = node.get("wallet_address")
@@ -165,6 +165,14 @@ class _GatewayHandler(http.server.BaseHTTPRequestHandler):
tokens=tokens,
speed_score=float(node.get("score", 1.0)),
)
if server.contracts is not None:
server.contracts.validation.record_completed_inference(
session_id=session_id,
model=model,
messages=messages if isinstance(messages, list) else [],
observed_output=text,
route_nodes=route_nodes,
)
if streaming:
self._send_sse_response(text, model)