Rework AI
This commit is contained in:
parent
e46c4427cc
commit
aebee54562
10 changed files with 79 additions and 20 deletions
|
|
@ -3,9 +3,10 @@ import type { ICallbackStore } from "../types.js";
|
|||
import { config } from "../../config.js";
|
||||
import { getTextGemini, getImageGemini } from "../../services/ai/ai.js";
|
||||
import { alts } from "./alts.js";
|
||||
import type { IAdminInstructions, IAIAlt } from "./types.js";
|
||||
import type { IAIInstructions } from "./types.js";
|
||||
import { getUserById, getUserName } from "../../helpers.js";
|
||||
import { prices } from "./prices.js";
|
||||
import { state } from "../../store/store.js";
|
||||
|
||||
let client: MatrixClient;
|
||||
|
||||
|
|
@ -34,21 +35,41 @@ const onAI = async (text: string, roomId: string, sender: string) => {
|
|||
return;
|
||||
}
|
||||
|
||||
let personality = config.app.ai.personalities[state.personality.index];
|
||||
if (
|
||||
Date.now() >
|
||||
state.personality.startTime + (personality?.timeout ?? 0)
|
||||
) {
|
||||
const randomInt = Math.floor(
|
||||
Math.random() * (config.app.ai.personalities.length + 1),
|
||||
);
|
||||
state.personality = {
|
||||
index: randomInt,
|
||||
startTime: Date.now(),
|
||||
};
|
||||
}
|
||||
|
||||
personality = config.app.ai.personalities[state.personality.index];
|
||||
|
||||
let textMod = text.replace("!ai", "").trim().toLowerCase();
|
||||
let instructions = {
|
||||
prefferedLanguages: ["english", "slovak"],
|
||||
adminText: config.app.ai.prompt,
|
||||
alts: alts.map((alt) => ({
|
||||
keys: alt.keys,
|
||||
users: alts.map((alt) => ({
|
||||
names: alt.keys,
|
||||
alt: alt.alt,
|
||||
information: user.information,
|
||||
backstory: alt.id
|
||||
? getUserById(`${alt.id}:${config.server}`).information
|
||||
: undefined,
|
||||
})),
|
||||
} as IAdminInstructions;
|
||||
aiPersonality: personality?.personality ?? "",
|
||||
aiLikes: personality?.likes ?? "",
|
||||
aiDislikes: personality?.dislikes ?? "",
|
||||
} as IAIInstructions;
|
||||
|
||||
const username = getUserName(user);
|
||||
textMod = `Admin Instructions:\n${JSON.stringify(instructions)}\nPrompt by ${username}:\n${textMod}`;
|
||||
textMod = `${username}:\n${textMod}`;
|
||||
|
||||
const responseAI = await getTextGemini(textMod);
|
||||
const responseAI = await getTextGemini(instructions, textMod);
|
||||
|
||||
user.aiCost += responseAI.tokens * prices.text;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue