bump libs
migrate to typescript 6 remove ytdl feature
This commit is contained in:
+27
-22
@@ -28,11 +28,12 @@ export class OllamaChat extends ChatCommand {
|
||||
|
||||
async execute(msg: Message, match?: RegExpExecArray | null): Promise<void> {
|
||||
console.log("match", match);
|
||||
return this.executeOllama(msg, match?.[3], match?.[1]?.toLowerCase()?.startsWith("ollamathink"));
|
||||
return this.executeOllama(msg, match?.[3] || "", match?.[1]?.toLowerCase()?.startsWith("ollamathink"));
|
||||
}
|
||||
|
||||
async executeOllama(msg: Message, text: string, think: boolean = false, voiceB64?: string): Promise<void> {
|
||||
if ((!text || text.trim().length === 0) && !voiceB64) return;
|
||||
async executeOllama(msg: Message, text: string, think: boolean = false, voiceB64?: string | null): Promise<void> {
|
||||
if (!msg.from) return;
|
||||
if ((!text || !text.trim().length) && !voiceB64) return;
|
||||
|
||||
const chatId = msg.chat.id;
|
||||
|
||||
@@ -66,7 +67,7 @@ export class OllamaChat extends ChatCommand {
|
||||
chatMessages.unshift({role: "system", content: Environment.SYSTEM_PROMPT, images: []});
|
||||
}
|
||||
|
||||
let waitMessage: Message;
|
||||
let waitMessage: Message | null = null;
|
||||
|
||||
const startTime = Date.now();
|
||||
|
||||
@@ -77,7 +78,7 @@ export class OllamaChat extends ChatCommand {
|
||||
|
||||
if (!think && imagesCount) {
|
||||
try {
|
||||
const modelInfo = await commands.find(c => c instanceof OllamaGetModel).loadImageModelInfo();
|
||||
const modelInfo = await commands.find(c => c instanceof OllamaGetModel)?.loadImageModelInfo();
|
||||
if (modelInfo) {
|
||||
if (!modelInfo.vision?.supported) {
|
||||
await replyToMessage({
|
||||
@@ -94,7 +95,7 @@ export class OllamaChat extends ChatCommand {
|
||||
|
||||
if (think) {
|
||||
try {
|
||||
const modelInfo = await commands.find(c => c instanceof OllamaGetModel).loadThinkModelInfo();
|
||||
const modelInfo = await commands.find(c => c instanceof OllamaGetModel)?.loadThinkModelInfo();
|
||||
if (modelInfo) {
|
||||
if (!modelInfo.thinking?.supported) {
|
||||
await replyToMessage({
|
||||
@@ -131,11 +132,11 @@ export class OllamaChat extends ChatCommand {
|
||||
}
|
||||
|
||||
const stream = await ollama.chat({
|
||||
model: think ? Environment.OLLAMA_THINK_MODEL : imagesCount ? Environment.OLLAMA_IMAGE_MODEL : Environment.OLLAMA_MODEL,
|
||||
model: <string>(think ? Environment.OLLAMA_THINK_MODEL : imagesCount ? Environment.OLLAMA_IMAGE_MODEL : Environment.OLLAMA_MODEL),
|
||||
stream: true,
|
||||
think: think,
|
||||
messages: chatMessages,
|
||||
options: options
|
||||
options: <Partial<Options>>options
|
||||
});
|
||||
|
||||
const newRequest = {
|
||||
@@ -170,7 +171,7 @@ export class OllamaChat extends ChatCommand {
|
||||
try {
|
||||
await bot.editMessageText({
|
||||
chat_id: chatId,
|
||||
message_id: waitMessage.message_id,
|
||||
message_id: <number>waitMessage?.message_id,
|
||||
text: escapeMarkdownV2Text(text),
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_markup: cancelMarkup
|
||||
@@ -178,9 +179,11 @@ export class OllamaChat extends ChatCommand {
|
||||
|
||||
console.log("editMessageText", text);
|
||||
|
||||
waitMessage.reply_to_message = msg;
|
||||
waitMessage.text = text;
|
||||
await MessageStore.put(waitMessage);
|
||||
if (waitMessage) {
|
||||
waitMessage.reply_to_message = msg;
|
||||
waitMessage.text = text;
|
||||
await MessageStore.put(waitMessage);
|
||||
}
|
||||
} catch (e) {
|
||||
logError(e);
|
||||
}
|
||||
@@ -225,7 +228,7 @@ export class OllamaChat extends ChatCommand {
|
||||
shouldBreak = true;
|
||||
}
|
||||
|
||||
if (getOllamaRequest(uuid).done) {
|
||||
if (getOllamaRequest(uuid)?.done) {
|
||||
shouldBreak = true;
|
||||
}
|
||||
|
||||
@@ -266,17 +269,19 @@ export class OllamaChat extends ChatCommand {
|
||||
}).catch(logError);
|
||||
console.log(`aborted request ${uuid}:`, abortOllamaRequest(uuid));
|
||||
}
|
||||
} catch (error) {
|
||||
if (error.message.toLowerCase().includes("aborted")) return;
|
||||
} catch (e: any) {
|
||||
if (e.message.toLowerCase().includes("aborted")) return;
|
||||
logError(e);
|
||||
|
||||
await bot.editMessageReplyMarkup({
|
||||
chat_id: chatId,
|
||||
message_id: waitMessage.message_id,
|
||||
reply_markup: {inline_keyboard: []}
|
||||
}).catch(logError);
|
||||
if (waitMessage) {
|
||||
await bot.editMessageReplyMarkup({
|
||||
chat_id: chatId,
|
||||
message_id: waitMessage.message_id,
|
||||
reply_markup: {inline_keyboard: []}
|
||||
}).catch(logError);
|
||||
|
||||
logError(error);
|
||||
await oldReplyToMessage(waitMessage, `Произошла ошибка!\n${error.toString()}`).catch(logError);
|
||||
await oldReplyToMessage(waitMessage, `Произошла ошибка!\n${e.toString()}`).catch(logError);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user