From 8ac057b80acc884368edcd00ada034a6b2bf2440 Mon Sep 17 00:00:00 2001 From: Index Date: Sun, 9 Nov 2025 22:23:39 -0600 Subject: [PATCH] feat: model overload error --- docker-compose.yml | 7 +++++-- src/core.ts | 3 +++ src/handlers/messages.ts | 11 ++++++++--- src/utils/conversation.ts | 5 ++--- src/utils/post.ts | 6 +++--- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 3dd3bd9..dd03094 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,7 +6,7 @@ services: environment: - "AUTHORIZED_USERS=${AUTHORIZED_USERS}" - "SERVICE=${SERVICE:?https://bsky.social}" - - "DB_PATH=sqlite.db" + - DB_PATH=/data/sqlite.db - "GEMINI_MODEL=${GEMINI_MODEL:-gemini-2.5-flash}" - "DID=${DID:?}" - "HANDLE=${HANDLE:?}" @@ -14,4 +14,7 @@ services: - "GEMINI_API_KEY=${GEMINI_API_KEY:?}" - "USE_JETSTREAM=${USE_JETSTREAM:-false}" volumes: - - aero_db:/sqlite.db + - "aero_db:/data" + +volumes: + aero_db: diff --git a/src/core.ts b/src/core.ts index d78400d..cd0e687 100644 --- a/src/core.ts +++ b/src/core.ts @@ -63,6 +63,9 @@ export const ai = new GoogleGenAI({ export const QUOTA_EXCEEDED_MESSAGE = "You have exceeded your daily message quota (15). Please wait 24 hours before trying again."; +export const ERROR_MESSAGE = + "Sorry, I ran into an issue analyzing that post. Please try again."; + export const UNAUTHORIZED_MESSAGE = "I can’t make sense of your noise just yet. You’ll need to be whitelisted before I can help."; diff --git a/src/handlers/messages.ts b/src/handlers/messages.ts index 47cd4c5..755a74f 100644 --- a/src/handlers/messages.ts +++ b/src/handlers/messages.ts @@ -174,12 +174,17 @@ export async function handler(message: ChatMessage): Promise { }); } } - } catch (error) { + } catch (error: any) { logger.error("Error in post handler:", error); + let errorMsg = c.ERROR_MESSAGE; + + if (error.error.code == 503) { + errorMsg = + "Sorry, the AI model is currently overloaded. Please try again later."; + } await conversation.sendMessage({ - text: - "Sorry, I ran into an issue analyzing that post. Please try again.", + text: errorMsg, }); } } diff --git a/src/utils/conversation.ts b/src/utils/conversation.ts index 6fd5d45..aeb9026 100644 --- a/src/utils/conversation.ts +++ b/src/utils/conversation.ts @@ -8,7 +8,7 @@ import db from "../db"; import { conversations, messages } from "../db/schema"; import { and, eq } from "drizzle-orm"; import { env } from "../env"; -import { bot, MAX_GRAPHEMES } from "../core"; +import { bot, ERROR_MESSAGE, MAX_GRAPHEMES } from "../core"; import { parsePost, parsePostImages, traverseThread } from "./post"; /* @@ -137,8 +137,7 @@ export async function parseConversation( }; } catch (e) { convo.sendMessage({ - text: - "Sorry, I ran into an issue analyzing that post. Please try again.", + text: ERROR_MESSAGE, }); throw new Error("Failed to parse conversation"); diff --git a/src/utils/post.ts b/src/utils/post.ts index 6d0782f..c893732 100644 --- a/src/utils/post.ts +++ b/src/utils/post.ts @@ -42,8 +42,6 @@ async function parseQuote(post: Post) { ) return undefined; const record = (post.embed as RecordEmbed || RecordWithMediaEmbed).record; - console.log("embed: ", post.embed); - console.log("record: ", record); const embedPost = await c.bot.getPost(record.uri); return await parsePost(embedPost, false); @@ -63,7 +61,9 @@ export function parsePostImages(post: Post) { } } - return images.map((image, idx) => parseImage(image, idx + 1)); + return images.map((image, idx) => parseImage(image, idx + 1)).filter((img) => + img.alt.length > 0 + ); } function parseImage(image: EmbedImage, index: number) {