-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
30c54ed
commit e5b65ed
Showing
24 changed files
with
281 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { | ||
kfc, | ||
ChatType, | ||
createAssistant, | ||
createMockTextMessage, | ||
MultiChatModelSwitch, | ||
} from '../src'; | ||
|
||
const assistant = createAssistant({ | ||
llm: new MultiChatModelSwitch([ | ||
{ | ||
name: 'yiyan', | ||
human_name: '文心一言', | ||
input_type: [ChatType.Text], | ||
summary: '文心一言 [百度]', | ||
call(ctx) { | ||
console.log('[文心一言] 收到', ctx.message.text()); | ||
}, | ||
}, | ||
{ | ||
name: 'xinghuo', | ||
human_name: '星火认知 [讯飞]', | ||
input_type: [ChatType.Text], | ||
call(ctx) { | ||
console.log('[讯飞星火] 收到', ctx.message.text()); | ||
}, | ||
}, | ||
]), | ||
}); | ||
|
||
assistant.command.addCommand(kfc) | ||
|
||
async function main() { | ||
assistant.run(); | ||
|
||
await assistant.handler(createMockTextMessage('帮助')); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { | ||
ChatERNIEBot, | ||
ChatQWen, | ||
MultiChatModelSwitch, | ||
createAssistant, | ||
} from '../src'; | ||
import { WechatyBuilder } from 'wechaty'; | ||
import { EventLogger, QRCodeTerminal } from 'wechaty-plugin-contrib'; | ||
|
||
const ernie = new ChatERNIEBot({ | ||
token: process.env.EB_ACCESS_TOKEN, // 飞桨平台的 token | ||
}); | ||
|
||
const qwen = new ChatQWen({ | ||
apiKey: process.env.QWEN_API_KEY, | ||
}) | ||
|
||
const assistant = createAssistant({ | ||
llm: new MultiChatModelSwitch([ernie, qwen]) | ||
}); | ||
|
||
const bot = WechatyBuilder.build({ | ||
name: 'demo', | ||
puppet: 'wechaty-puppet-wechat4u', | ||
puppetOptions: { uos: true }, | ||
}); | ||
|
||
bot.use(QRCodeTerminal({ small: true })); | ||
bot.use(EventLogger(['login', 'logout', 'error', 'friendship', 'room-invite'])); | ||
|
||
// 作为插件使用 | ||
bot.use(assistant.callback()); | ||
|
||
bot.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Keywords } from '../interfaces' | ||
|
||
export const keywords: Keywords = { | ||
newConversation: ['新对话', '新聊天', '重新开始', '重新对话', '重新聊天', '重新对话', '重新开始对话', '重新开始聊天', '重新开始对话'], | ||
stopConversation: ['停', '停止', '停止回复'], | ||
help: ['帮助', '获取帮助'], | ||
sourceCode: ['获取源码', '查看源码'], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { html } from 'common-tags'; | ||
import { MultiChatModelSwitch } from '../llms' | ||
import { type ConversationContext } from '../interfaces'; | ||
|
||
export function printHelp(ctx: ConversationContext) { | ||
const { llm } = ctx | ||
const llms = llm instanceof MultiChatModelSwitch ? llm.llms : [llm]; | ||
|
||
const commands = Array.from(ctx.assistant.command.commands.values()); | ||
|
||
return ctx.reply(html` | ||
⊶ 帮助信息 | ||
﹊ | ||
口令 | ||
☛ 重新开始 | ||
☛ 停止 | ||
☛ 查看模型 | ||
☛ 切换 <模型名称> | ||
☛ 帮助 | ||
☛ 查看源码 | ||
指令 | ||
${commands.map(cmd => ` ☛ ${cmd.name}`)} | ||
模型列表 | ||
${llms.map(m => ` ☛ ${m.summary || m.human_name}`)} | ||
如恶意使用,将拉入黑名单,敬请谅解。`); | ||
} |
Oops, something went wrong.