feat: rede_korrigieren.py -m/--model zur Modellwahl
Das Modell steckt in den Cache-Schlüsseln; ein anderes Modell rechnet neu. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
19b6bbf5a2
commit
7bc5e93613
1 changed files with 48 additions and 3 deletions
|
|
@ -46,6 +46,8 @@ def no_model_calls(*args, **kwargs):
|
|||
|
||||
def run_main(monkeypatch, *args):
|
||||
monkeypatch.setattr(sys, "argv", ["rede_korrigieren.py", *map(str, args)])
|
||||
# main() sets the module-wide model; restore it after the test
|
||||
monkeypatch.setattr(rk, "MODEL", rk.MODEL)
|
||||
rk.main()
|
||||
|
||||
|
||||
|
|
@ -301,6 +303,40 @@ def test_main_vtt_input_matches_txt_input(sample_copy, monkeypatch):
|
|||
) == expected.read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_main_model_option(sample_copy, monkeypatch):
|
||||
default = rk.MODEL
|
||||
used = []
|
||||
|
||||
def correct(chunk, index, system):
|
||||
used.append(rk.MODEL)
|
||||
return chunk.strip()
|
||||
|
||||
monkeypatch.setattr(rk, "correct_chunk", correct)
|
||||
monkeypatch.setattr(rk, "find_paragraph_starts", every_nth_start(5))
|
||||
parts = sample_copy.parent / "ramstein.de.korrigiert.parts"
|
||||
|
||||
run_main(monkeypatch, "-i", sample_copy)
|
||||
default_parts = {p.name for p in parts.glob("part*")}
|
||||
run_main(monkeypatch, "-i", sample_copy, "-m", "anderes:7b")
|
||||
|
||||
assert set(used) == {default, "anderes:7b"}
|
||||
# Another model must not reuse the cached parts of the default model
|
||||
assert {p.name for p in parts.glob("part*")} - default_parts
|
||||
|
||||
|
||||
def test_correct_chunk_sends_model(monkeypatch):
|
||||
sent = {}
|
||||
|
||||
def urlopen(request, timeout=None):
|
||||
sent.update(json.loads(request.data))
|
||||
return FakeResponse(stream_body(["Text."]))
|
||||
|
||||
monkeypatch.setattr(rk, "MODEL", "anderes:7b")
|
||||
monkeypatch.setattr(rk.urllib.request, "urlopen", urlopen)
|
||||
rk.correct_chunk("Text.", 1, "system")
|
||||
assert sent["model"] == "anderes:7b"
|
||||
|
||||
|
||||
def test_main_warns_on_word_count_deviation(sample_copy, monkeypatch, capsys):
|
||||
def shortening(chunk, index, system):
|
||||
words = chunk.split()
|
||||
|
|
|
|||
Loading…
Reference in a new issue