Skip to content

Commit

Permalink
remove mirai code
Browse files Browse the repository at this point in the history
  • Loading branch information
SchneeHertz committed Nov 6, 2023
1 parent 9507f15 commit c50a28b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 73 deletions.
68 changes: 2 additions & 66 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ const {
systemPrompt,
useProxy,
proxyObject,
miraiSetting = {},
functionCallingRoundLimit = 3
} = config
const proxyString = `${proxyObject.protocol}://${proxyObject.host}:${proxyObject.port}`
Expand Down Expand Up @@ -385,11 +384,11 @@ const resolveMessages = async ({ resArgument, resFunction, resText, resTextTemp,
* @param {Object} options.triggerRecord - The trigger record object.
* @return {Promise<void>} - A promise that resolves with the generated response.
*/
const resloveAdminPrompt = async ({ prompt, triggerRecord, miraiSystemPrompt }) => {
const resloveAdminPrompt = async ({ prompt, triggerRecord, givenSystemPrompt }) => {
let from = triggerRecord ? `(${AI_NAME})` : AI_NAME
let history = getStore('history')
let messages = [
{ role: 'system', content: miraiSystemPrompt ? miraiSystemPrompt : systemPrompt },
{ role: 'system', content: givenSystemPrompt ? givenSystemPrompt : systemPrompt },
{ role: 'user', content: `我的名字是${ADMIN_NAME}` },
{ role: 'assistant', content: `你好, ${ADMIN_NAME}` },
..._.takeRight(history, 12),
Expand Down Expand Up @@ -558,66 +557,3 @@ ipcMain.handle('load-setting', async () => {
ipcMain.handle('save-setting', async (event, receiveSetting) => {
return await fs.promises.writeFile(path.join(STORE_PATH, 'config.json'), JSON.stringify(receiveSetting, null, ' '), { encoding: 'utf-8' })
})

// mirai connect
// const { connectWs } = require('./modules/mirai.js')
// if (miraiSetting.USE_MIRAI) {
// connectWs(miraiSetting.VERIFY_KEY)
// .then(wss=>{
// let tempMessage = []
// wss.addEventListener('message', async (event) => {
// let messageObject = JSON.parse(event.data).data || {}
// if (messageObject.type === 'GroupMessage') {
// let message = `###${messageObject.sender.memberName}: `
// let forceReply
// let hasPlain = false
// messageObject.messageChain.forEach(part => {
// switch (part.type) {
// case 'At':
// if (part.target === miraiSetting.QQ) {
// forceReply = messageObject.sender.id
// }
// message += part.display + ' '
// break
// case 'Plain':
// hasPlain = true
// message += part.text
// break
// }
// })
// if (hasPlain) {
// tempMessage.push(message + '###')
// let prepareMessage = {
// target: miraiSetting.QQ_GROUP_NUMBER,
// messageChain:[]
// }
// if (forceReply) {
// prepareMessage.messageChain.push({
// type: 'At',
// target: forceReply
// })
// }
// if (forceReply || message.includes('休留') || Math.random() > 0.95) {
// let prompt = `历史消息:\n ${_.initial(_.takeRight(tempMessage, 10)).join('\n')}\n当前消息:\n ${_.last(tempMessage)}`
// messageLogAndSend({
// id: nanoid(),
// from: '群聊',
// text: prompt
// })
// prepareMessage.messageChain.push({
// type:'Plain',
// text: await resloveAdminPrompt({ prompt, miraiSystemPrompt: `你是虚拟猫娘休留,你现在在聊天群里聊天,你需要遵守以下规则:\n1.群友会以###昵称: 内容###的形式发言\n2.记住你是在聊天,用高度口语化的表述发言,不要重复历史消息` })
// })
// tempMessage = []
// wss.send(JSON.stringify({
// syncId: -1,
// command: 'sendGroupMessage',
// subCommand: null,
// content: prepareMessage
// }))
// }
// }
// }
// })
// })
// }
73 changes: 72 additions & 1 deletion modules/mirai.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,75 @@ const connectWs = async (verifyKey) => {

module.exports = {
connectWs
}
}

// mirai connect
// const { connectWs } = require('./modules/mirai.js')
// if (miraiSetting.USE_MIRAI) {
// connectWs(miraiSetting.VERIFY_KEY)
// .then(wss=>{
// let tempMessage = []
// wss.addEventListener('message', async (event) => {
// let messageObject = JSON.parse(event.data).data || {}
// if (messageObject.type === 'GroupMessage') {
// let message = `###${messageObject.sender.memberName}: `
// let forceReply
// let hasPlain = false
// messageObject.messageChain.forEach(part => {
// switch (part.type) {
// case 'At':
// if (part.target === miraiSetting.QQ) {
// forceReply = messageObject.sender.id
// }
// message += part.display + ' '
// break
// case 'Plain':
// hasPlain = true
// message += part.text
// break
// }
// })
// if (hasPlain) {
// tempMessage.push(message + '###')
// let prepareMessage = {
// target: miraiSetting.QQ_GROUP_NUMBER,
// messageChain:[]
// }
// if (forceReply) {
// prepareMessage.messageChain.push({
// type: 'At',
// target: forceReply
// })
// }
// if (forceReply || message.includes('休留') || Math.random() > 0.95) {
// let prompt = `历史消息:\n ${_.initial(_.takeRight(tempMessage, 10)).join('\n')}\n当前消息:\n ${_.last(tempMessage)}`
// messageLogAndSend({
// id: nanoid(),
// from: '群聊',
// text: prompt
// })
// prepareMessage.messageChain.push({
// type:'Plain',
// text: await resloveAdminPrompt({ prompt, miraiSystemPrompt: `你是虚拟猫娘休留,你现在在聊天群里聊天,你需要遵守以下规则:\n1.群友会以###昵称: 内容###的形式发言\n2.记住你是在聊天,用高度口语化的表述发言,不要重复历史消息` })
// })
// tempMessage = []
// wss.send(JSON.stringify({
// syncId: -1,
// command: 'sendGroupMessage',
// subCommand: null,
// content: prepareMessage
// }))
// }
// }
// }
// })
// })
// }

// setting
// miraiSetting: {
// USE_MIRAI: false,
// VERIFY_KEY: '',
// QQ: 0,
// QQ_GROUP_NUMBER: 0
// },
6 changes: 0 additions & 6 deletions utils/loadConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ try {
host: '127.0.0.1',
port: 7890
},
miraiSetting: {
USE_MIRAI: false,
VERIFY_KEY: '',
QQ: 0,
QQ_GROUP_NUMBER: 0
},
functionCallingRoundLimit: 3
}
fs.writeFileSync(path.join(STORE_PATH, 'config.json'), JSON.stringify(config, null, ' '), { encoding: 'utf-8' })
Expand Down

0 comments on commit c50a28b

Please sign in to comment.