Fixes; Logging
This commit is contained in:
parent
76e496bd38
commit
1e94df499c
8 changed files with 79 additions and 33 deletions
|
|
@ -10,6 +10,7 @@ import { FunctionCallingConfigMode } from "@google/genai";
|
|||
import { toolFunctions, tools } from "./tools.js";
|
||||
import type { FunctionResponse } from "@google/genai";
|
||||
import type { Content } from "@google/genai";
|
||||
import { log } from "../../helpers.js";
|
||||
|
||||
const googleAI = new GoogleGenAI({
|
||||
apiKey: config.app.ai.api.key,
|
||||
|
|
@ -22,6 +23,16 @@ const getTextGemini = async (
|
|||
oldInput?: string,
|
||||
inputImage?: Buffer<ArrayBuffer>,
|
||||
): Promise<AIResponseText> => {
|
||||
log(`AI Text Request: ${input}`);
|
||||
|
||||
const oldInputContent: Content = {
|
||||
role: "user",
|
||||
parts: [
|
||||
{
|
||||
text: oldInput ?? "",
|
||||
},
|
||||
],
|
||||
};
|
||||
const inputContent: Content = inputImage
|
||||
? {
|
||||
role: "user",
|
||||
|
|
@ -45,14 +56,6 @@ const getTextGemini = async (
|
|||
},
|
||||
],
|
||||
};
|
||||
const oldInputContent: Content = {
|
||||
role: "user",
|
||||
parts: [
|
||||
{
|
||||
text: oldInput ?? "",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const contents: Content[] = oldInput
|
||||
? [oldInputContent, inputContent]
|
||||
|
|
@ -91,12 +94,14 @@ const getTextGemini = async (
|
|||
(func) => func.name === functionCall.name,
|
||||
)?.function;
|
||||
if (!func) {
|
||||
log(`Failed to tool: ${functionCall.name}`);
|
||||
return {
|
||||
text: text,
|
||||
tokens: token,
|
||||
};
|
||||
}
|
||||
|
||||
log(`Calling tool: ${functionCall.name}...`);
|
||||
const output = func(matrixData, functionCall.args);
|
||||
const functionResponse: FunctionResponse = {
|
||||
id: functionCall.id ?? "",
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ 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";
|
||||
import { readFileSync } from "fs";
|
||||
|
||||
const tools: FunctionDeclaration[] = [
|
||||
{
|
||||
|
|
@ -110,6 +111,16 @@ const tools: FunctionDeclaration[] = [
|
|||
required: [],
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getBotLog",
|
||||
description:
|
||||
"Gets the recent log about the activity of this bot from a log file",
|
||||
parametersJsonSchema: {
|
||||
type: "object",
|
||||
properties: {},
|
||||
required: [],
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const toolFunctions: AIToolFunction[] = [
|
||||
|
|
@ -202,7 +213,12 @@ const toolFunctions: AIToolFunction[] = [
|
|||
};
|
||||
}
|
||||
|
||||
state.aiMemory.splice(index, 1);
|
||||
state.aiMemory = state.aiMemory.filter(
|
||||
(memory) =>
|
||||
memory !== args.knowledge &&
|
||||
memory !== null &&
|
||||
memory !== undefined,
|
||||
);
|
||||
|
||||
return {
|
||||
message: "success",
|
||||
|
|
@ -246,6 +262,20 @@ const toolFunctions: AIToolFunction[] = [
|
|||
};
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getBotLog",
|
||||
function: (_matrix, _args) => {
|
||||
const delimeter = "\n";
|
||||
const logFile = readFileSync(config.logPath);
|
||||
|
||||
let lines = logFile.toString().trim();
|
||||
lines = lines.split(delimeter).slice(-20).join(delimeter);
|
||||
|
||||
return {
|
||||
log: lines,
|
||||
};
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export { tools, toolFunctions };
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue