diff --git a/src/execution.ts b/src/execution.ts index dada0a4..1f4b282 100644 --- a/src/execution.ts +++ b/src/execution.ts @@ -212,6 +212,7 @@ async function executeFromQueue(channel: string) { const message = channelQueue.at(0) as RequestMessage; let functionRanCounter = 0; let OpenAImessages: ChatCompletionMessageParam[] = []; + let modelUsernameMap: Map; // ignore if we can't even send anything to reply if (!canReplyToRequest(message)) return; @@ -237,7 +238,7 @@ async function executeFromQueue(channel: string) { return b.createdTimestamp - a.createdTimestamp; }); - [OpenAImessages] = toOpenAIMessages(messages.values()); + [OpenAImessages, modelUsernameMap] = toOpenAIMessages(messages.values()); let generatedMessage: ChatCompletionMessage | undefined = undefined; let answer: Awaited>; @@ -259,7 +260,7 @@ async function executeFromQueue(channel: string) { OpenAImessages.push(generatedMessage); // FIXME: don't use new instance of FunctionManager OpenAImessages.push( - new FunctionManager().handleFunction(generatedMessage.function_call) + new FunctionManager().handleFunction(generatedMessage.function_call, modelUsernameMap) ); } } while (generatedMessage.function_call); diff --git a/src/funcitonManager.ts b/src/funcitonManager.ts index 9bcb0ec..9af00d5 100644 --- a/src/funcitonManager.ts +++ b/src/funcitonManager.ts @@ -43,7 +43,10 @@ export abstract class OpenAIFunction { }; } - abstract execute(data: OpenAIFunctionRequestData): string; + abstract execute( + data: OpenAIFunctionRequestData, + modelUsernameMap: Map, + ): string; } /* @@ -64,7 +67,10 @@ export default class FunctionManager { return rvalue; } - public handleFunction(request: ChatCompletionFunctionCall): ChatCompletionMessageParam { + public handleFunction( + request: ChatCompletionFunctionCall, + modelUsernameMap: Map = new Map(), + ): ChatCompletionMessageParam { // eslint-disable-next-line @typescript-eslint/no-explicit-any let parsedArguments: any; @@ -91,7 +97,7 @@ export default class FunctionManager { role: "function", name: request.name, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument - content: functionToRun.execute(parsedArguments), + content: functionToRun.execute(parsedArguments, modelUsernameMap), }; } }