Skip to content

Commit b474b84

Browse files
committed
get rid of try catch
1 parent 932b6f9 commit b474b84

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

packages/main/src/telegram_api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ export default class TelegramApi {
3232
* @param token - bot token
3333
*/
3434
async getFile(botApi: string, data: Record<string, number | string | boolean>, token: string) {
35+
if (data.file_id === '') {
36+
return new Response();
37+
}
3538
const url = this.getApiUrl(botApi, 'getFile', data);
3639
const response = await fetch(url);
3740
const json: { result: { file_path: string } } = await response.json();

packages/worker/src/worker.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ export default {
282282
const file_response = await bot.getFile(file_id);
283283
const blob = await file_response.arrayBuffer();
284284
const prompt = bot.update.business_message?.text?.toString() ?? bot.update.business_message?.caption ?? '';
285-
if (bot.update.business_message?.from.id !== 69148517) {
285+
if (bot.update.business_message?.from.id !== 69148518) {
286286
const { results } = await env.DB.prepare('SELECT * FROM Messages WHERE userId=?')
287287
.bind(bot.update.business_message?.from.id)
288288
.all();
@@ -300,14 +300,14 @@ export default {
300300
},
301301
];
302302
let response: AiTextGenerationOutput;
303+
console.log(blob.byteLength);
303304
try {
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);
305+
if (blob.byteLength === 0) {
309306
// @ts-expect-error broken bindings
310307
response = await env.AI.run('@cf/meta/llama-3.2-11b-vision-instruct', { messages });
308+
} else {
309+
// @ts-expect-error broken bindings
310+
response = await env.AI.run('@cf/meta/llama-3.2-11b-vision-instruct', { messages, image: [...new Uint8Array(blob)] });
311311
}
312312
} catch (e) {
313313
console.log(e);

0 commit comments

Comments
 (0)