feat(api): chunk LLM correction for small context windows (+running glossary)
사내 GPT-4o 컨텍스트(<30k)에 맞춰 긴 전사를 문장 경계로 청크 분할하고, 각 청크 보정의 영문 용어를 '러닝 글로서리'로 다음 청크 system에 전달 → 큰 창 없이 강연 전체 용어 일관성 유지. config.llm_max_chars(기본 3000; ~8k창→1500/~16k→3000/~30k→6000). 과대 단일문장은 글자단위 강제 분할 안전망. 23 tests pass(청크 분할/글로서리 주입 포함), ruff clean. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -39,3 +39,21 @@ def test_llm_correct_monkeypatched(monkeypatch):
|
||||
monkeypatch.setattr(llm.urllib.request, "urlopen", fake_urlopen)
|
||||
out = llm.correct("인베딩 점마", base_url="http://x/v1", api_key="k", model="m")
|
||||
assert out == "EmbeddingGemma 복원됨"
|
||||
|
||||
|
||||
def test_llm_chunking_and_glossary(monkeypatch):
|
||||
"""긴 입력 → 청크 분할 + 러닝 글로서리(작은 컨텍스트 창 대응)."""
|
||||
calls: list[list[dict]] = []
|
||||
|
||||
def fake_request(messages, **_kw):
|
||||
calls.append(messages)
|
||||
return messages[1]["content"] # 청크 그대로 echo
|
||||
|
||||
monkeypatch.setattr(llm, "_request", fake_request)
|
||||
long_text = ". ".join(f"문장{i} EmbeddingGemma 설명" for i in range(400))
|
||||
out = llm.correct(long_text, base_url="http://x/v1", api_key="k", max_chars=200)
|
||||
|
||||
assert len(calls) > 1 # 분할됨
|
||||
assert "EmbeddingGemma" in out # 재조립됨
|
||||
# 2번째 청크부터 이전에 확정된 영문 표기가 system에 주입됨
|
||||
assert any("확정된 영문 표기" in m[0]["content"] for m in calls[1:])
|
||||
|
||||
Reference in New Issue
Block a user