mirror of
https://github.com/matrixgpt/matrix-chatgpt-bot.git
synced 2024-09-30 13:05:50 +00:00
Feature/reverse proxy (#161)
* add CHATGPT_REVERSE_PROXY --------- Co-authored-by: Max Kammler <max.kammler@icloud.com>
This commit is contained in:
parent
9bed44abfd
commit
b11d566ecb
@ -11,6 +11,8 @@ CHATGPT_API_MODEL=gpt-3.5-turbo
|
|||||||
#CHATGPT_PROMPT_PREFIX=Instructions:\nYou are ChatGPT, a large language model trained by OpenAI.
|
#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
|
# (Optional) Set to true if ChatGPT should ignore any messages which are not text
|
||||||
#CHATGPT_IGNORE_MEDIA=false
|
#CHATGPT_IGNORE_MEDIA=false
|
||||||
|
# (Optional) You can change the api url to use another (OpenAI-compatible) API endpoint
|
||||||
|
#CHATGPT_REVERSE_PROXY=https://api.openai.com/v1/chat/completions
|
||||||
|
|
||||||
# Set data store settings
|
# Set data store settings
|
||||||
KEYV_BACKEND=file
|
KEYV_BACKEND=file
|
||||||
|
@ -44,6 +44,7 @@ Adjust all required settings in the `.env` file before running. Optional setting
|
|||||||
- You need to have an account at [openai.com](https://openai.com/). Please note that the usage of the ChatGPT-API is not free.
|
- 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
|
- Create a [API Key](https://platform.openai.com/account/api-keys). Then, set `OPENAI_API_KEY` in your `.env` file
|
||||||
- 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.
|
- 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.
|
||||||
|
- You can change the API-URL to use another base than the official OpenAI-endpoint. To do so, change the `CHATGPT_REVERSE_PROXY` in the `.env` file.
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ export const {
|
|||||||
CHATGPT_API_MODEL,
|
CHATGPT_API_MODEL,
|
||||||
CHATGPT_PROMPT_PREFIX,
|
CHATGPT_PROMPT_PREFIX,
|
||||||
CHATGPT_IGNORE_MEDIA,
|
CHATGPT_IGNORE_MEDIA,
|
||||||
|
CHATGPT_REVERSE_PROXY,
|
||||||
} = parseEnv(process.env, {
|
} = parseEnv(process.env, {
|
||||||
DATA_PATH: { schema: z.string().default("./storage"), description: "Set to /storage/ if using docker, ./storage if running without" },
|
DATA_PATH: { schema: z.string().default("./storage"), description: "Set to /storage/ if using docker, ./storage if running without" },
|
||||||
KEYV_BACKEND: { schema: z.enum(["file", "other"]).default("file"),description: "Set the Keyv backend to 'file' or 'other' if other set KEYV_URL" },
|
KEYV_BACKEND: { schema: z.enum(["file", "other"]).default("file"),description: "Set the Keyv backend to 'file' or 'other' if other set KEYV_URL" },
|
||||||
@ -67,4 +68,5 @@ export const {
|
|||||||
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_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_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"},
|
CHATGPT_IGNORE_MEDIA: { schema: z.boolean().default(false), description: "Wether or not the bot should react to non-text messages"},
|
||||||
|
CHATGPT_REVERSE_PROXY: { schema: z.string().default(""), description: "Change the api url to use another (OpenAI-compatible) API endpoint" }
|
||||||
});
|
});
|
||||||
|
10
src/index.ts
10
src/index.ts
@ -7,7 +7,12 @@ import {
|
|||||||
} from "matrix-bot-sdk";
|
} from "matrix-bot-sdk";
|
||||||
|
|
||||||
import * as path from "path";
|
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_API_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,
|
||||||
|
CHATGPT_REVERSE_PROXY
|
||||||
|
} from './env.js'
|
||||||
import CommandHandler from "./handlers.js"
|
import CommandHandler from "./handlers.js"
|
||||||
import { KeyvStorageProvider } from './storage.js'
|
import { KeyvStorageProvider } from './storage.js'
|
||||||
import { parseMatrixUsernamePretty, wrapPrompt } from './utils.js';
|
import { parseMatrixUsernamePretty, wrapPrompt } from './utils.js';
|
||||||
@ -58,6 +63,9 @@ async function main() {
|
|||||||
},
|
},
|
||||||
promptPrefix: wrapPrompt(CHATGPT_PROMPT_PREFIX),
|
promptPrefix: wrapPrompt(CHATGPT_PROMPT_PREFIX),
|
||||||
debug: false,
|
debug: false,
|
||||||
|
options: {
|
||||||
|
reverseProxyUrl: CHATGPT_REVERSE_PROXY
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const chatgpt = new ChatGPTClient(OPENAI_API_KEY, clientOptions, cacheOptions);
|
const chatgpt = new ChatGPTClient(OPENAI_API_KEY, clientOptions, cacheOptions);
|
||||||
|
Loading…
Reference in New Issue
Block a user