FastAPI service wrapping the Surya-OCR-2 model (datalab-to) served through vLLM: legacy /v1/api/ai/* endpoints, an OpenAI-compatible /v1/chat/completions endpoint, a coalescing request batcher, a local OCR CLI, Docker packaging, multilingual example outputs, and quantization/concurrency benchmarks. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from scripts.parse_timing import parse_line, aggregate
|
|
|
|
SAMPLE = (
|
|
"2026-06-11 14:35:00 - vllm_batcher - _process_jobs - line:119 - INFO - "
|
|
"surya_timing_summary request_id=a,b batch_size=2 events=["
|
|
"{'name': 'openai_chat_completion', 'duration_ms': 100.0, 'metadata': {'token_count': 40}}, "
|
|
"{'name': 'openai_chat_completion', 'duration_ms': 300.0, 'metadata': {'token_count': 60}}, "
|
|
"{'name': 'recognition_manager_generate', 'duration_ms': 450.0}]"
|
|
)
|
|
|
|
|
|
def test_parse_line_extracts_events_and_batch_size():
|
|
rec = parse_line(SAMPLE)
|
|
assert rec["batch_size"] == 2
|
|
assert len(rec["events"]) == 3
|
|
assert rec["events"][0]["metadata"]["token_count"] == 40
|
|
|
|
|
|
def test_parse_line_returns_none_for_unrelated_line():
|
|
assert parse_line("2026-06-11 - foo - bar - line:1 - INFO - request_start id=x") is None
|
|
|
|
|
|
def test_aggregate_counts_and_sums_by_span_name():
|
|
rec = parse_line(SAMPLE)
|
|
agg = aggregate([rec])
|
|
chat = agg["openai_chat_completion"]
|
|
assert chat["count"] == 2
|
|
assert chat["total_ms"] == 400.0
|
|
assert chat["mean_ms"] == 200.0
|
|
assert chat["total_tokens"] == 100
|