Remove env fallback for model choices
This commit is contained in:
@@ -44,7 +44,6 @@ class ModelChoice:
|
||||
@dataclass(frozen=True)
|
||||
class ModelOptions:
|
||||
models: tuple[ModelChoice, ...]
|
||||
fallback: bool = False
|
||||
error: str | None = None
|
||||
|
||||
def by_value(self, value: str | None) -> ModelChoice | None:
|
||||
@@ -208,15 +207,6 @@ def _codex_config() -> CodexConfig:
|
||||
return CodexConfig(codex_bin=config.CODEX_BIN)
|
||||
|
||||
|
||||
def _fallback_model_options(error: str | None = None) -> ModelOptions:
|
||||
all_efforts = tuple(effort.value for effort in ReasoningEffort)
|
||||
models = tuple(
|
||||
ModelChoice(label=label, value=value, efforts=all_efforts)
|
||||
for label, value in config.MODEL_CHOICES
|
||||
)
|
||||
return ModelOptions(models=models, fallback=True, error=error)
|
||||
|
||||
|
||||
def _reasoning_efforts(raw_options: Any) -> tuple[str, ...]:
|
||||
efforts: list[str] = []
|
||||
for option in raw_options or []:
|
||||
@@ -235,7 +225,7 @@ async def list_model_options() -> ModelOptions:
|
||||
|
||||
response = await codex.models()
|
||||
except Exception as exc:
|
||||
return _fallback_model_options(error=str(exc))
|
||||
return ModelOptions(models=(), error=str(exc))
|
||||
|
||||
models: list[ModelChoice] = []
|
||||
for model in response.data:
|
||||
@@ -251,7 +241,7 @@ async def list_model_options() -> ModelOptions:
|
||||
)
|
||||
|
||||
if not models:
|
||||
return _fallback_model_options(error="Codex returned no visible models")
|
||||
return ModelOptions(models=(), error="Codex returned no visible models")
|
||||
|
||||
return ModelOptions(models=tuple(models))
|
||||
|
||||
|
||||
@@ -37,28 +37,3 @@ SYSTEM_PROMPT = os.environ.get(
|
||||
"Execute the tasks you are given carefully. Answer concisely: the reply is shown "
|
||||
"in a Telegram chat. Reply in the same language the user writes in.",
|
||||
)
|
||||
|
||||
|
||||
def _parse_model_choices(raw: str) -> list[tuple[str, str]]:
|
||||
choices: list[tuple[str, str]] = []
|
||||
for item in raw.split(","):
|
||||
item = item.strip()
|
||||
if not item:
|
||||
continue
|
||||
if "=" in item:
|
||||
label, value = item.split("=", 1)
|
||||
else:
|
||||
label = value = item
|
||||
label = label.strip()
|
||||
value = value.strip()
|
||||
if label and value:
|
||||
choices.append((label, value))
|
||||
return choices
|
||||
|
||||
|
||||
MODEL_CHOICES = _parse_model_choices(
|
||||
os.environ.get(
|
||||
"CODEX_MODEL_CHOICES",
|
||||
"GPT-5.5=gpt-5.5,GPT-5.4=gpt-5.4,GPT-5.4 mini=gpt-5.4-mini",
|
||||
)
|
||||
)
|
||||
|
||||
14
bot/main.py
14
bot/main.py
@@ -174,11 +174,14 @@ async def cmd_compact(_, message: Message):
|
||||
async def cmd_model(_, message: Message):
|
||||
loading = await message.reply_text("Загружаю список моделей Codex...")
|
||||
options = await _model_options()
|
||||
text = MODEL_TEXT
|
||||
if options.fallback:
|
||||
text += "\n\nНе удалось получить live-список, показываю fallback из env."
|
||||
if options.error or not options.models:
|
||||
await loading.edit_text(
|
||||
"Не удалось загрузить список моделей из Codex. "
|
||||
"Проверьте авторизацию и логи бота."
|
||||
)
|
||||
return
|
||||
await loading.edit_text(
|
||||
text,
|
||||
MODEL_TEXT,
|
||||
parse_mode=ParseMode.MARKDOWN,
|
||||
reply_markup=_model_keyboard(message.chat.id, options),
|
||||
)
|
||||
@@ -198,6 +201,9 @@ async def on_settings_callback(_, query: CallbackQuery):
|
||||
value = raw or None
|
||||
chat_id = query.message.chat.id
|
||||
options = await _model_options()
|
||||
if options.error or not options.models:
|
||||
log.warning("Model options reload failed: %s", options.error)
|
||||
return
|
||||
chats.set(chat_id, key, value)
|
||||
if key == "model":
|
||||
current_effort = chats.get(chat_id, "effort")
|
||||
|
||||
Reference in New Issue
Block a user