Skip to content

Commit

Permalink
Rename BOT_AI_NAME env key to BOT_NAME
Browse files Browse the repository at this point in the history
  • Loading branch information
memochou1993 committed Jan 1, 2023
1 parent 63b2f81 commit fd65847
Show file tree
Hide file tree
Showing 15 changed files with 31 additions and 31 deletions.
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ APP_PORT=3000
APP_LANG=
APP_WEBHOOK_PATH=

SETTING_AI_NAME=
SETTING_AI_ACTIVATED=
BOT_NAME=

VERCEL_GIT_REPO_SLUG=gpt-ai-assistant
VERCEL_ACCESS_TOKEN=
Expand Down
4 changes: 2 additions & 2 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const handleContext = async (context) => (
);

const handleEvents = async (events = []) => (
Promise.all(
(Promise.all(
(await Promise.all(
(await Promise.all(
events
Expand All @@ -59,7 +59,7 @@ const handleEvents = async (events = []) => (
))
.filter((context) => context.messages.length > 0)
.map((context) => replyMessage(context)),
)
))
);

export default handleEvents;
2 changes: 1 addition & 1 deletion app/commands/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const execCommandCommand = async (context) => {
new MessageAction(COMMAND_SUMMARIZE),
new MessageAction(COMMAND_DEPLOY),
];
context.pushTemplate(config.BOT_AI_NAME, buttons, actions);
context.pushTemplate(config.BOT_NAME, buttons, actions);
} catch (err) {
context.pushError(err);
}
Expand Down
2 changes: 1 addition & 1 deletion app/commands/continue.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const execContinueCommand = async (context) => {
if (!text) return context;
prompt.patch(text);
if (!lastSentence.isEnquiring) {
updateHistory(context.contextId, (history) => history.write(config.BOT_AI_NAME, text));
updateHistory(context.contextId, (history) => history.write(config.BOT_NAME, text));
}
setPrompt(context.userId, prompt);
const defaultActions = lastSentence.isEnquiring ? enquiryActions : [];
Expand Down
5 changes: 2 additions & 3 deletions app/commands/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ const isDrawCommand = (context) => context.hasCommand(COMMAND_DRAW);
* @returns {Promise<Context>}
*/
const execDrawCommand = async (context) => {
const content = context.trimmedText.replace(COMMAND_DRAW.text, '');
const prompt = getPrompt(context.userId);
prompt.write(PARTICIPANT_HUMAN, `${context.trimmedText}?`).write(PARTICIPANT_AI);
try {
const { url } = await generateImage({ prompt: content, size: config.OPENAI_IMAGE_GENERATION_SIZE });
const { url } = await generateImage({ prompt: context.trimmedText, size: config.OPENAI_IMAGE_GENERATION_SIZE });
prompt.patch(MOCK_TEXT_OK);
setPrompt(context.userId, prompt);
updateHistory(context.contextId, (history) => history.write(config.BOT_AI_NAME, MOCK_TEXT_OK));
updateHistory(context.contextId, (history) => history.write(config.BOT_NAME, MOCK_TEXT_OK));
context.pushImage(url);
} catch (err) {
context.pushError(err);
Expand Down
6 changes: 3 additions & 3 deletions app/commands/summon.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { execTalkCommand } from './talk.js';
*/
const isSummonCommand = (context) => {
if (!context.event.isText) return false;
const name = config.BOT_AI_NAME;
const input = context.event.text.replaceAll(' ', ' ').trim().toLowerCase();
return input.startsWith(name.toLowerCase());
const name = config.BOT_NAME;
const content = context.event.text.replaceAll(' ', ' ').trim().toLowerCase();
return content.startsWith(name.toLowerCase());
};

/**
Expand Down
4 changes: 2 additions & 2 deletions app/commands/talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ const isTalkCommand = (context) => context.hasCommand(COMMAND_TALK) || isActivat
*/
const execTalkCommand = async (context) => {
const prompt = getPrompt(context.userId);
prompt.write(PARTICIPANT_HUMAN, `${context.trimmedText}?`).write(PARTICIPANT_AI, '');
prompt.write(PARTICIPANT_HUMAN, `${context.trimmedText}?`).write(PARTICIPANT_AI);
try {
const { text, isFinishReasonStop } = await generateCompletion({ prompt: prompt.toString() });
prompt.patch(text);
setPrompt(context.userId, prompt);
updateHistory(context.contextId, (history) => history.write(config.BOT_AI_NAME, text));
updateHistory(context.contextId, (history) => history.write(config.BOT_NAME, text));
const actions = isFinishReasonStop ? [] : [new MessageAction(COMMAND_CONTINUE)];
context.pushText(text, actions);
} catch (err) {
Expand Down
20 changes: 11 additions & 9 deletions app/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class Context {
*/
get trimmedText() {
if (!this.event.isText) return this.event.message.type;
return this.event.text.replace(config.BOT_AI_NAME, ' ').replaceAll(' ', ' ').trim();
const text = this.event.text.replaceAll(' ', ' ').trim();
if (text.startsWith(config.BOT_NAME)) return text.replace(config.BOT_NAME, '');
return text;
}

/**
Expand All @@ -67,9 +69,9 @@ class Context {
aliases,
}) {
if (!this.event.isText) return false;
const input = this.trimmedText.toLowerCase();
if (input === text.toLowerCase()) return true;
if (aliases.some((alias) => input === alias.toLowerCase())) return true;
const content = this.trimmedText.toLowerCase();
if (content === text.toLowerCase()) return true;
if (aliases.some((alias) => content === alias.toLowerCase())) return true;
return false;
}

Expand All @@ -84,11 +86,11 @@ class Context {
aliases,
}) {
if (!this.event.isText) return false;
const input = this.trimmedText.toLowerCase();
if (aliases.some((alias) => input.startsWith(alias.toLowerCase()))) return true;
if (aliases.some((alias) => input.endsWith(alias.toLowerCase()))) return true;
if (input.startsWith(text.toLowerCase())) return true;
if (input.endsWith(text.toLowerCase())) return true;
const content = this.trimmedText.toLowerCase();
if (aliases.some((alias) => content.startsWith(alias.toLowerCase()))) return true;
if (aliases.some((alias) => content.endsWith(alias.toLowerCase()))) return true;
if (content.startsWith(text.toLowerCase())) return true;
if (content.endsWith(text.toLowerCase())) return true;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const config = Object.freeze({
APP_PORT: env.APP_PORT || null,
APP_LANG: env.APP_LANG || 'zh',
APP_WEBHOOK_PATH: env.APP_WEBHOOK_PATH || '/webhook',
BOT_AI_NAME: env.BOT_AI_NAME || 'AI',
BOT_NAME: env.BOT_NAME || 'AI',
SETTING_AI_ACTIVATED: env.SETTING_AI_ACTIVATED || null,
VERCEL_GIT_REPO_SLUG: env.VERCEL_GIT_REPO_SLUG || null,
VERCEL_ACCESS_TOKEN: env.VERCEL_ACCESS_TOKEN || null,
Expand Down
2 changes: 1 addition & 1 deletion locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const en = {
__COMMAND_SUMMARIZE_LABEL: 'Summarize',
__COMMAND_SUMMARIZE_TEXT: 'Summarize',
__COMMAND_SUMMON_DEMO_LABEL: 'Summon',
__COMMAND_SUMMON_DEMO_TEXT: `${config.BOT_AI_NAME} What's up?`,
__COMMAND_SUMMON_DEMO_TEXT: `${config.BOT_NAME} What's up?`,
__COMMAND_VERSION_LABEL: 'Version',
__COMMAND_VERSION_TEXT: 'Version',
__TEMPLATE_TITLE_COMMAND: 'Commands',
Expand Down
2 changes: 1 addition & 1 deletion locales/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const ja = {
__COMMAND_SUMMARIZE_LABEL: '要約して',
__COMMAND_SUMMARIZE_TEXT: '要約して',
__COMMAND_SUMMON_DEMO_LABEL: 'サモン',
__COMMAND_SUMMON_DEMO_TEXT: `${config.BOT_AI_NAME} 元気?`,
__COMMAND_SUMMON_DEMO_TEXT: `${config.BOT_NAME} 元気?`,
__COMMAND_VERSION_LABEL: 'バージョン',
__COMMAND_VERSION_TEXT: 'バージョン',
__TEMPLATE_TITLE_COMMAND: 'コマンド',
Expand Down
2 changes: 1 addition & 1 deletion locales/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const zh = {
__COMMAND_SUMMARIZE_LABEL: '總結',
__COMMAND_SUMMARIZE_TEXT: '總結',
__COMMAND_SUMMON_DEMO_LABEL: '呼叫',
__COMMAND_SUMMON_DEMO_TEXT: `${config.BOT_AI_NAME} 你好嗎?`,
__COMMAND_SUMMON_DEMO_TEXT: `${config.BOT_NAME} 你好嗎?`,
__COMMAND_VERSION_LABEL: '查看版本',
__COMMAND_VERSION_TEXT: '版本',
__TEMPLATE_TITLE_COMMAND: '指令',
Expand Down
2 changes: 1 addition & 1 deletion releases/v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

### 呼叫

AI 助理預設的名稱是「AI」,當關閉自動回覆後,可以使用「AI 你好」的方式呼叫。可以透過修改 `BOT_AI_NAME` 環境變數來自訂名稱。
AI 助理預設的名稱是「AI」,當關閉自動回覆後,可以使用「AI 你好」的方式呼叫。可以透過修改 `BOT_NAME` 環境變數來自訂名稱。

### 圖像生成

Expand Down
4 changes: 2 additions & 2 deletions tests/command.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ test('COMMAND_COMMAND', async () => {
} catch (err) {
console.error(err);
}
expect(getPrompt(MOCK_USER_01).sentences.length).toEqual(1 );
expect(getPrompt(MOCK_USER_01).sentences.length).toEqual(1);
const replies = results.map(({ messages }) => messages.map(({ altText }) => altText));
expect(replies).toEqual(
[
[config.BOT_AI_NAME],
[config.BOT_NAME],
],
);
}, TIMEOUT);
2 changes: 1 addition & 1 deletion tests/summon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ afterEach(() => {

test('COMMAND_SUMMON', async () => {
const events = [
...createEvents([`${config.BOT_AI_NAME} 你好`]),
...createEvents([`${config.BOT_NAME} 你好`]),
];
let results;
try {
Expand Down

0 comments on commit fd65847

Please sign in to comment.