Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

yoken - change chinese #283

Closed
wants to merge 17 commits into from
13 changes: 13 additions & 0 deletions app/commands/bot-draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,18 @@ export default new Command({
...t('__COMMAND_BOT_DRAW_ALIASES'),
'/draw',
'Draw',
'請畫',
'畫一',
'畫給我',
'可以畫',
'可以看',
'我要看',
'我想看',
'給我看',
'給我一張',
'我要一張',
'我可以看',
'請給我看',
'傳給我一張',
],
});
20 changes: 20 additions & 0 deletions app/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,26 @@ class Context {
return false;
}

get sensitiveWords() {
let sensitive_words = config.SENSITIVE_WORDS.split(',');

if (this.event.isText) {
let text = this.event.text.replaceAll(' ', ' ').trim();
for (let i = 0 ; i < sensitive_words.length ; i++){
if (text.includes(sensitive_words[i])){
text = text.replaceAll(sensitive_words[i], '(某個身體部位)').trim();
}
}

return addMark(text);
}
if (this.event.isAudio) {
const text = this.transcription.replace(config.BOT_NAME, '').trim();
return addMark(text);
}
return '?';
}

async initialize() {
try {
this.validate();
Expand Down
19 changes: 18 additions & 1 deletion app/handlers/talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,24 @@ const check = (context) => (
const exec = (context) => check(context) && (
async () => {
const prompt = getPrompt(context.userId);
prompt.write(ROLE_HUMAN, `${t('__COMPLETION_DEFAULT_AI_TONE')(config.BOT_TONE)}${context.trimmedText}`).write(ROLE_AI);
// prompt.write(ROLE_HUMAN, `${t('__COMPLETION_DEFAULT_AI_TONE')(config.BOT_TONE)}${context.trimmedText}'`).write(ROLE_AI);

let sensitive_words = config.SENSITIVE_WORDS.split(',');
let sensitive_bool = false;
for (let i = 0 ; i < sensitive_words.length ; i++){
if (context.ToString.includes(sensitive_words[i])){
sensitive_bool = true;
}
}

if (sensitive_bool){
prompt.write(ROLE_HUMAN, `t('__COMPLETION_DEFAULT_AI_TONE_SHY')${context.sensitiveWords}'`).write(ROLE_AI);
}
else{
prompt.write(ROLE_HUMAN, `${t('__COMPLETION_DEFAULT_AI_TONE')(config.BOT_TONE)}${context.sensitiveWords}'`).write(ROLE_AI);
}


try {
const { text, isFinishReasonStop } = await generateCompletion({ prompt });
prompt.patch(text);
Expand Down
7 changes: 7 additions & 0 deletions app/prompt/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const MAX_TOKENS = config.APP_MAX_PROMPT_TOKENS;
class Prompt {
messages = [];

// constructor() {
// this
// .write(ROLE_SYSTEM, config.APP_INIT_PROMPT || t('__COMPLETION_DEFAULT_SYSTEM_PROMPT'))
// .write(ROLE_HUMAN, `${t('__COMPLETION_DEFAULT_HUMAN_PROMPT')(config.HUMAN_NAME)}${config.HUMAN_INIT_PROMPT}`)
// .write(ROLE_AI, `${t('__COMPLETION_DEFAULT_AI_PROMPT')(config.BOT_NAME)}${config.BOT_INIT_PROMPT}`);
// }

constructor() {
this
.write(ROLE_SYSTEM, config.APP_INIT_PROMPT || t('__COMPLETION_DEFAULT_SYSTEM_PROMPT'))
Expand Down
1 change: 1 addition & 0 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const config = Object.freeze({
SERPAPI_API_KEY: env.SERPAPI_API_KEY || null,
SERPAPI_LOCATION: env.SERPAPI_LOCATION || 'Taiwan',
SERPAPI_LANG: env.SERPAPI_LANG || 'lang_zh-TW',
SENSITIVE_WORDS: env.SENSITIVE_WORDS || '',
});

export default config;
3 changes: 2 additions & 1 deletion locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ const en = {
__COMPLETION_DEFAULT_SYSTEM_PROMPT: '', // TODO
__COMPLETION_DEFAULT_HUMAN_PROMPT: (name) => (name ? `I am ${name}` : 'Hello'),
__COMPLETION_DEFAULT_AI_PROMPT: (name) => (name ? `I am ${name}` : 'Hello'),
__COMPLETION_DEFAULT_AI_TONE: (tone) => (tone ? `以${tone}的語氣回應我:` : ''), // TODO
__COMPLETION_DEFAULT_AI_TONE: (tone) => (tone ? `以${tone}的語氣回應我:(請你模仿各種情緒)` : ''), // TODO
__COMPLETION_DEFAULT_AI_TONE_SHY: '以害羞的語氣回應我:', // TODO
__COMPLETION_SEARCH: (a, q) => `根據「${a}」查詢結果,回答「${q}」問題`, // TODO
__COMPLETION_SEARCH_NOT_FOUND: '查無資料', // TODO
__COMPLETION_QUOTATION_MARK_OPENING: '"',
Expand Down
3 changes: 2 additions & 1 deletion locales/ja.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ const ja = {
__COMPLETION_DEFAULT_SYSTEM_PROMPT: '', // TODO
__COMPLETION_DEFAULT_HUMAN_PROMPT: (name) => (name ? `私は${name}です` : 'こんにちは'),
__COMPLETION_DEFAULT_AI_PROMPT: (name) => (name ? `私は${name}です` : 'こんにちは'),
__COMPLETION_DEFAULT_AI_TONE: (tone) => (tone ? `以${tone}的語氣回應我:` : ''), // TODO
__COMPLETION_DEFAULT_AI_TONE: (tone) => (tone ? `以${tone}的語氣回應我:(請你模仿各種情緒)` : ''), // TODO
__COMPLETION_DEFAULT_AI_TONE_SHY: '以害羞的語氣回應我:', // TODO
__COMPLETION_SEARCH: (a, q) => `根據「${a}」查詢結果,回答「${q}」問題`, // TODO
__COMPLETION_SEARCH_NOT_FOUND: '查無資料', // TODO
__COMPLETION_QUOTATION_MARK_OPENING: '「',
Expand Down
3 changes: 2 additions & 1 deletion locales/zh.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ const zh = {
__COMPLETION_DEFAULT_SYSTEM_PROMPT: '以下將使用繁體中文進行對話。',
__COMPLETION_DEFAULT_HUMAN_PROMPT: (name) => (name ? `我是${name}` : '哈囉'),
__COMPLETION_DEFAULT_AI_PROMPT: (name) => (name ? `我是${name}` : '哈囉'),
__COMPLETION_DEFAULT_AI_TONE: (tone) => (tone ? `以${tone}的語氣回應我:` : ''),
__COMPLETION_DEFAULT_AI_TONE: (tone) => (tone ? `以${tone}的語氣回應我:(請你模仿各種情緒)` : ''),
__COMPLETION_DEFAULT_AI_TONE_SHY: '以害羞的語氣回應我:',
__COMPLETION_SEARCH: (a, q) => `根據「${a}」查詢結果,回答「${q}」問題`,
__COMPLETION_SEARCH_NOT_FOUND: '查無資料',
__COMPLETION_QUOTATION_MARK_OPENING: '「',
Expand Down