Dispatch chat models by config type, not hardcoded lists

Replace the hardcoded model-name sets in __init__, send_message and
send_message_stream with checks against config/models.yml: the assert
now accepts any model defined in models['info'], and the chat path is
taken for any model whose type is 'chat_completion'. Adding a new
chat model is now a models.yml-only change. Vision handling is left
on its explicit model set for now.
This commit is contained in:
Father Bot
2026-02-28 18:47:09 +03:00
parent ee9dae189f
commit 6af26cc9bc
+3 -3
View File
@@ -27,7 +27,7 @@ OPENAI_COMPLETION_OPTIONS = {
class ChatGPT:
def __init__(self, model="gpt-4o-mini"):
assert model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4", "gpt-4o", "gpt-4o-mini", "gpt-4-1106-preview", "gpt-4-vision-preview"}, f"Unknown model: {model}"
assert model in config.models["info"], f"Unknown model: {model}"
self.model = model
async def send_message(self, message, dialog_messages=[], chat_mode="assistant"):
@@ -38,7 +38,7 @@ class ChatGPT:
answer = None
while answer is None:
try:
if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4", "gpt-4o", "gpt-4o-mini", "gpt-4-1106-preview", "gpt-4-vision-preview"}:
if config.models["info"][self.model]["type"] == "chat_completion":
messages = self._generate_prompt_messages(message, dialog_messages, chat_mode)
r = await openai_client.chat.completions.create(
@@ -71,7 +71,7 @@ class ChatGPT:
answer = None
while answer is None:
try:
if self.model in {"gpt-3.5-turbo-16k", "gpt-3.5-turbo", "gpt-4","gpt-4o", "gpt-4o-mini", "gpt-4-1106-preview"}:
if config.models["info"][self.model]["type"] == "chat_completion":
messages = self._generate_prompt_messages(message, dialog_messages, chat_mode)
r_gen = await openai_client.chat.completions.create(