ability to cancel ollama generation
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import {CallbackCommand} from "../base/callback-command";
|
||||
|
||||
export class Cancel extends CallbackCommand {
|
||||
|
||||
text = "❌ Отменить";
|
||||
data = null;
|
||||
|
||||
constructor(text?: string, data?: string) {
|
||||
super();
|
||||
|
||||
this.text = text ?? this.text;
|
||||
this.data = data ?? this.data;
|
||||
}
|
||||
|
||||
static withData(data?: string): Cancel {
|
||||
return new Cancel(null, data);
|
||||
}
|
||||
|
||||
async execute(): Promise<void> {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import {CallbackCommand} from "../base/callback-command";
|
||||
import {CallbackQuery} from "typescript-telegram-bot-api";
|
||||
import {abortOllamaRequest, bot, getOllamaRequest} from "../index";
|
||||
import {logError} from "../util/utils";
|
||||
|
||||
export class OllamaCancel extends CallbackCommand {
|
||||
|
||||
data = "/cancel_ollama";
|
||||
text = "Cancel Ollama generation";
|
||||
|
||||
async execute(query: CallbackQuery): Promise<void> {
|
||||
const chatId = query.message.chat.id;
|
||||
const fromId = query.from.id;
|
||||
const messageId = query.message.message_id;
|
||||
|
||||
const uuid = query.data.split(" ")[1];
|
||||
if (!uuid) return;
|
||||
|
||||
const request = getOllamaRequest(uuid);
|
||||
if (!request) return;
|
||||
if (request.fromId !== fromId) return;
|
||||
|
||||
const aborted = abortOllamaRequest(uuid);
|
||||
console.log(`aborted request ${uuid}:`, aborted);
|
||||
|
||||
await bot.editMessageReplyMarkup({
|
||||
chat_id: chatId,
|
||||
message_id: messageId,
|
||||
reply_markup: {inline_keyboard: []}
|
||||
}).catch(logError);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user