Files
liqiang b119135836
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
2026-08-20 13:12:50 +00:00

54 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Regression tests for the local LLM serving benchmark."""
from types import SimpleNamespace
from unittest.mock import patch
from benchmark import stream_once
class FakeCompletions:
def __init__(self, chunks):
self.chunks = chunks
def create(self, **kwargs):
return iter(self.chunks)
def make_client(chunks):
completions = FakeCompletions(chunks)
return SimpleNamespace(chat=SimpleNamespace(completions=completions))
def run_reasoning_stream(field):
delta = SimpleNamespace(**{field: "Thinking about the answer."})
chunks = [
SimpleNamespace(
usage=None,
choices=[SimpleNamespace(delta=delta)],
),
SimpleNamespace(
usage=SimpleNamespace(completion_tokens=8),
choices=[],
),
]
with patch("benchmark.time.perf_counter", side_effect=[0.0, 0.25, 1.0]):
return stream_once(
make_client(chunks),
model="qwen3:0.6b",
messages=[{"role": "user", "content": "hello"}],
max_tokens=8,
temperature=0.0,
)
def test_stream_once_uses_reasoning_chunks_for_ttft():
for field in ("reasoning_content", "reasoning"):
result = run_reasoning_stream(field)
assert result["ttft"] == 0.25, field
assert result["total"] == 1.0, field
assert result["output_tokens"] == 8.0, field
assert result["decode_tps"] == 8.0 / 0.75, field