Files
tg-chat-bot/src/commands/ollama-set-model.ts
T
melod1n 13b41c3026 bump libs
migrate to typescript 6
remove ytdl feature
2026-05-01 07:05:17 +03:00

35 lines
1.3 KiB
TypeScript

import {Message} from "typescript-telegram-bot-api";
import {Command} from "../base/command";
import {Environment} from "../common/environment";
import {logError, replyToMessage} from "../util/utils";
import {Requirements} from "../base/requirements";
import {Requirement} from "../base/requirement";
import {ollama} from "../index";
export class OllamaSetModel extends Command {
argsMode = "required" as const;
title = "/ollamaSetModel";
description = "Set Ollama model";
requirements = Requirements.Build(Requirement.BOT_CREATOR);
async execute(msg: Message, match?: RegExpExecArray | null): Promise<void> {
const newModel = match?.[3] || "";
if (!newModel || !newModel.length) return;
try {
await ollama.show({model: newModel});
Environment.setOllamaModel(newModel || <string>Environment.OLLAMA_MODEL);
const text = newModel ? `Выбрана модель "${newModel}"`
: `Модель не задана. Будет использоваться стандартная модель "${Environment.OLLAMA_MODEL}".`;
await replyToMessage({message: msg, text: text}).catch(logError);
} catch (e: any) {
logError(e);
await replyToMessage({message: msg, text: e.toString()}).catch(logError);
}
}
}