rename env, bump chatgpt client version

This commit is contained in:
Max Kammler 2023-03-03 11:59:52 +01:00
parent a6eed7954a
commit 2d7d482fca
6 changed files with 21 additions and 18 deletions

View File

@ -5,7 +5,7 @@ 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_MODEL=gpt-3.5-turbo
#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

View File

@ -7,6 +7,9 @@ Talk to ChatGPT via any Matrix client!
A Matrix bot that uses [waylaidwanderer/node-chatgpt-api](https://github.com/waylaidwanderer/node-chatgpt-api) to access the unofficial ChatGPT API.
## Warning for users upgrading from version 2.x
OpenAI released the [official API for ChatGPT](https://openai.com/blog/introducing-chatgpt-and-whisper-apis). Thus, we no longer have to use any older models or any models which kept on being turned off by OpenAI. This means the bot is now way more stable and way faster. However, please note: The usage of the API is **no longer free**. If you use this bot, your OpenAI account **will be charged**! You might want to limit your budget in your account using the OpenAI website.
# Usage
1. Create a room
2. Add the bot
@ -39,7 +42,7 @@ Adjust all required settings in the `.env` file before running. Optional setting
### OpenAI / ChatGPT
- You need to have an account at [openai.com](https://openai.com/). Please note that the usage of the ChatGPT-API is not free.
- 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. ChatGPT is the `gpt-3.5-turbo`-model which is the default. Please note that depending on the model, your OpenAI account will be charged.
- You can change the chat-model by setting the `CHATGPT_API_MODEL` in your `.env` file. ChatGPT is the `gpt-3.5-turbo`-model which is the default. Please note that depending on the model your OpenAI account will be charged.
## Setup

View File

@ -19,7 +19,7 @@
"@keyv/postgres": "^1.4.1",
"@keyv/redis": "^2.5.4",
"@keyv/sqlite": "^3.6.4",
"@waylaidwanderer/chatgpt-api": "^1.22.0",
"@waylaidwanderer/chatgpt-api": "^1.23.0",
"dotenv": "^16.0.3",
"hash.js": "^1.1.7",
"keyv": "^4.5.2",

View File

@ -32,7 +32,7 @@ export const {
OPENAI_API_KEY,
CHATGPT_CONTEXT,
CHATGPT_TIMEOUT,
CHATGPT_MODEL,
CHATGPT_API_MODEL,
CHATGPT_PROMPT_PREFIX,
CHATGPT_IGNORE_MEDIA,
} = parseEnv(process.env, {
@ -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_MODEL: { schema: z.string().default("gpt-3.5-turbo"), description: "The model for the ChatGPT-API to use" },
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_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"},
});

View File

@ -7,7 +7,7 @@ import {
} from "matrix-bot-sdk";
import * as path from "path";
import { DATA_PATH, KEYV_URL, OPENAI_API_KEY, MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, MATRIX_AUTOJOIN, MATRIX_BOT_PASSWORD, MATRIX_BOT_USERNAME, MATRIX_ENCRYPTION, MATRIX_THREADS, CHATGPT_CONTEXT, CHATGPT_MODEL, KEYV_BOT_STORAGE, KEYV_BACKEND, CHATGPT_PROMPT_PREFIX, MATRIX_WELCOME } from './env.js'
import { DATA_PATH, KEYV_URL, OPENAI_API_KEY, MATRIX_HOMESERVER_URL, MATRIX_ACCESS_TOKEN, MATRIX_AUTOJOIN, MATRIX_BOT_PASSWORD, MATRIX_BOT_USERNAME, MATRIX_ENCRYPTION, MATRIX_THREADS, CHATGPT_CONTEXT, CHATGPT_API_MODEL, KEYV_BOT_STORAGE, KEYV_BACKEND, CHATGPT_PROMPT_PREFIX, MATRIX_WELCOME } from './env.js'
import CommandHandler from "./handlers.js"
import { KeyvStorageProvider } from './storage.js'
import { parseMatrixUsernamePretty, wrapPrompt } from './utils.js';
@ -47,7 +47,7 @@ async function main() {
const clientOptions = { // (Optional) Parameters as described in https://platform.openai.com/docs/api-reference/completions
modelOptions: {
model: CHATGPT_MODEL, // The model is set to gpt-3.5-turbo by default
model: CHATGPT_API_MODEL, // The model is set to gpt-3.5-turbo by default
},
promptPrefix: wrapPrompt(CHATGPT_PROMPT_PREFIX),
debug: false,
@ -77,7 +77,7 @@ async function main() {
const commands = new CommandHandler(client, chatgpt);
await commands.start();
LogService.info("index", `Starting bot using ChatGPT model: ${CHATGPT_MODEL}`);
LogService.info("index", `Starting bot using ChatGPT model: ${CHATGPT_API_MODEL}`);
LogService.info("index", `Using promptPrefix: ${wrapPrompt(CHATGPT_PROMPT_PREFIX)}`)
await client.start()
LogService.info("index", "Bot started!");

View File

@ -737,6 +737,11 @@
"@aws-sdk/util-buffer-from" "3.208.0"
tslib "^2.3.1"
"@dqbd/tiktoken@^0.4.0":
version "0.4.0"
resolved "https://registry.yarnpkg.com/@dqbd/tiktoken/-/tiktoken-0.4.0.tgz#070e770ae3fa3fa8fccbea4f2e02ab87117f6c3a"
integrity sha512-iaHgmwKAOqowBFZKxelyszoeGLoNw62eOULcmyme1aA1Ymr3JgYl0V7jwpuUm7fksalycZajx3loFn9TRUaviw==
"@fastify/ajv-compiler@^3.3.1":
version "3.5.0"
resolved "https://registry.yarnpkg.com/@fastify/ajv-compiler/-/ajv-compiler-3.5.0.tgz#459bff00fefbf86c96ec30e62e933d2379e46670"
@ -937,11 +942,12 @@
"@types/node" "*"
"@types/webidl-conversions" "*"
"@waylaidwanderer/chatgpt-api@^1.22.0":
version "1.22.5"
resolved "https://registry.yarnpkg.com/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.22.5.tgz#8613c0cd84c1fc4784b49b90dde560ea44231701"
integrity sha512-mjuui0ZuBYqpAbpKtpbrP3iYpNBHL5Uj2Rq42jYXBXC5mVTH6GPIUxczrWLFucHYTxau0kupa9SOoeBOZ4d+JQ==
"@waylaidwanderer/chatgpt-api@^1.23.0":
version "1.23.2"
resolved "https://registry.yarnpkg.com/@waylaidwanderer/chatgpt-api/-/chatgpt-api-1.23.2.tgz#6cd8051d39fdb5a1d11aa8f2cb6a2cd6de31c49c"
integrity sha512-JBXwqASFBazp1W7qQKZ0tV88WQ4/xqCX6B4g+XJqMM1QbHSFJ9uEnTbZrUUFFCnOzsmHwDg/UMizl2ISB4dAsw==
dependencies:
"@dqbd/tiktoken" "^0.4.0"
"@fastify/cors" "^8.2.0"
"@waylaidwanderer/fastify-sse-v2" "^3.1.0"
"@waylaidwanderer/fetch-event-source" "^3.0.1"
@ -950,7 +956,6 @@
dotenv "^16.0.3"
fastify "^4.11.0"
fetch-undici "^3.0.1"
gpt-3-encoder "^1.1.4"
https-proxy-agent "^5.0.1"
inquirer "^9.1.4"
inquirer-autocomplete-prompt "^3.0.0"
@ -2048,11 +2053,6 @@ glob@^7.1.3, glob@^7.1.4:
once "^1.3.0"
path-is-absolute "^1.0.0"
gpt-3-encoder@^1.1.4:
version "1.1.4"
resolved "https://registry.yarnpkg.com/gpt-3-encoder/-/gpt-3-encoder-1.1.4.tgz#d6cdaacf5824857e133b6065247c757fc7e4fa72"
integrity sha512-fSQRePV+HUAhCn7+7HL7lNIXNm6eaFWFbNLOOGtmSJ0qJycyQvj60OvRlH7mee8xAMjBDNRdMXlMwjAbMTDjkg==
graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.2.6:
version "4.2.10"
resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.10.tgz#147d3a006da4ca3ce14728c7aefc287c367d7a6c"