From b8cd35540fe45900e5ba1748c554d759f29e1e9c04ba9182360935b68ed33c11 Mon Sep 17 00:00:00 2001 From: aslan Date: Sat, 24 Jan 2026 04:55:25 -0500 Subject: [PATCH] Add smart models --- src/modules/ai/ai.ts | 7 ++++++- src/modules/game/game.ts | 1 - src/services/ai/ai.ts | 20 ++++++++++++++++---- src/services/ai/tools.ts | 17 ++++++++++++++++- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/modules/ai/ai.ts b/src/modules/ai/ai.ts index ef072f4..702887b 100644 --- a/src/modules/ai/ai.ts +++ b/src/modules/ai/ai.ts @@ -46,6 +46,8 @@ const onAI = async ( let personality = config.app.ai.personalities[state.personality.index]; + const useSmartModel = text.startsWith("!aipro"); + let textMod = text.replace("!ai", "").trim(); let instructions = { prefferedLanguages: ["english", "slovak"], @@ -72,6 +74,7 @@ const onAI = async ( roomId: roomId, sender: sender, }, + useSmartModel, instructions, `${username}: ${textMod}`, `${repliedUsername}: ${repliedMessage}`, @@ -100,6 +103,8 @@ const onAI = async ( const onImageGen = async (text: string, roomId: string, sender: string) => { const user = getUserById(sender); + const useSmartModel = text.startsWith("!imgpro"); + let textMod = text.replace("!img", "").trim().toLowerCase(); alts.forEach((alt) => { alt.keys.forEach((key) => { @@ -107,7 +112,7 @@ const onImageGen = async (text: string, roomId: string, sender: string) => { }); }); - const responseAI = await getImageGemini(textMod); + const responseAI = await getImageGemini(textMod, useSmartModel); user.aiCost += responseAI.tokens * prices.image; if (!responseAI.image || responseAI.image.length < 10) { diff --git a/src/modules/game/game.ts b/src/modules/game/game.ts index 1a55dad..42cacc6 100644 --- a/src/modules/game/game.ts +++ b/src/modules/game/game.ts @@ -3,7 +3,6 @@ import type { ICallbackStore } from "../types.js"; import { config } from "../../config.js"; import { existsEntity, - getEntitiesAtLocation, getEntityByName, getHealthPercentage, getMaxHealth, diff --git a/src/services/ai/ai.ts b/src/services/ai/ai.ts index 157d51f..4a7ccc5 100644 --- a/src/services/ai/ai.ts +++ b/src/services/ai/ai.ts @@ -19,6 +19,7 @@ const googleAI = new GoogleGenAI({ const getTextGemini = async ( matrixData: AIToolMatrixData, + smartModel: boolean, instructions: IAIInstructions, input: string, oldInput?: string, @@ -82,7 +83,9 @@ const getTextGemini = async ( let response: GenerateContentResponse; try { response = await googleAI.models.generateContent({ - model: "gemini-3-flash-preview", + model: smartModel + ? "gemini-3-pro-preview" + : "gemini-3-flash-preview", contents: contents, config: { systemInstruction: JSON.stringify(instructions), @@ -140,7 +143,9 @@ const getTextGemini = async ( let responseTool: GenerateContentResponse; try { responseTool = await googleAI.models.generateContent({ - model: "gemini-3-flash-preview", + model: smartModel + ? "gemini-3-pro-preview" + : "gemini-3-flash-preview", contents: [ ...contents, content, @@ -176,11 +181,18 @@ const getTextGemini = async ( }; }; -const getImageGemini = async (input: string): Promise => { +const getImageGemini = async ( + input: string, + smartModel: boolean, +): Promise => { + log(`AI Image Request: ${input}`); + let response: GenerateContentResponse; try { response = await googleAI.models.generateContent({ - model: "gemini-2.5-flash-image", + model: smartModel + ? "gemini-3-pro-image-preview" + : "gemini-2.5-flash-image", contents: input, }); } catch (e: unknown) { diff --git a/src/services/ai/tools.ts b/src/services/ai/tools.ts index f4de906..b378dbc 100644 --- a/src/services/ai/tools.ts +++ b/src/services/ai/tools.ts @@ -131,8 +131,13 @@ const tools: FunctionDeclaration[] = [ type: "string", description: "a very detailed prompt to generate an image", }, + smart: { + type: "boolean", + description: + "use a smarter, more expensive model. only true if the user explicitly requests it, otherwise false", + }, }, - required: ["prompt"], + required: ["prompt", "smart"], }, }, ]; @@ -293,6 +298,16 @@ const toolFunctions: AIToolFunction[] = [ { name: "generateImage", function: (matrix, args) => { + if (args.smart === true) { + matrix.client.sendTextMessage( + matrix.roomId, + `!imgpro ${args.prompt}`, + ); + return { + message: "trying to generate using smart model...", + }; + } + matrix.client.sendTextMessage(matrix.roomId, `!img ${args.prompt}`); return {