mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 10:56:10 +00:00
Merge pull request #54 from yusufipk/codex-model-list
Ask Codex itself which models it offers
This commit is contained in:
+47
-1
@@ -17,7 +17,8 @@ import unittest
|
||||
from unittest import mock
|
||||
|
||||
from dikte import assistant
|
||||
from tests.support import DikteTest, fake_urlopen, only_these_tools
|
||||
from tests.support import (DikteTest, FakeCompleted, fake_urlopen,
|
||||
only_these_tools)
|
||||
|
||||
|
||||
class FakeCli:
|
||||
@@ -664,5 +665,50 @@ class Ask(DikteTest):
|
||||
self.assertEqual(len(calls), 1)
|
||||
|
||||
|
||||
class CodexModels(DikteTest):
|
||||
"""The model list read off `codex debug models`."""
|
||||
|
||||
CATALOG = {"models": [
|
||||
{"slug": "gpt-6-mini", "visibility": "list", "priority": 9},
|
||||
{"slug": "gpt-6", "visibility": "list", "priority": 1},
|
||||
{"slug": "codex-auto-review", "visibility": "hide", "priority": 3},
|
||||
]}
|
||||
|
||||
def models(self, reply, code=0):
|
||||
with only_these_tools("codex"), \
|
||||
mock.patch.object(subprocess, "run",
|
||||
return_value=FakeCompleted(
|
||||
returncode=code, stdout=reply)) as run:
|
||||
found = assistant.codex_models()
|
||||
self.run_call = run
|
||||
return found
|
||||
|
||||
def test_the_catalog_arrives_best_first_without_the_hidden_ones(self):
|
||||
found = self.models(json.dumps(self.CATALOG))
|
||||
self.assertEqual(found, ["gpt-6", "gpt-6-mini"])
|
||||
self.assertEqual(self.run_call.call_args.args[0],
|
||||
["codex", "debug", "models"])
|
||||
|
||||
def test_a_codex_that_is_not_installed_is_not_run(self):
|
||||
with only_these_tools(), \
|
||||
mock.patch.object(subprocess, "run") as run:
|
||||
self.assertEqual(assistant.codex_models(), [])
|
||||
run.assert_not_called()
|
||||
|
||||
def test_a_codex_too_old_to_have_the_command(self):
|
||||
self.assertEqual(self.models("error: unknown subcommand", code=2), [])
|
||||
|
||||
def test_a_catalog_that_is_not_what_was_expected(self):
|
||||
self.assertEqual(self.models(json.dumps(["gpt-6"])), [])
|
||||
self.assertEqual(self.models(""), [])
|
||||
|
||||
def test_a_codex_that_hangs_is_given_up_on(self):
|
||||
with only_these_tools("codex"), \
|
||||
mock.patch.object(subprocess, "run",
|
||||
side_effect=subprocess.TimeoutExpired(
|
||||
["codex"], 30)):
|
||||
self.assertEqual(assistant.codex_models(), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
+21
-1
@@ -133,6 +133,8 @@ class Settings(DikteTest):
|
||||
"_load_models"))
|
||||
self.enterContext(mock.patch.object(settings_ui.SettingsWindow,
|
||||
"_load_transcribe_models"))
|
||||
self.enterContext(mock.patch.object(settings_ui.SettingsWindow,
|
||||
"_load_codex_models"))
|
||||
# The local model boxes fetch their own list the moment they are shown,
|
||||
# from a thread, which is nobody's test failing but a real request.
|
||||
self.enterContext(mock.patch.object(settings_ui.LocalModelBox,
|
||||
@@ -269,6 +271,19 @@ class Settings(DikteTest):
|
||||
self.assertEqual(shown, [provider])
|
||||
self.assertFalse(box.isHidden())
|
||||
|
||||
def test_codex_answering_refills_both_of_its_boxes(self):
|
||||
"""The list Codex gave replaces the built-in one, in both places, and
|
||||
neither loses what was already picked."""
|
||||
conf = self.config(cleanup_codex_model="my-own-model")
|
||||
window = self.window(conf)
|
||||
window._on_codex_models_loaded(["gpt-6", "gpt-6-mini"])
|
||||
for combo in (window.cleanup_codex_model, window.assistant_codex_model):
|
||||
with self.subTest(combo=combo.objectName() or "combo"):
|
||||
offered = [combo.itemText(i) for i in range(combo.count())]
|
||||
self.assertEqual(offered[1:], ["gpt-6", "gpt-6-mini"])
|
||||
self.assertEqual(window.cleanup_codex_model.currentText(),
|
||||
"my-own-model")
|
||||
|
||||
def test_the_update_line_names_the_version_that_is_running(self):
|
||||
window = self.window(cfg.Config())
|
||||
self.assertIn(settings_ui.__version__, window.update_status.text())
|
||||
@@ -984,7 +999,9 @@ class MeetingSources(DikteTest):
|
||||
only_these_tools(), \
|
||||
mock.patch.object(settings_ui.SettingsWindow, "_load_models"), \
|
||||
mock.patch.object(settings_ui.SettingsWindow,
|
||||
"_load_transcribe_models"):
|
||||
"_load_transcribe_models"), \
|
||||
mock.patch.object(settings_ui.SettingsWindow,
|
||||
"_load_codex_models"):
|
||||
window = settings_ui.SettingsWindow(cfg.Config())
|
||||
self.addCleanup(window.deleteLater)
|
||||
self.addCleanup(window.close)
|
||||
@@ -1013,6 +1030,9 @@ class LocalModels(DikteTest):
|
||||
# "nothing can transcribe" question from its real binary and model.
|
||||
self.patch_attr(ggml, "BIN_DIR", self.path("bin"))
|
||||
self.patch_attr(ggml, "MODELS_DIR", self.path("models"))
|
||||
# And one with Codex on it would ask it for its model list.
|
||||
self.enterContext(mock.patch.object(settings_ui.SettingsWindow,
|
||||
"_load_codex_models"))
|
||||
|
||||
def window(self, conf):
|
||||
window = settings_ui.SettingsWindow(conf)
|
||||
|
||||
Reference in New Issue
Block a user