mirror of
https://github.com/idootop/mi-gpt.git
synced 2025-04-07 22:44:03 +00:00
feat: 支持更新 bot/master 人设
This commit is contained in:
parent
27d523f9ba
commit
e5a2889b8a
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
@ -23,5 +23,8 @@
|
|||
},
|
||||
"[prisma]": {
|
||||
"editor.defaultFormatter": "Prisma.prisma"
|
||||
},
|
||||
"[typescript]": {
|
||||
"editor.defaultFormatter": "esbenp.prettier-vscode"
|
||||
}
|
||||
}
|
||||
|
|
4
TODO.md
4
TODO.md
|
@ -4,5 +4,5 @@
|
|||
- ✅ Update long/short memories
|
||||
- ✅ Logger
|
||||
- ✅ Npm export
|
||||
- ✅ Docker
|
||||
- 更新人设:你是[xxx]你[爱/喜欢][xxx]
|
||||
- ✅ 更新人设:你是[xxx]你[xxx]
|
||||
- Docker
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"name": "mi-gpt",
|
||||
"version": "1.0.0",
|
||||
"type": "module",
|
||||
"description": "Seamlessly integrate your XiaoAI speaker and Mi Home devices with ChatGPT for an enhanced smart home experience.",
|
||||
"description": "将小爱音箱接入 ChatGPT 和豆包,改造成你的专属语音助手。",
|
||||
"license": "MIT",
|
||||
"author": {
|
||||
"name": "Del Wang",
|
||||
|
@ -29,7 +29,7 @@
|
|||
"axios": "^1.6.5",
|
||||
"fs-extra": "^11.2.0",
|
||||
"https-proxy-agent": "^7.0.4",
|
||||
"mi-service-lite": "^2.1.0",
|
||||
"mi-service-lite": "^2.2.0",
|
||||
"openai": "^4.28.0",
|
||||
"prisma": "^5.8.1"
|
||||
},
|
||||
|
|
|
@ -6,7 +6,7 @@ import { Logger } from "./utils/log";
|
|||
import { deleteFile } from "./utils/io";
|
||||
|
||||
export type MiGPTConfig = Omit<MyBotConfig, "speaker"> & {
|
||||
speaker: AISpeakerConfig;
|
||||
speaker: Omit<AISpeakerConfig, "name">;
|
||||
};
|
||||
|
||||
export class MiGPT {
|
||||
|
@ -29,9 +29,6 @@ export class MiGPT {
|
|||
"如果需要切换设备或账号,请先使用 MiGPT.reset() 重置实例。"
|
||||
);
|
||||
} else {
|
||||
if (config.bot?.name && !config.speaker.name) {
|
||||
config.speaker.name = config.bot?.name;
|
||||
}
|
||||
MiGPT.instance = new MiGPT({ ...config, fromCreate: true });
|
||||
}
|
||||
return MiGPT.instance;
|
||||
|
|
|
@ -78,6 +78,56 @@ export class MyBot {
|
|||
constructor(config: MyBotConfig) {
|
||||
this.speaker = config.speaker;
|
||||
this.manager = new ConversationManager(config);
|
||||
// 更新 bot 人设命令
|
||||
// 比如:你是蔡徐坤,喜欢唱跳rap。
|
||||
this.speaker.addCommand({
|
||||
match: (msg) =>
|
||||
/.*你是(?<name>[^你]*)你(?<profile>.*)/.exec(msg.text) != null,
|
||||
run: async (msg) => {
|
||||
const res = /.*你是(?<name>[^你]*)你(?<profile>.*)/.exec(msg.text)!;
|
||||
const name = res[1];
|
||||
const profile = res[2];
|
||||
const config = await this.manager.update({
|
||||
bot: { name, profile },
|
||||
});
|
||||
if (config) {
|
||||
this.speaker.name = config?.bot.name;
|
||||
await this.speaker.response({
|
||||
text: `我是${name},很高兴认识你!`,
|
||||
keepAlive: this.speaker.keepAlive,
|
||||
});
|
||||
} else {
|
||||
await this.speaker.response({
|
||||
text: `召唤${name}失败,请稍后再试吧!`,
|
||||
keepAlive: this.speaker.keepAlive,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
this.speaker.addCommand({
|
||||
match: (msg) =>
|
||||
/.*我是(?<name>[^我]*)我(?<profile>.*)/.exec(msg.text) != null,
|
||||
run: async (msg) => {
|
||||
const res = /.*我是(?<name>[^我]*)我(?<profile>.*)/.exec(msg.text)!;
|
||||
const name = res[1];
|
||||
const profile = res[2];
|
||||
const config = await this.manager.update({
|
||||
bot: { name, profile },
|
||||
});
|
||||
if (config) {
|
||||
this.speaker.name = config?.bot.name;
|
||||
await this.speaker.response({
|
||||
text: `好的主人,我记住了!`,
|
||||
keepAlive: this.speaker.keepAlive,
|
||||
});
|
||||
} else {
|
||||
await this.speaker.response({
|
||||
text: `哎呀出错了,请稍后再试吧!`,
|
||||
keepAlive: this.speaker.keepAlive,
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
stop() {
|
||||
|
@ -86,7 +136,10 @@ export class MyBot {
|
|||
|
||||
async run() {
|
||||
this.speaker.askAI = (msg) => this.ask(msg);
|
||||
await this.manager.init();
|
||||
const { bot } = await this.manager.init();
|
||||
if (bot) {
|
||||
this.speaker.name = bot.name;
|
||||
}
|
||||
return this.speaker.run();
|
||||
}
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ export class Speaker extends BaseSpeaker {
|
|||
}
|
||||
|
||||
addCommand(command: SpeakerCommand) {
|
||||
this.commands.push(command);
|
||||
this._commands.push(command);
|
||||
}
|
||||
|
||||
async onMessage(msg: QueryMessage) {
|
||||
|
|
|
@ -927,10 +927,10 @@ merge2@^1.3.0, merge2@^1.4.1:
|
|||
resolved "https://registry.yarnpkg.com/merge2/-/merge2-1.4.1.tgz#4368892f885e907455a6fd7dc55c0c9d404990ae"
|
||||
integrity sha512-8q7VEgMJW4J8tcfVPy8g09NcQwZdbwFEqhe/WZkoIzjn/3TGDwtOCYtXGxA3O8tPzpczCCDgv+P2P5y00ZJOOg==
|
||||
|
||||
mi-service-lite@^2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/mi-service-lite/-/mi-service-lite-2.1.0.tgz#a05d85340f18d3ee5278afc180294273235533c5"
|
||||
integrity sha512-yy7q/7sR36PiE+0kIXgGDQ8ZUCrnLpMUxqtpmdIQgKBsyCaxBx0QNEcscwY+2ejx3WLwbB+ObMy6yR9fznx6hg==
|
||||
mi-service-lite@^2.2.0:
|
||||
version "2.2.0"
|
||||
resolved "https://registry.yarnpkg.com/mi-service-lite/-/mi-service-lite-2.2.0.tgz#30bcebaa8faeb83d1606be0c2ef552a4621dc722"
|
||||
integrity sha512-rcepSHGA4yUOjI9Tim/1kgu6BzMGeblMl+Nm5aevlRoXw7vv/x8fGx3jiwMV+LX6aDyY7NABEBbjwdPc98wlGA==
|
||||
dependencies:
|
||||
axios "^1.6.5"
|
||||
pako "^2.1.0"
|
||||
|
|
Loading…
Reference in New Issue
Block a user