fix(images): cache Telegram photos by unique_id and pass base64 to LLM commands
Stop reading image files inside gemini/mistral commands; use pre-encoded image data from message parts Rework loadImagesIfExists / loadImagesFromFileIds to return cached file_unique_ids and download only missing sizes Encode cached images to base64 when assembling the reply chain Make getPhotoMaxSize synchronous (returns PhotoSize), and map to URL only when needed Await MessageStore.put / UserStore.put and prefetch single-image downloads on message receipt
This commit is contained in:
@@ -13,7 +13,6 @@ import {
|
||||
oldReplyToMessage,
|
||||
startIntervalEditor
|
||||
} from "../util/utils";
|
||||
import fs from "node:fs";
|
||||
|
||||
export class GeminiChat extends ChatCommand {
|
||||
command = "gemini";
|
||||
@@ -66,10 +65,9 @@ export class GeminiChat extends ChatCommand {
|
||||
const images = messageParts[0].images;
|
||||
|
||||
images.forEach(image => {
|
||||
const base64Image = Buffer.from(fs.readFileSync(image)).toString("base64");
|
||||
input.push({
|
||||
type: "image",
|
||||
data: base64Image,
|
||||
data: image,
|
||||
mime_type: "image/png"
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,13 +7,11 @@ import {
|
||||
escapeMarkdownV2Text,
|
||||
logError,
|
||||
oldReplyToMessage,
|
||||
photoPathByUniqueId,
|
||||
startIntervalEditor
|
||||
} from "../util/utils";
|
||||
import {Environment} from "../common/environment";
|
||||
import {bot, mistralAi} from "../index";
|
||||
import {MessageStore} from "../common/message-store";
|
||||
import fs from "node:fs";
|
||||
|
||||
export class MistralChat extends ChatCommand {
|
||||
command = "mistral";
|
||||
@@ -46,10 +44,9 @@ export class MistralChat extends ChatCommand {
|
||||
});
|
||||
|
||||
for (const image of part.images) {
|
||||
const base64Image = Buffer.from(fs.readFileSync(photoPathByUniqueId(image))).toString("base64");
|
||||
content.push({
|
||||
type: "image_url",
|
||||
imageUrl: "data:image/jpeg;base64," + base64Image
|
||||
imageUrl: "data:image/jpeg;base64," + image
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user