functionManager: Forward username mapping here
This commit is contained in:
parent
52f16c9d0a
commit
6e0a5e72ea
2 changed files with 12 additions and 5 deletions
|
@ -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<string, string>;
|
||||
|
||||
// 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<ReturnType<typeof openai.chat.completions.create>>;
|
||||
|
||||
|
@ -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);
|
||||
|
|
|
@ -43,7 +43,10 @@ export abstract class OpenAIFunction<T extends nameTypeMap = nameTypeMap> {
|
|||
};
|
||||
}
|
||||
|
||||
abstract execute(data: OpenAIFunctionRequestData<T>): string;
|
||||
abstract execute(
|
||||
data: OpenAIFunctionRequestData<T>,
|
||||
modelUsernameMap: Map<string, string>,
|
||||
): string;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -64,7 +67,10 @@ export default class FunctionManager {
|
|||
return rvalue;
|
||||
}
|
||||
|
||||
public handleFunction(request: ChatCompletionFunctionCall): ChatCompletionMessageParam {
|
||||
public handleFunction(
|
||||
request: ChatCompletionFunctionCall,
|
||||
modelUsernameMap: Map<string, string> = 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),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue