mirror of
https://github.com/matrixgpt/matrix-chatgpt-bot.git
synced 2024-06-29 08:02:16 +00:00
Add CHATGPT_PROMPT_PREFIX setting
This commit is contained in:
parent
e39f3fdeee
commit
8ace02896e
|
@ -29,7 +29,8 @@ export const {
|
||||||
OPENAI_API_KEY,
|
OPENAI_API_KEY,
|
||||||
CHATGPT_CONTEXT,
|
CHATGPT_CONTEXT,
|
||||||
CHATGPT_TIMEOUT,
|
CHATGPT_TIMEOUT,
|
||||||
CHATGPT_MODEL
|
CHATGPT_MODEL,
|
||||||
|
CHATGPT_PROMPT_PREFIX,
|
||||||
} = 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" },
|
||||||
|
@ -56,5 +57,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_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_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" }
|
CHATGPT_MODEL: { schema: z.string().default("text-chat-davinci-002-20221122"), description: "The model for the ChatGPT-API to use" },
|
||||||
|
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"},
|
||||||
});
|
});
|
||||||
|
|
13
src/index.ts
13
src/index.ts
|
@ -8,10 +8,10 @@ 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_MODEL, KEYV_BOT_STORAGE, KEYV_BACKEND } 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_MODEL, KEYV_BOT_STORAGE, KEYV_BACKEND, CHATGPT_PROMPT_PREFIX } 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 } from './utils.js';
|
import { parseMatrixUsernamePretty, wrapPrompt } from './utils.js';
|
||||||
|
|
||||||
LogService.setLogger(new RichConsoleLogger());
|
LogService.setLogger(new RichConsoleLogger());
|
||||||
// LogService.setLevel(LogLevel.DEBUG); // Shows the Matrix sync loop details - not needed most of the time
|
// LogService.setLevel(LogLevel.DEBUG); // Shows the Matrix sync loop details - not needed most of the time
|
||||||
|
@ -51,13 +51,7 @@ async function main() {
|
||||||
modelOptions: {
|
modelOptions: {
|
||||||
model: CHATGPT_MODEL, // The model is set to text-chat-davinci-002-20221122 by default
|
model: CHATGPT_MODEL, // The model is set to text-chat-davinci-002-20221122 by default
|
||||||
},
|
},
|
||||||
// (Optional) Set custom instructions instead of "You are ChatGPT...".
|
promptPrefix: wrapPrompt(CHATGPT_PROMPT_PREFIX),
|
||||||
// promptPrefix: 'You are Bob, a cowboy in Western times...',
|
|
||||||
// (Optional) Set a custom name for the user
|
|
||||||
// userLabel: 'User',
|
|
||||||
// (Optional) Set a custom name for ChatGPT
|
|
||||||
// chatGptLabel: 'ChatGPT',
|
|
||||||
// (Optional) Set to true to enable `console.debug()` logging
|
|
||||||
debug: false,
|
debug: false,
|
||||||
};
|
};
|
||||||
const cacheOptions = { // Options for the Keyv cache, see https://www.npmjs.com/package/keyv
|
const cacheOptions = { // Options for the Keyv cache, see https://www.npmjs.com/package/keyv
|
||||||
|
@ -87,6 +81,7 @@ async function main() {
|
||||||
await commands.start();
|
await commands.start();
|
||||||
|
|
||||||
LogService.info("index", `Starting bot using ChatGPT model: ${CHATGPT_MODEL}`);
|
LogService.info("index", `Starting bot using ChatGPT model: ${CHATGPT_MODEL}`);
|
||||||
|
LogService.info("index", `Using promptPrefix: ${wrapPrompt(CHATGPT_PROMPT_PREFIX)}`)
|
||||||
await client.start()
|
await client.start()
|
||||||
LogService.info("index", "Bot started!");
|
LogService.info("index", "Bot started!");
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,3 +82,8 @@ export async function sendChatGPTMessage(chatgpt: ChatGPTClient, question: strin
|
||||||
await chatgpt.sendMessage(question, { conversationId: storedConversation.conversationId, parentMessageId: storedConversation.messageId }) :
|
await chatgpt.sendMessage(question, { conversationId: storedConversation.conversationId, parentMessageId: storedConversation.messageId }) :
|
||||||
await chatgpt.sendMessage(question);
|
await chatgpt.sendMessage(question);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function wrapPrompt(wrapped: string) {
|
||||||
|
const currentDateString = new Date().toLocaleDateString('en-us', { year: 'numeric', month: 'long', day: 'numeric' },);
|
||||||
|
return `<|im_sep|>${wrapped}\nCurrent date: ${currentDateString}<|im_sep|>\n\n`
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user