From af954b763285345d74744bc99da11dfa5ba248c6 Mon Sep 17 00:00:00 2001 From: Max Kammler Date: Fri, 3 Mar 2023 12:56:52 +0100 Subject: [PATCH] add new env for model, add warning about new version --- .env.example | 5 +++-- src/env.ts | 2 +- src/index.ts | 8 ++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 0a05411..2aba99e 100644 --- a/.env.example +++ b/.env.example @@ -4,8 +4,9 @@ OPENAI_API_KEY= # Set the ChatGPT conversation context to 'thread', 'room' or 'both'. CHATGPT_CONTEXT=thread -# (Optional) Explicitly set the ChatGPT model to be used by the API. -#CHATGPT_API_MODEL=gpt-3.5-turbo +# Set the ChatGPT model to be used by the API. 'gpt-3.5-turbo' is the official ChatGPT-model from OpenAI +# Note that the models are not free and will charge your OpenAI account depending on the usage of tokens +CHATGPT_API_MODEL=gpt-3.5-turbo # (Optional) Explicitly set the prefix sent to model at the beginning of a conversation #CHATGPT_PROMPT_PREFIX=Instructions:\nYou are ChatGPT, a large language model trained by OpenAI. # (Optional) Set to true if ChatGPT should ignore any messages which are not text diff --git a/src/env.ts b/src/env.ts index b4cfc89..464971b 100644 --- a/src/env.ts +++ b/src/env.ts @@ -64,7 +64,7 @@ export const { OPENAI_API_KEY: { schema: z.string().default(""), description: "Set to the API key from https://platform.openai.com/account/api-keys"}, CHATGPT_TIMEOUT: { schema: z.number().default(2 * 60 * 1000), description: "Set number of milliseconds to wait for ChatGPT responses" }, CHATGPT_CONTEXT: { schema: z.enum(["thread", "room", "both"]).default("thread"), description: "Set the ChatGPT conversation context to 'thread', 'room' or 'both'" }, - CHATGPT_API_MODEL: { schema: z.string().default("gpt-3.5-turbo"), description: "The model for the ChatGPT-API to use. Keep in mind that these models will charge your OpenAI account depending on their pricing." }, + CHATGPT_API_MODEL: { schema: z.string().default(""), description: "The model for the ChatGPT-API to use. Keep in mind that these models will charge your OpenAI account depending on their pricing." }, CHATGPT_PROMPT_PREFIX: { schema: z.string().default('Instructions:\nYou are ChatGPT, a large language model trained by OpenAI.'), description: "Instructions to feed to ChatGPT on startup"}, CHATGPT_IGNORE_MEDIA: { schema: z.boolean().default(false), description: "Wether or not the bot should react to non-text messages"}, }); diff --git a/src/index.ts b/src/index.ts index 97cd36f..c9d5375 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,13 @@ async function main() { if (!MATRIX_THREADS && CHATGPT_CONTEXT !== "room") throw Error("You must set CHATGPT_CONTEXT to 'room' if you set MATRIX_THREADS to false") const client: MatrixClient = new MatrixClient(MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, storage, cryptoStore); + if (!CHATGPT_API_MODEL) { + LogService.warn("index", "This bot now uses the official API from ChatGPT. In order to migrate add the CHATGPT_API_MODEL variable to your .env"); + LogService.warn("index", "The official ChatGPT-model which should be used is 'gpt-3.5-turbo'. See the .env.example for details") + LogService.warn("index", "Please note that the usage of the models charge your OpenAI account and are not free to use"); + return; + } + const clientOptions = { // (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions modelOptions: { model: CHATGPT_API_MODEL, // The model is set to gpt-3.5-turbo by default @@ -52,6 +59,7 @@ async function main() { promptPrefix: wrapPrompt(CHATGPT_PROMPT_PREFIX), debug: false, }; + const chatgpt = new ChatGPTClient(OPENAI_API_KEY, clientOptions, cacheOptions); // Automatically join rooms the bot is invited to