Add forgetting and personality change
This commit is contained in:
parent
6ab8dbd19e
commit
76e496bd38
3 changed files with 103 additions and 4 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "aslobot-matrix",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "",
|
||||
"license": "ISC",
|
||||
"author": "",
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import type { MatrixClient } from "matrix-js-sdk";
|
||||
import { config } from "./config.js";
|
||||
import { state } from "./store/store.js";
|
||||
import { type IUser, type TRole } from "./store/types.js";
|
||||
|
|
@ -98,6 +99,28 @@ const getUserFromMention = (mention: string | undefined): IUser | undefined => {
|
|||
return user;
|
||||
};
|
||||
|
||||
const changePersonality = (
|
||||
client: MatrixClient,
|
||||
personalityName: string,
|
||||
): boolean => {
|
||||
const personalityIndex = config.app.ai.personalities.findIndex(
|
||||
(personality) => personality.personalityName === personalityName,
|
||||
);
|
||||
if (personalityIndex === -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
state.personality = {
|
||||
index: personalityIndex,
|
||||
startTime: Date.now(),
|
||||
};
|
||||
client.setDisplayName(
|
||||
`AsloBot (${config.app.ai.personalities[state.personality.index]?.personalityName})`,
|
||||
);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export {
|
||||
fixUserData,
|
||||
getUserById,
|
||||
|
|
@ -105,4 +128,5 @@ export {
|
|||
getLevel,
|
||||
getUserName,
|
||||
getUserFromMention,
|
||||
changePersonality,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { config, packageConfig } from "../../config.js";
|
|||
import type { AIToolFunction } from "./types.js";
|
||||
import { save, state } from "../../store/store.js";
|
||||
import { EventType, RelationType } from "matrix-js-sdk";
|
||||
import { changePersonality } from "../../helpers.js";
|
||||
|
||||
const tools: FunctionDeclaration[] = [
|
||||
{
|
||||
|
|
@ -44,7 +45,7 @@ const tools: FunctionDeclaration[] = [
|
|||
},
|
||||
{
|
||||
name: "remember",
|
||||
description: "Gets information about this AI bot",
|
||||
description: "Remembers information",
|
||||
parametersJsonSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
|
|
@ -57,6 +58,21 @@ const tools: FunctionDeclaration[] = [
|
|||
required: ["knowledge"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "forget",
|
||||
description: "Forgets information",
|
||||
parametersJsonSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
knowledge: {
|
||||
type: "string",
|
||||
description:
|
||||
"knowledge to forget (has to be exactly word for word, every character)",
|
||||
},
|
||||
},
|
||||
required: ["knowledge"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "changeUsername",
|
||||
description: "Changes the username of this AI bot",
|
||||
|
|
@ -71,6 +87,20 @@ const tools: FunctionDeclaration[] = [
|
|||
required: ["username"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "changePersonality",
|
||||
description: "Changes the personality of this AI bot",
|
||||
parametersJsonSchema: {
|
||||
type: "object",
|
||||
properties: {
|
||||
personalityName: {
|
||||
type: "string",
|
||||
description: "name of the personality to switch to",
|
||||
},
|
||||
},
|
||||
required: ["personalityName"],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getFullUserData",
|
||||
description: "Gets the full user data about all users",
|
||||
|
|
@ -140,10 +170,40 @@ const toolFunctions: AIToolFunction[] = [
|
|||
if (!state.aiMemory) {
|
||||
state.aiMemory = [];
|
||||
}
|
||||
if (args.knowledge) {
|
||||
state.aiMemory.push(args.knowledge);
|
||||
if (!args.knowledge) {
|
||||
return {
|
||||
message: "failed",
|
||||
};
|
||||
}
|
||||
|
||||
state.aiMemory.push(args.knowledge);
|
||||
|
||||
return {
|
||||
message: "success",
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "forget",
|
||||
function: (_matrix, args) => {
|
||||
if (!state.aiMemory) {
|
||||
state.aiMemory = [];
|
||||
}
|
||||
if (!args.knowledge) {
|
||||
return {
|
||||
message: "failed",
|
||||
};
|
||||
}
|
||||
|
||||
const index = state.aiMemory.indexOf(args.knowledge);
|
||||
if (index === -1) {
|
||||
return {
|
||||
message: "cannot find that memory",
|
||||
};
|
||||
}
|
||||
|
||||
state.aiMemory.splice(index, 1);
|
||||
|
||||
return {
|
||||
message: "success",
|
||||
};
|
||||
|
|
@ -163,6 +223,21 @@ const toolFunctions: AIToolFunction[] = [
|
|||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "changePersonality",
|
||||
function: (matrix, args) => {
|
||||
const result = changePersonality(
|
||||
matrix.client,
|
||||
args.personalityName,
|
||||
);
|
||||
|
||||
return {
|
||||
message: result
|
||||
? "success"
|
||||
: "personality with that name does not exist",
|
||||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getFullUserData",
|
||||
function: (_matrix, _args) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue