fix: harden the observability fields against the verifier findings
This commit is contained in:
@@ -99,7 +99,8 @@ class PricingTable:
|
||||
logger.warning("pricing 表无 model {!r} 的单价,cost 记 None", model)
|
||||
return None
|
||||
billed_input = prompt_tokens / 1_000_000 * price.input_per_1m
|
||||
if price.cached_input_per_1m is not None and cached_prompt_tokens:
|
||||
# 负数按"无命中"处理: cost() 是公共方法,不能假定调用方已过 transport 的校验
|
||||
if price.cached_input_per_1m is not None and (cached_prompt_tokens or 0) > 0:
|
||||
cached = self._clamp_cached(model, prompt_tokens, cached_prompt_tokens)
|
||||
billed_input = (prompt_tokens - cached) / 1_000_000 * price.input_per_1m + (
|
||||
cached / 1_000_000 * price.cached_input_per_1m
|
||||
|
||||
@@ -45,9 +45,12 @@ def _sse_delta(chunk: dict[str, Any], usage_sink: dict[str, Any]) -> tuple[bool,
|
||||
"""从 chunk 提取增量: (True, content) 或 (False, reasoning);usage 帧旁路进 sink。"""
|
||||
if chunk.get("usage"):
|
||||
usage_sink["usage"] = chunk["usage"]
|
||||
if "model" not in usage_sink and chunk.get("model") is not None:
|
||||
# 首次写入即固定: 末帧的异常值不得覆盖首帧报的真实版本(issue #3)
|
||||
usage_sink["model"] = chunk["model"]
|
||||
if "model" not in usage_sink:
|
||||
# 首个**有效**值即固定: 末帧的异常值不得覆盖它;但首帧报空串也不能锁死
|
||||
# sink——否则后续真实版本会丢(issue #3)
|
||||
reported = _coerce_model_reported(chunk.get("model"))
|
||||
if reported is not None:
|
||||
usage_sink["model"] = reported
|
||||
choices = chunk.get("choices") or []
|
||||
if not choices:
|
||||
return None
|
||||
|
||||
Reference in New Issue
Block a user