Compare commits

...

2 commits

Author SHA1 Message Date
74359067d0 functionManager: don't return empty function array for openai
openai doesn't accept empty function parameter,
it was discovered after I removed the testing buildin function
2023-12-13 21:08:09 +01:00
24e85f535a "Gracefully" exit when receiving sigint 2023-12-13 20:56:23 +01:00
4 changed files with 21 additions and 2 deletions

View file

@ -17,3 +17,4 @@ RUN npx tsc
# Run the app
CMD ["node", "dist/src/index.js"]
STOPSIGNAL SIGINT

View file

@ -246,7 +246,7 @@ async function executeFromQueue(channel: string) {
...config.chatCompletionParams,
messages: OpenAImessages,
// FIXME: don't use new instance of FunctionManager
functions: new FunctionManager().getFunctions(),
functions: new FunctionManager().getFunctionsForOpenAi(),
});
logUsedTokens(answer, message, ++functionRanCounter);

View file

@ -62,6 +62,11 @@ export default class FunctionManager {
return rvalue;
}
public getFunctionsForOpenAi(): ChatCompletionFunctions[] | undefined {
const rvalue = this.getFunctions();
return rvalue.length > 0 ? rvalue : undefined;
}
public handleFunction(request: ChatCompletionFunctionCall): ChatCompletionMessageParam {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let parsedArguments: any;

View file

@ -63,4 +63,17 @@ discord.on("messageCreate", message => {
return queueRequest(message);
});
if (require.main === module) void discord.login(config.tokens.Discord);
if (require.main === module) {
void discord.login(config.tokens.Discord);
process.on("SIGINT", () => {
console.log("got SIGINT, exiting");
//FIXME: finish executing requests then exit
discord.destroy()
.then(() => process.exit())
.catch((e) => {
console.error("Failed to gracefully exit");
console.error(e);
process.exit();
});
});
}