Skip to content

Commit bd34e36

Browse files
committed
photos in business mode work now
1 parent f9863d2 commit bd34e36

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

packages/main/src/telegram_execution_context.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default class TelegramExecutionContext {
3535
this.update_type = 'document';
3636
} else if (this.update.callback_query?.id) {
3737
this.update_type = 'callback';
38-
} else if (this.update.business_message?.text) {
38+
} else if (this.update.business_message) {
3939
this.update_type = 'business_message';
4040
}
4141
}

packages/worker/src/worker.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,14 @@ export default {
147147
};
148148
let response: AiImageToTextOutput;
149149
try {
150-
response = await env.AI.run('@cf/llava-hf/llava-1.5-7b-hf', input);
150+
// @ts-expect-error broken bindings
151+
response = await env.AI.run('@cf/meta/llama-3.2-11b-vision-instruct', input);
151152
} catch (e) {
152153
console.log(e);
153154
await bot.reply(`Error: ${e as string}`);
154155
return new Response('ok');
155156
}
156-
await bot.replyPhoto(file_id, response.description);
157+
await bot.replyPhoto(file_id, (response as unknown as { response: string }).response);
157158
}
158159
return new Response('ok');
159160
})
@@ -277,8 +278,11 @@ export default {
277278
}
278279
case 'business_message': {
279280
await bot.sendTyping();
280-
const prompt = bot.update.business_message?.text?.toString() ?? '';
281-
if (bot.update.business_message?.from.id !== 69148517) {
281+
const file_id: string = bot.update.business_message?.photo?.pop()?.file_id ?? '';
282+
const file_response = await bot.getFile(file_id);
283+
const blob = await file_response.arrayBuffer();
284+
const prompt = bot.update.business_message?.text?.toString() ?? bot.update.business_message?.caption ?? '';
285+
if (bot.update.business_message?.from.id !== 69148518) {
282286
const { results } = await env.DB.prepare('SELECT * FROM Messages WHERE userId=?')
283287
.bind(bot.update.business_message?.from.id)
284288
.all();
@@ -297,8 +301,14 @@ export default {
297301
];
298302
let response: AiTextGenerationOutput;
299303
try {
300-
// @ts-expect-error broken bindings
301-
response = await env.AI.run('@cf/meta/llama-3.2-11b-vision-instruct', { messages });
304+
try {
305+
// @ts-expect-error broken bindings
306+
response = await env.AI.run('@cf/meta/llama-3.2-11b-vision-instruct', { messages, image: [...new Uint8Array(blob)] });
307+
} catch (e) {
308+
console.log(e);
309+
// @ts-expect-error broken bindings
310+
response = await env.AI.run('@cf/meta/llama-3.2-11b-vision-instruct', { messages });
311+
}
302312
} catch (e) {
303313
console.log(e);
304314
await bot.reply(`Error: ${e as string}`);

0 commit comments

Comments
 (0)