messages.parse() с pydantic-схемой (валидация на клиенте), adaptive thinking, кэш system-промпта, замер usage и стоимости на лекцию. CLI build_knowledge.py: --source/--limit/--lecture/--dry-run/--force, выход в data/knowledge/<лекция>.json. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
"""Сборка запроса извлечения — проверяется без API."""
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from rag import config, corpus
|
|
from rag.extract import extract
|
|
from rag.extract.cards import ExtractionResult
|
|
|
|
|
|
@pytest.fixture()
|
|
def lecture(tmp_path: Path) -> corpus.Lecture:
|
|
seg = tmp_path / "segments.txt"
|
|
seg.write_text("[00:01] тестовый сегмент про 80 кГц\n", encoding="utf-8")
|
|
return corpus.Lecture(id="тест-лекция", fragments=(
|
|
corpus.Transcript(id="тест-лекция__фрагмент1", source="mass", path=seg),
|
|
))
|
|
|
|
|
|
def test_request_has_model_and_schema(lecture):
|
|
kw = extract.build_request_kwargs(lecture)
|
|
assert kw["model"] == "claude-opus-4-8"
|
|
assert kw["output_format"] is ExtractionResult
|
|
assert kw["thinking"] == {"type": "adaptive"}
|
|
|
|
|
|
def test_request_system_is_cached_and_has_glossary(lecture):
|
|
kw = extract.build_request_kwargs(lecture)
|
|
sys_block = kw["system"][0]
|
|
assert sys_block["cache_control"] == {"type": "ephemeral"}
|
|
# живой словарь из docs/glossary.md подставлен
|
|
assert "IR2153" in sys_block["text"]
|
|
|
|
|
|
def test_request_user_contains_fragment_marker_and_text(lecture):
|
|
kw = extract.build_request_kwargs(lecture)
|
|
user_text = kw["messages"][0]["content"]
|
|
assert "=== ФРАГМЕНТ: тест-лекция__фрагмент1 ===" in user_text
|
|
assert "тестовый сегмент про 80 кГц" in user_text
|
|
assert "Лекция: тест-лекция" in user_text
|
|
|
|
|
|
def test_cost_constants_positive():
|
|
# цены заданы и стоимость считается из usage, не из воздуха
|
|
assert extract.PRICE_IN > 0 and extract.PRICE_OUT > extract.PRICE_IN
|