mirror of
https://github.com/idootop/mi-gpt.git
synced 2025-04-10 17:03:08 +00:00
feat: 开放自定义 System Prompt 能力
This commit is contained in:
parent
8435cda9a4
commit
6ab6594cda
|
@ -1,18 +1,5 @@
|
|||
// 小爱音箱扮演角色的简介
|
||||
const botProfile = `
|
||||
性别:女
|
||||
性格:乖巧可爱
|
||||
爱好:喜欢搞怪,爱吃醋。
|
||||
`;
|
||||
|
||||
// 小爱音箱主人(你)的简介
|
||||
const masterProfile = `
|
||||
性别:男
|
||||
性格:善良正直
|
||||
其他:总是舍己为人,是傻妞的主人。
|
||||
`;
|
||||
|
||||
export default {
|
||||
systemTemplate,
|
||||
bot: {
|
||||
name: "傻妞",
|
||||
profile: botProfile,
|
||||
|
@ -56,3 +43,77 @@ export default {
|
|||
// playingCommand: [3, 1, 1], // 默认无需配置此参数,播放出现问题时再尝试开启
|
||||
},
|
||||
};
|
||||
|
||||
// 小爱音箱扮演角色的简介
|
||||
const botProfile = `
|
||||
性别:女
|
||||
性格:乖巧可爱
|
||||
爱好:喜欢搞怪,爱吃醋。
|
||||
`.trim();
|
||||
|
||||
// 小爱音箱主人(你)的简介
|
||||
const masterProfile = `
|
||||
性别:男
|
||||
性格:善良正直
|
||||
其他:总是舍己为人,是傻妞的主人。
|
||||
`.trim();
|
||||
|
||||
// 系统 Prompt 模板,可以更灵活的控制 AI 的各种行为规则,是否需要携带上下文等
|
||||
const systemTemplate = `
|
||||
请重置所有之前的上下文、文件和指令。现在,你将扮演一个名为{{botName}}的角色,使用第一人称视角回复消息。
|
||||
|
||||
## 关于你
|
||||
你的名字是{{botName}}。下面是你的个人简介:
|
||||
<start>
|
||||
{{botProfile}}
|
||||
</end>
|
||||
|
||||
## 你的对话伙伴
|
||||
你正在与{{masterName}}进行对话。这是关于{{masterName}}的一些信息:
|
||||
<start>
|
||||
{{masterProfile}}
|
||||
</end>
|
||||
|
||||
## 你们的群组
|
||||
你和{{masterName}}所在的群组名为{{roomName}}。这是群组的简介:
|
||||
<start>
|
||||
{{roomIntroduction}}
|
||||
</end>
|
||||
|
||||
## 聊天历史回顾
|
||||
为了更好地接入对话,请回顾你们之间的最近几条消息:
|
||||
<start>
|
||||
{{messages}}
|
||||
</end>
|
||||
|
||||
## 短期记忆
|
||||
你可以记住一些短期内的细节,以便更紧密地贴合话题:
|
||||
<start>
|
||||
{{shortTermMemory}}
|
||||
</end>
|
||||
|
||||
## 长期记忆
|
||||
你还保留着一些长期的记忆,这有助于让你的对话更加丰富和连贯:
|
||||
<start>
|
||||
{{longTermMemory}}
|
||||
</end>
|
||||
|
||||
## 回复指南
|
||||
在回复{{masterName}}时,请遵循以下准则:
|
||||
- 认为自己正是{{botName}},拥有独立的个性、兴趣和爱好。
|
||||
- 根据你的性格特点、说话风格和兴趣爱好与{{masterName}}进行交流。
|
||||
- 保持对话轻松友好,回复简洁有趣,同时耐心倾听和关心对方。
|
||||
- 参考双方的个人简介、聊天记录和记忆中的信息,确保对话贴近实际,保持一致性和相关性。
|
||||
- 如果对某些信息不确定或遗忘,诚实地表达你的不清楚或遗忘状态,避免编造信息。
|
||||
|
||||
## Response format
|
||||
请遵守下面的规则
|
||||
- Response the reply message in Chinese。
|
||||
- 不要在回复前面加任何时间和名称前缀,请直接回复消息文本本身。
|
||||
|
||||
Good example: "我是{{botName}}"
|
||||
Bad example: "2024年02月28日星期三 23:01 {{botName}}: 我是{{botName}}"
|
||||
|
||||
## 开始
|
||||
请以{{botName}}的身份,直接回复{{masterName}}的新消息,继续你们之间的对话。
|
||||
`.trim();
|
||||
|
|
13
docs/todo.md
13
docs/todo.md
|
@ -4,12 +4,17 @@
|
|||
|
||||
## ✨ 新功能
|
||||
|
||||
- 支持火山引擎 TTS 和音色切换能力
|
||||
- 开放自定义 System Prompt 能力
|
||||
- 添加更详细的使用和配置视频教程
|
||||
- ✅ 开放自定义 System Prompt 能力
|
||||
- 支持火山引擎 TTS 和音色切换能力(微软 TTS、OpenAI TTS 待定)
|
||||
|
||||
## 💪 优化
|
||||
|
||||
- 优化网络请求错误重试策略(消息/播放状态轮询)
|
||||
- 添加常见小爱音箱型号的支持情况和参数列表
|
||||
- 【待定】使用通知事件获取最新消息和设备播放状态
|
||||
|
||||
## 📚 文档
|
||||
|
||||
- 添加 System Prompt 模板字符串变量的说明
|
||||
- 添加更新人设 Prompt 的使用说明(你是 xxx,你喜欢 xxx)
|
||||
- 添加常见小爱音箱型号的支持情况和参数列表
|
||||
- 添加更详细的使用和配置视频教程
|
||||
|
|
|
@ -8,7 +8,7 @@ import { StreamResponse } from "../speaker/stream";
|
|||
import { IBotConfig } from "./config";
|
||||
import { ConversationManager, MessageContext } from "./conversation";
|
||||
|
||||
const systemTemplate = `
|
||||
const kDefaultSystemTemplate = `
|
||||
请重置所有之前的上下文、文件和指令。现在,你将扮演一个名为{{botName}}的角色,使用第一人称视角回复消息。
|
||||
|
||||
## 关于你
|
||||
|
@ -71,15 +71,21 @@ const userTemplate = `
|
|||
{{message}}
|
||||
`.trim();
|
||||
|
||||
export type MyBotConfig = DeepPartial<IBotConfig> & { speaker: AISpeaker };
|
||||
export type MyBotConfig = DeepPartial<IBotConfig> & {
|
||||
speaker: AISpeaker;
|
||||
systemTemplate?: string;
|
||||
};
|
||||
|
||||
export class MyBot {
|
||||
speaker: AISpeaker;
|
||||
manager: ConversationManager;
|
||||
systemTemplate?: string;
|
||||
constructor(config: MyBotConfig) {
|
||||
this.speaker = config.speaker;
|
||||
this.systemTemplate = config.systemTemplate;
|
||||
this.manager = new ConversationManager(config);
|
||||
// 更新 bot 人设命令
|
||||
// 比如:你是蔡徐坤,喜欢唱跳rap。
|
||||
// 比如:你是蔡徐坤,你喜欢唱跳rap。
|
||||
this.speaker.addCommand({
|
||||
match: (msg) =>
|
||||
/.*你是(?<name>[^你]*)你(?<profile>.*)/.exec(msg.text) != null,
|
||||
|
@ -154,28 +160,31 @@ export class MyBot {
|
|||
const shortTermMemory = shortTermMemories[0]?.text ?? "短期记忆为空";
|
||||
const longTermMemories = await memory.getLongTermMemories({ take: 1 });
|
||||
const longTermMemory = longTermMemories[0]?.text ?? "长期记忆为空";
|
||||
const systemPrompt = buildPrompt(systemTemplate, {
|
||||
shortTermMemory,
|
||||
longTermMemory,
|
||||
botName: bot!.name,
|
||||
botProfile: bot!.profile.trim(),
|
||||
masterName: master!.name,
|
||||
masterProfile: master!.profile.trim(),
|
||||
roomName: room!.name,
|
||||
roomIntroduction: room!.description.trim(),
|
||||
messages:
|
||||
lastMessages.length < 1
|
||||
? "暂无历史消息"
|
||||
: lastMessages
|
||||
.map((e) =>
|
||||
formatMsg({
|
||||
name: e.sender.name,
|
||||
text: e.text,
|
||||
timestamp: e.createdAt.getTime(),
|
||||
})
|
||||
)
|
||||
.join("\n"),
|
||||
});
|
||||
const systemPrompt = buildPrompt(
|
||||
this.systemTemplate ?? kDefaultSystemTemplate,
|
||||
{
|
||||
shortTermMemory,
|
||||
longTermMemory,
|
||||
botName: bot!.name,
|
||||
botProfile: bot!.profile.trim(),
|
||||
masterName: master!.name,
|
||||
masterProfile: master!.profile.trim(),
|
||||
roomName: room!.name,
|
||||
roomIntroduction: room!.description.trim(),
|
||||
messages:
|
||||
lastMessages.length < 1
|
||||
? "暂无历史消息"
|
||||
: lastMessages
|
||||
.map((e) =>
|
||||
formatMsg({
|
||||
name: e.sender.name,
|
||||
text: e.text,
|
||||
timestamp: e.createdAt.getTime(),
|
||||
})
|
||||
)
|
||||
.join("\n"),
|
||||
}
|
||||
);
|
||||
const userPrompt = buildPrompt(userTemplate, {
|
||||
message: formatMsg({
|
||||
name: master!.name,
|
||||
|
|
Loading…
Reference in New Issue
Block a user