shitton of the ai changes
This commit is contained in:
+55
-51
@@ -2,66 +2,70 @@ import {ChatCommand} from "../base/chat-command";
|
||||
import {Message} from "typescript-telegram-bot-api";
|
||||
import {callbackCommands, commands} from "../index";
|
||||
import {Environment} from "../common/environment";
|
||||
import {boolToEmoji, getCurrentModel, getCurrentModelCapabilities, logError, replyToMessage} from "../util/utils";
|
||||
import {AiModelCapabilities} from "../model/ai-model-capabilities";
|
||||
import {logError, replyToMessage} from "../util/utils";
|
||||
import {AiProvider} from "../model/ai-provider";
|
||||
import {Command} from "../base/command";
|
||||
import {getProviderTools} from "../ai/tool-mappers";
|
||||
import {prepareTelegramMarkdownV2} from "../util/markdown-v2-renderer";
|
||||
import {resolveEffectiveAiProviderForUser} from "../common/user-ai-settings";
|
||||
import {getFormattedCapabilities} from "../ai/provider-model-runtime";
|
||||
|
||||
export class Info extends Command {
|
||||
command = ["info", "v"];
|
||||
|
||||
title = "/info";
|
||||
description = "Info about bot";
|
||||
title = Environment.commandTitles.info;
|
||||
description = Environment.commandDescriptions.info;
|
||||
|
||||
async execute(msg: Message): Promise<void> {
|
||||
const aiProvider = Environment.DEFAULT_AI_PROVIDER;
|
||||
const aiModel = getCurrentModel();
|
||||
let aiModelCapabilities: AiModelCapabilities = {};
|
||||
if (!msg.from) return;
|
||||
|
||||
try {
|
||||
aiModelCapabilities = await getCurrentModelCapabilities();
|
||||
} catch (e) {
|
||||
logError(e);
|
||||
await replyToMessage({message: msg, text: `Произошла ошибка: ${e}`}).catch(logError);
|
||||
return;
|
||||
}
|
||||
const getToolsInfo = async () => {
|
||||
const tools = getProviderTools(provider);
|
||||
return Environment.getInfoToolsBlockText(tools.map(t => t.function.name));
|
||||
};
|
||||
|
||||
const getCommandsInfo = async () => {
|
||||
const cmds = commands.filter(c => !(c instanceof ChatCommand));
|
||||
const chatCmds = commands.filter(c => c instanceof ChatCommand);
|
||||
const callbackCmds = callbackCommands;
|
||||
const publicCmdsLength = cmds.filter(c => c.requirements?.isPublic()).length;
|
||||
const privateCmdsLength = cmds.length - publicCmdsLength;
|
||||
const chatCmdsLength = chatCmds.length;
|
||||
const callbackCmdsLength = callbackCmds.length;
|
||||
|
||||
return Environment.getInfoCommandsBlockText({
|
||||
publicCommands: publicCmdsLength,
|
||||
privateCommands: privateCmdsLength,
|
||||
chatCommands: chatCmdsLength,
|
||||
callbackCommands: callbackCmdsLength,
|
||||
});
|
||||
};
|
||||
|
||||
const provider = await resolveEffectiveAiProviderForUser(msg.from.id);
|
||||
// const aiProvidersLength = Object.keys(AiProvider).filter(key => isNaN(Number(key))).length;
|
||||
const aiProviders = Object.keys(AiProvider).map(p => p.toLowerCase());
|
||||
|
||||
const finalText = [
|
||||
`\`\`\`${Environment.runtimeProviderLabelText}`,
|
||||
`${Environment.infoSupportedProvidersLabelText}: ${aiProviders.join(", ")}`,
|
||||
`${Environment.runtimeProviderCurrentLabelText}: ${provider.toLowerCase()}`,
|
||||
"```",
|
||||
"",
|
||||
|
||||
`\`\`\`${Environment.runtimeCapabilitiesLabelText}`,
|
||||
(await getFormattedCapabilities(provider)).join("\n"),
|
||||
"```",
|
||||
"",
|
||||
|
||||
await getToolsInfo(),
|
||||
await getCommandsInfo()
|
||||
].join("\n");
|
||||
|
||||
|
||||
const aiInfo = "```" +
|
||||
"AI\n" +
|
||||
`supported providers: ${Object.keys(AiProvider).filter(key => isNaN(Number(key))).length}\n\n` +
|
||||
|
||||
`provider: ${aiProvider.toLowerCase()}\n` +
|
||||
`model: ${aiModel}\n\n` +
|
||||
`vision${aiModelCapabilities.vision?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities.vision?.supported)}\n` +
|
||||
`ocr${aiModelCapabilities.ocr?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities.ocr?.supported)}\n` +
|
||||
`thinking${aiModelCapabilities.thinking?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities.thinking?.supported)}\n` +
|
||||
`tools${aiModelCapabilities.tools?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities.tools?.supported)}` +
|
||||
"```";
|
||||
|
||||
const cmds = commands.filter(c => !(c instanceof ChatCommand));
|
||||
const chatCmds = commands.filter(c => c instanceof ChatCommand);
|
||||
const callbackCmds = callbackCommands;
|
||||
|
||||
const publicCmdsLength = cmds.filter(c => c.requirements?.isPublic()).length;
|
||||
const privateCmdsLength = cmds.length - publicCmdsLength;
|
||||
|
||||
const chatCmdsLength = chatCmds.length;
|
||||
|
||||
const callbackCmdsLength = callbackCmds.length;
|
||||
|
||||
const text =
|
||||
aiInfo + "\n\n" +
|
||||
|
||||
"```" +
|
||||
"Commands\n" +
|
||||
`Public: ${publicCmdsLength}\n` +
|
||||
`Private: ${privateCmdsLength}\n` +
|
||||
`Chat: ${chatCmdsLength}\n` +
|
||||
`Callback: ${callbackCmdsLength}\n` +
|
||||
"```"
|
||||
;
|
||||
|
||||
await replyToMessage({message: msg, text: text, parse_mode: "Markdown"}).catch(logError);
|
||||
await replyToMessage({
|
||||
message: msg,
|
||||
text: prepareTelegramMarkdownV2(finalText, {mode: "final"}),
|
||||
parse_mode: "MarkdownV2"
|
||||
}).catch(logError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user