add CHATGPT_MODEL environment variable

This commit is contained in:
Max Kammler 2023-02-03 11:35:49 +01:00
parent 660c225ee7
commit dcf038df1f
4 changed files with 13 additions and 5 deletions

View File

@ -6,6 +6,8 @@ OPENAI_PRO=false
# 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_MODEL=text-chat-davinci-002-20221122
# Matrix Static Settings (required, see notes)
# Defaults to "https://matrix.org"

View File

@ -36,6 +36,7 @@ Per default, whoever knows the name of your bot can add it to their rooms and st
### OpenAI / ChatGPT
- You need to have an account at [openai.com. ](https://openai.com/). Create a [API Key](https://platform.openai.com/account/api-keys). Then, set `OPENAI_API_KEY` in your `.env` file
- You might want to change to chat-model by setting the `CHATGPT_MODEL` in your `.env` file. The model currently defaults to `text-chat-davinci-002-20221122`. Check the [node-chatgpt-api](https://github.com/waylaidwanderer/node-chatgpt-api) repository for keeping track of the models.
## Setup

View File

@ -26,7 +26,8 @@ export const {
OPENAI_API_KEY,
OPENAI_PRO,
CHATGPT_CONTEXT,
CHATGPT_TIMEOUT
CHATGPT_TIMEOUT,
CHATGPT_MODEL
} = parseEnv(process.env, {
DATA_PATH: { schema: z.string().default("./storage"), description: "Set to /storage/ if using docker, ./storage if running without" },
/** Matrix Bot Settings */
@ -50,5 +51,6 @@ export const {
OPENAI_API_KEY: { schema: z.string().default(""), description: "Set to the API key from https://platform.openai.com/account/api-keys"},
OPENAI_PRO: { schema: z.boolean().default(false), description: "Set to true if you have a paid ChatGPT subscription." },
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_CONTEXT: { schema: z.enum(["thread", "room", "both"]).default("thread"), description: "Set the ChatGPT conversation context to 'thread', 'room' or 'both'" },
CHATGPT_MODEL: { schema: z.string().default("text-chat-davinci-002-20221122"), description: "The model for the ChatGPT-API to use" }
});

View File

@ -7,7 +7,7 @@ import {
} from "matrix-bot-sdk";
import * as path from "path";
import { DATA_PATH, OPENAI_API_KEY, OPENAI_PRO, MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, MATRIX_AUTOJOIN, MATRIX_BOT_PASSWORD, MATRIX_BOT_USERNAME, MATRIX_ENCRYPTION, MATRIX_THREADS, CHATGPT_CONTEXT } from './env.js'
import { DATA_PATH, OPENAI_API_KEY, OPENAI_PRO, MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, MATRIX_AUTOJOIN, MATRIX_BOT_PASSWORD, MATRIX_BOT_USERNAME, MATRIX_ENCRYPTION, MATRIX_THREADS, CHATGPT_CONTEXT, CHATGPT_MODEL } from './env.js'
import { parseMatrixUsernamePretty } from './utils.js';
import CommandHandler from "./handlers.js"
import { ChatGPTAPI } from 'chatgpt'
@ -43,7 +43,10 @@ async function main() {
// use puppeteer to bypass cloudflare (headful because of captchas)
const chatGPT: ChatGPTAPI = new ChatGPTAPI({
apiKey: OPENAI_API_KEY
apiKey: OPENAI_API_KEY,
completionParams: {
model: CHATGPT_MODEL
}
})
// // call `api.refreshSession()` every hour to refresh the session
@ -83,7 +86,7 @@ async function main() {
const commands = new CommandHandler(client, chatGPT);
await commands.start();
LogService.info("index", "Starting bot...");
LogService.info("index", `Starting bot using ChatGPT model ${CHATGPT_MODEL}`);
await client.start()
LogService.info("index", "Bot started!");
}