move config to a typescript file, add option for chatCompletionConfig

Now we can write code inside config,
which allows us to send current time to the OpenAI api
inside system message!

Example config updated accordingly
This commit is contained in:
Wroclaw 2023-03-24 15:44:22 +01:00
parent 960c340760
commit 4f4b708ba5
5 changed files with 39 additions and 14 deletions

34
src/config_example.ts Normal file
View file

@ -0,0 +1,34 @@
import { ChatCompletionRequestMessage as OpenAIMessage , CreateChatCompletionRequest as ChatCompletionRequestData } from "openai";
// Don't forget to rename the file to config.ts
const calendarConfig: Intl.DateTimeFormatOptions = {
weekday: "short",
year: "numeric",
month: "short",
day: "numeric",
hour: "2-digit",
minute: "2-digit",
hour12: false,
};
export default class config {
/** Tokens to authenticate with */
static readonly tokens = {
Discord: "Discord token here",
OpenAI: "OpenAI token here",
};
/** Messages to append at the start of every chat when sending to API */
static systemPrompt(): OpenAIMessage[] {
return [
{ role: "system", content: `You are GPTcord, an AI built on top of ChatGPT (a large language model trained by OpenAI) for Discord. Answer as concisely as possible. Current time (${Intl.DateTimeFormat().resolvedOptions().timeZone}): ${new Date().toLocaleString("en-US", calendarConfig)}` }
];
}
/** OpenAI model config */
static readonly chatCompletionConfig: Omit<ChatCompletionRequestData, "messages"> = {
model: "gpt-3.5-turbo",
max_tokens: 384,
};
}