mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 21:37:11 +00:00
fix: 优化一些错误提示和一些代码格式化
This commit is contained in:
parent
c5d11efb74
commit
4bd6c8c7d8
3 changed files with 22 additions and 22 deletions
14
apps/chat.js
14
apps/chat.js
|
|
@ -524,8 +524,10 @@ export class chatgpt extends plugin {
|
||||||
prompt = e.raw_message.trim()
|
prompt = e.raw_message.trim()
|
||||||
if (e.isGroup) {
|
if (e.isGroup) {
|
||||||
let me = e.group.pickMember(Bot.uin)
|
let me = e.group.pickMember(Bot.uin)
|
||||||
let card = me.card || me.nickname
|
let card = me.card
|
||||||
|
let nickname = me.nickname
|
||||||
prompt = prompt.replace(`@${card}`, '').trim()
|
prompt = prompt.replace(`@${card}`, '').trim()
|
||||||
|
prompt = prompt.replace(`@${nickname}`, '').trim()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let ats = e.message.filter(m => m.type === 'at')
|
let ats = e.message.filter(m => m.type === 'at')
|
||||||
|
|
@ -747,7 +749,7 @@ export class chatgpt extends plugin {
|
||||||
} else {
|
} else {
|
||||||
previousConversation.bingToken = ''
|
previousConversation.bingToken = ''
|
||||||
}
|
}
|
||||||
} else {
|
} else if (chatMessage.id) {
|
||||||
previousConversation.parentMessageId = chatMessage.id
|
previousConversation.parentMessageId = chatMessage.id
|
||||||
}
|
}
|
||||||
if (Config.debug) {
|
if (Config.debug) {
|
||||||
|
|
@ -767,9 +769,9 @@ export class chatgpt extends plugin {
|
||||||
}
|
}
|
||||||
// 分离内容和情绪
|
// 分离内容和情绪
|
||||||
if (Config.sydneyMood) {
|
if (Config.sydneyMood) {
|
||||||
let temp_response = completeJSON(response)
|
let tempResponse = completeJSON(response)
|
||||||
if (temp_response.text) response = temp_response.text
|
if (tempResponse.text) response = tempResponse.text
|
||||||
if (temp_response.mood) mood = temp_response.mood
|
if (tempResponse.mood) mood = tempResponse.mood
|
||||||
} else {
|
} else {
|
||||||
mood = ''
|
mood = ''
|
||||||
}
|
}
|
||||||
|
|
@ -819,7 +821,7 @@ export class chatgpt extends plugin {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
await this.reply('你没有配置转语音API或者文字太长了哦')
|
await this.reply('你没有配置转语音API或者文字太长了哦')
|
||||||
}
|
}
|
||||||
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
|
} else if (userSetting.usePicture || (Config.autoUsePicture && response.length > Config.autoUsePictureThreshold)) {
|
||||||
// todo use next api of chatgpt to complete incomplete respoonse
|
// todo use next api of chatgpt to complete incomplete respoonse
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"author": "ikechan8370",
|
"author": "ikechan8370",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@waylaidwanderer/chatgpt-api": "^1.32.0",
|
"@waylaidwanderer/chatgpt-api": "^1.33.2",
|
||||||
"chatgpt": "^5.1.1",
|
"chatgpt": "^5.1.1",
|
||||||
"delay": "^5.0.0",
|
"delay": "^5.0.0",
|
||||||
"https-proxy-agent": "5.0.1",
|
"https-proxy-agent": "5.0.1",
|
||||||
|
|
@ -17,11 +17,11 @@
|
||||||
"ws": "^8.13.0"
|
"ws": "^8.13.0"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
|
"eventsource-parser": "^1.0.0",
|
||||||
"jimp": "^0.22.7",
|
"jimp": "^0.22.7",
|
||||||
"puppeteer-extra": "^3.3.6",
|
"puppeteer-extra": "^3.3.6",
|
||||||
"puppeteer-extra-plugin-recaptcha": "^3.6.8",
|
"puppeteer-extra-plugin-recaptcha": "^3.6.8",
|
||||||
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
"puppeteer-extra-plugin-stealth": "^2.11.2",
|
||||||
"sharp": "^0.31.3",
|
"sharp": "^0.31.3"
|
||||||
"eventsource-parser": "^1.0.0"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -120,6 +120,11 @@ export default class SydneyAIClient {
|
||||||
text = await response.text()
|
text = await response.text()
|
||||||
retry--
|
retry--
|
||||||
}
|
}
|
||||||
|
if (response.status !== 200) {
|
||||||
|
logger.error('创建sydney对话失败: status code: ' + response.status + response.statusText)
|
||||||
|
logger.error(text)
|
||||||
|
throw new Error(text)
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
return JSON.parse(text)
|
return JSON.parse(text)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
@ -144,6 +149,7 @@ export default class SydneyAIClient {
|
||||||
logger.mark(`use sydney websocket host: ${sydneyHost}`)
|
logger.mark(`use sydney websocket host: ${sydneyHost}`)
|
||||||
let ws = new WebSocket(sydneyHost + '/sydney/ChatHub', { agent })
|
let ws = new WebSocket(sydneyHost + '/sydney/ChatHub', { agent })
|
||||||
ws.on('error', (err) => {
|
ws.on('error', (err) => {
|
||||||
|
console.error(err)
|
||||||
reject(err)
|
reject(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -332,7 +338,6 @@ export default class SydneyAIClient {
|
||||||
role: 'User',
|
role: 'User',
|
||||||
message
|
message
|
||||||
}
|
}
|
||||||
|
|
||||||
const ws = await this.createWebSocketConnection()
|
const ws = await this.createWebSocketConnection()
|
||||||
if (Config.debug) {
|
if (Config.debug) {
|
||||||
logger.mark('sydney websocket constructed successful')
|
logger.mark('sydney websocket constructed successful')
|
||||||
|
|
@ -405,15 +410,6 @@ export default class SydneyAIClient {
|
||||||
target: 'chat',
|
target: 'chat',
|
||||||
type: 4
|
type: 4
|
||||||
}
|
}
|
||||||
// if (previousMessagesFormatted) {
|
|
||||||
// obj.arguments[0].previousMessages.push({
|
|
||||||
// author: 'user',
|
|
||||||
// description: previousMessagesFormatted,
|
|
||||||
// contextType: 'WebPage',
|
|
||||||
// messageType: 'Context',
|
|
||||||
// messageId: 'discover-web--page-ping-mriduna-----'
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// simulates document summary function on Edge's Bing sidebar
|
// simulates document summary function on Edge's Bing sidebar
|
||||||
// unknown character limit, at least up to 7k
|
// unknown character limit, at least up to 7k
|
||||||
if (groupId) {
|
if (groupId) {
|
||||||
|
|
@ -694,6 +690,9 @@ export default class SydneyAIClient {
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
ws.on('error', err => {
|
||||||
|
reject(err)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
const messageJson = JSON.stringify(obj)
|
const messageJson = JSON.stringify(obj)
|
||||||
|
|
@ -701,9 +700,8 @@ export default class SydneyAIClient {
|
||||||
console.debug(messageJson)
|
console.debug(messageJson)
|
||||||
console.debug('\n\n\n\n')
|
console.debug('\n\n\n\n')
|
||||||
}
|
}
|
||||||
ws.send(`${messageJson}`)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
ws.send(`${messageJson}`)
|
||||||
const {
|
const {
|
||||||
message: reply,
|
message: reply,
|
||||||
conversationExpiryTime
|
conversationExpiryTime
|
||||||
|
|
@ -729,7 +727,7 @@ export default class SydneyAIClient {
|
||||||
conversationExpiryTime,
|
conversationExpiryTime,
|
||||||
response: reply.text,
|
response: reply.text,
|
||||||
details: reply,
|
details: reply,
|
||||||
apology: Config.sydneyApologyIgnored && apology,
|
apology: Config.sydneyApologyIgnored && apology
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await this.conversationsCache.set(conversationKey, conversation)
|
await this.conversationsCache.set(conversationKey, conversation)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue