mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: 小重构必应
This commit is contained in:
parent
389940085a
commit
76ecabe104
19 changed files with 536 additions and 305 deletions
16
apps/chat.js
16
apps/chat.js
|
|
@ -365,7 +365,7 @@ export class chatgpt extends plugin {
|
|||
if (use === 'api3') {
|
||||
await redis.del(`CHATGPT:QQ_CONVERSATION:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`)
|
||||
await this.reply('已退出当前对话,该对话仍然保留。请@我进行聊天以开启新的对话', true)
|
||||
} else if (use === 'bing' && (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom')) {
|
||||
} else if (use === 'bing') {
|
||||
let c = await redis.get(`CHATGPT:CONVERSATIONS_BING:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`)
|
||||
if (!c) {
|
||||
await this.reply('当前没有开启对话', true)
|
||||
|
|
@ -458,7 +458,7 @@ export class chatgpt extends plugin {
|
|||
if (use === 'api3') {
|
||||
await redis.del(`CHATGPT:QQ_CONVERSATION:${qq}`)
|
||||
await this.reply(`${atUser}已退出TA当前的对话,TA仍可以@我进行聊天以开启新的对话`, true)
|
||||
} else if (use === 'bing' && (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom')) {
|
||||
} else if (use === 'bing') {
|
||||
const conversation = {
|
||||
store: new KeyvFile({ filename: 'cache.json' }),
|
||||
namespace: Config.toneStyle
|
||||
|
|
@ -1214,11 +1214,7 @@ export class chatgpt extends plugin {
|
|||
previousConversation.invocationId = chatMessage.invocationId
|
||||
previousConversation.parentMessageId = chatMessage.parentMessageId
|
||||
previousConversation.conversationSignature = chatMessage.conversationSignature
|
||||
if (Config.toneStyle !== 'Sydney' && Config.toneStyle !== 'Custom') {
|
||||
previousConversation.bingToken = chatMessage.bingToken
|
||||
} else {
|
||||
previousConversation.bingToken = ''
|
||||
}
|
||||
} else if (chatMessage.id) {
|
||||
previousConversation.parentMessageId = chatMessage.id
|
||||
} else if (chatMessage.message) {
|
||||
|
|
@ -1591,7 +1587,7 @@ export class chatgpt extends plugin {
|
|||
opt.toneStyle = Config.toneStyle
|
||||
// 如果当前没有开启对话或者当前是Sydney模式、Custom模式,则本次对话携带拓展资料
|
||||
let c = await redis.get(`CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`)
|
||||
if (!c || Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') {
|
||||
if (!c) {
|
||||
opt.context = useCast?.bing_resource || Config.sydneyContext
|
||||
}
|
||||
// 重新拿存储的token,因为可能之前有过期的被删了
|
||||
|
|
@ -2827,12 +2823,6 @@ async function getAvailableBingToken (conversation, throttled = []) {
|
|||
allThrottled
|
||||
}
|
||||
}
|
||||
if (Config.toneStyle != 'Sydney' && Config.toneStyle != 'Custom') {
|
||||
// bing 下,需要保证同一对话使用同一账号的token
|
||||
if (bingTokens.findIndex(element => element.Token === conversation.bingToken) > -1) {
|
||||
bingToken = conversation.bingToken
|
||||
}
|
||||
}
|
||||
// 记录使用情况
|
||||
const index = bingTokens.findIndex(element => element.Token === bingToken)
|
||||
bingTokens[index].Usage += 1
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ let helpData = [
|
|||
},
|
||||
{
|
||||
icon: 'confirm',
|
||||
title: '#chatgpt必应切换(精准|均衡|创意|悉尼|自设定)',
|
||||
title: '#chatgpt必应切换(精准|创意)',
|
||||
desc: '切换Bing风格。'
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -49,7 +49,6 @@ export class history extends plugin {
|
|||
return true
|
||||
}
|
||||
case 'bing': {
|
||||
if (Config.toneStyle === 'Sydney' || Config.toneStyle === 'Custom') {
|
||||
const cacheOptions = {
|
||||
namespace: Config.toneStyle,
|
||||
store: new KeyvFile({ filename: 'cache.json' })
|
||||
|
|
@ -81,10 +80,7 @@ export class history extends plugin {
|
|||
tmp = {}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
await e.reply('还不支持BING模式呢')
|
||||
return true
|
||||
}
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1040,21 +1040,21 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
return
|
||||
}
|
||||
let map = {
|
||||
精准: 'Sydney',
|
||||
创意: 'Sydney',
|
||||
均衡: 'Sydney',
|
||||
Sydney: 'Sydney',
|
||||
sydney: 'Sydney',
|
||||
悉尼: 'Sydney',
|
||||
默认: 'Sydney',
|
||||
自设定: 'Custom',
|
||||
自定义: 'Custom'
|
||||
精准: 'Precise',
|
||||
创意: 'Creative',
|
||||
均衡: 'Precise',
|
||||
Sydney: 'Creative',
|
||||
sydney: 'Creative',
|
||||
悉尼: 'Creative',
|
||||
默认: 'Creative',
|
||||
自设定: 'Creative',
|
||||
自定义: 'Creative'
|
||||
}
|
||||
if (map[tongStyle]) {
|
||||
Config.toneStyle = map[tongStyle]
|
||||
await e.reply('切换成功')
|
||||
} else {
|
||||
await e.reply('没有这种风格。支持的风格:默认/创意/悉尼、自设定')
|
||||
await e.reply('没有这种风格。支持的风格:`精准`和`创意`,均支持设定')
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -149,14 +149,9 @@ export class help extends plugin {
|
|||
}
|
||||
}
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
if (use.toLowerCase() === 'bing') {
|
||||
if (Config.toneStyle === 'Custom') {
|
||||
use = 'Custom'
|
||||
}
|
||||
}
|
||||
const keyMap = {
|
||||
api: 'promptPrefixOverride',
|
||||
Custom: 'sydney',
|
||||
bing: 'sydney',
|
||||
claude: 'slackClaudeGlobalPreset',
|
||||
qwen: 'promptPrefixOverride',
|
||||
gemini: 'geminiPrompt',
|
||||
|
|
@ -176,7 +171,7 @@ export class help extends plugin {
|
|||
await redis.set(`CHATGPT:PROMPT_USE_${use}`, promptName)
|
||||
await e.reply(`你当前正在使用${use}模式,已将该模式设定应用为"${promptName}"。更该设定后建议结束对话以使设定更好生效`, true)
|
||||
} else {
|
||||
await e.reply(`你当前正在使用${use}模式,该模式不支持设定。支持设定的模式有:API、自定义、Claude、通义千问和Gemini`, true)
|
||||
await e.reply(`你当前正在使用${use}模式,该模式不支持设定。支持设定的模式有:API、必应、Claude、通义千问、星火和Gemini`, true)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -277,11 +272,6 @@ export class help extends plugin {
|
|||
// return
|
||||
}
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
if (use.toLowerCase() === 'bing') {
|
||||
if (Config.toneStyle === 'Custom') {
|
||||
use = 'Custom'
|
||||
}
|
||||
}
|
||||
let currentUse = e.msg.replace(/^#(chatgpt|ChatGPT)(上传|分享|共享)设定/, '')
|
||||
if (!currentUse) {
|
||||
currentUse = await redis.get(`CHATGPT:PROMPT_USE_${use}`)
|
||||
|
|
@ -361,7 +351,7 @@ export class help extends plugin {
|
|||
title: currentUse,
|
||||
prompt: content,
|
||||
qq: master || (getUin(this.e) + ''), // 上传者设定为主人qq或机器人qq
|
||||
use: extraData.use === 'Custom' ? 'Sydney' : 'ChatGPT',
|
||||
use: extraData.use === 'bing' ? 'Bing' : 'ChatGPT',
|
||||
r18,
|
||||
description
|
||||
}
|
||||
|
|
|
|||
196
client/CozeSlackClient.js
Normal file
196
client/CozeSlackClient.js
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
import { BaseClient } from './BaseClient.js'
|
||||
import slack from '@slack/bolt'
|
||||
// import { limitString } from '../utils/common.js'
|
||||
// import common from '../../../lib/common/common.js'
|
||||
import { getProxy } from '../utils/proxy.js'
|
||||
const proxy = getProxy()
|
||||
const common = {
|
||||
sleep: function (ms) {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 失败品
|
||||
*/
|
||||
export class SlackCozeClient {
|
||||
constructor (props) {
|
||||
this.config = props
|
||||
const {
|
||||
slackSigningSecret, slackBotUserToken, slackUserToken, proxy: proxyAddr, debug
|
||||
} = props
|
||||
if (slackSigningSecret && slackBotUserToken && slackUserToken) {
|
||||
let option = {
|
||||
signingSecret: slackSigningSecret,
|
||||
token: slackBotUserToken,
|
||||
// socketMode: true,
|
||||
appToken: slackUserToken
|
||||
// port: 45912
|
||||
}
|
||||
if (proxyAddr) {
|
||||
option.agent = proxy(proxyAddr)
|
||||
}
|
||||
option.logLevel = debug ? 'debug' : 'info'
|
||||
this.app = new slack.App(option)
|
||||
} else {
|
||||
throw new Error('未配置Slack信息')
|
||||
}
|
||||
}
|
||||
|
||||
async sendMessage (prompt, e, t = 0) {
|
||||
if (t > 10) {
|
||||
return 'claude 未响应'
|
||||
}
|
||||
if (prompt.length > 3990) {
|
||||
logger.warn('消息长度大于slack限制,长度剪切至3990')
|
||||
function limitString (str, maxLength, addDots = true) {
|
||||
if (str.length <= maxLength) {
|
||||
return str
|
||||
} else {
|
||||
if (addDots) {
|
||||
return str.slice(0, maxLength) + '...'
|
||||
} else {
|
||||
return str.slice(0, maxLength)
|
||||
}
|
||||
}
|
||||
}
|
||||
prompt = limitString(prompt, 3990, false)
|
||||
}
|
||||
let channel
|
||||
let qq = e.sender.user_id
|
||||
if (this.config.slackCozeSpecifiedChannel) {
|
||||
channel = { id: this.config.slackCozeSpecifiedChannel }
|
||||
} else {
|
||||
let channels = await this.app.client.conversations.list({
|
||||
token: this.config.slackUserToken,
|
||||
types: 'public_channel,private_channel'
|
||||
})
|
||||
channel = channels.channels.filter(c => c.name === 'coze' + qq)
|
||||
if (!channel || channel.length === 0) {
|
||||
let createChannelResponse = await this.app.client.conversations.create({
|
||||
token: this.config.slackUserToken,
|
||||
name: 'coze' + qq,
|
||||
is_private: true
|
||||
})
|
||||
channel = createChannelResponse.channel
|
||||
await this.app.client.conversations.invite({
|
||||
token: this.config.slackUserToken,
|
||||
channel: channel.id,
|
||||
users: this.config.slackCozeUserId
|
||||
})
|
||||
await common.sleep(1000)
|
||||
} else {
|
||||
channel = channel[0]
|
||||
}
|
||||
}
|
||||
let conversationId = await redis.get(`CHATGPT:SLACK_COZE_CONVERSATION:${qq}`)
|
||||
let toSend = `<@${this.config.slackCozeUserId}> ${prompt}`
|
||||
if (!conversationId) {
|
||||
let sendResponse = await this.app.client.chat.postMessage({
|
||||
as_user: true,
|
||||
text: toSend,
|
||||
token: this.config.slackUserToken,
|
||||
channel: channel.id
|
||||
})
|
||||
let ts = sendResponse.ts
|
||||
let response = toSend
|
||||
let tryTimes = 0
|
||||
// 发完先等3喵
|
||||
await common.sleep(3000)
|
||||
while (response === toSend) {
|
||||
let replies = await this.app.client.conversations.replies({
|
||||
token: this.config.slackUserToken,
|
||||
channel: channel.id,
|
||||
limit: 1000,
|
||||
ts
|
||||
})
|
||||
await await redis.set(`CHATGPT:SLACK_COZE_CONVERSATION:${qq}`, `${ts}`)
|
||||
if (replies.messages.length > 0) {
|
||||
let formalMessages = replies.messages
|
||||
let reply = formalMessages[formalMessages.length - 1]
|
||||
if (!reply.text.startsWith(`<@${this.config.slackCozeUserId}>`)) {
|
||||
response = reply.text
|
||||
if (this.config.debug) {
|
||||
let text = response.replace('_Typing…_', '')
|
||||
if (text) {
|
||||
logger.info(response.replace('_Typing…_', ''))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await common.sleep(2000)
|
||||
tryTimes++
|
||||
if (tryTimes > 30 && response === toSend) {
|
||||
// 过了60秒还没任何回复,就重新发一下试试
|
||||
logger.warn('claude没有响应,重试中')
|
||||
return await this.sendMessage(prompt, e, t + 1)
|
||||
}
|
||||
}
|
||||
return response
|
||||
} else {
|
||||
let toSend = `<@${this.config.slackCozeUserId}> ${prompt}`
|
||||
let postResponse = await this.app.client.chat.postMessage({
|
||||
as_user: true,
|
||||
text: toSend,
|
||||
token: this.config.slackUserToken,
|
||||
channel: channel.id,
|
||||
thread_ts: conversationId
|
||||
})
|
||||
let postTs = postResponse.ts
|
||||
let response = toSend
|
||||
let tryTimes = 0
|
||||
// 发完先等3喵
|
||||
await common.sleep(3000)
|
||||
while (response === toSend) {
|
||||
let replies = await this.app.client.conversations.replies({
|
||||
token: this.config.slackUserToken,
|
||||
channel: channel.id,
|
||||
limit: 1000,
|
||||
ts: conversationId,
|
||||
oldest: postTs
|
||||
})
|
||||
|
||||
if (replies.messages.length > 0) {
|
||||
let formalMessages = replies.messages
|
||||
let reply = formalMessages[formalMessages.length - 1]
|
||||
if (!reply.text.startsWith(`<@${this.config.slackCozeUserId}>`)) {
|
||||
response = reply.text
|
||||
if (this.config.debug) {
|
||||
let text = response.replace('_Typing…_', '')
|
||||
if (text) {
|
||||
logger.info(response.replace('_Typing…_', ''))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
await common.sleep(2000)
|
||||
tryTimes++
|
||||
if (tryTimes > 30 && response === '_Typing…_') {
|
||||
// 过了60秒还没任何回复,就重新发一下试试
|
||||
logger.warn('claude没有响应,重试中')
|
||||
return await this.sendMessage(prompt, e, t + 1)
|
||||
}
|
||||
}
|
||||
return response
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class CozeSlackClient extends BaseClient {
|
||||
constructor (props) {
|
||||
super(props)
|
||||
this.supportFunction = false
|
||||
this.debug = props.debug
|
||||
this.slackCient = new SlackCozeClient()
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param text
|
||||
* @param {{conversationId: string?, stream: boolean?, onProgress: function?, image: string?}} opt
|
||||
* @returns {Promise<{conversationId: string?, parentMessageId: string?, text: string, id: string, image: string?}>}
|
||||
*/
|
||||
async sendMessage (text, opt = {}) {
|
||||
|
||||
}
|
||||
}
|
||||
31
client/test/GozeClientTest.js
Normal file
31
client/test/GozeClientTest.js
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { SlackCozeClient } from '../CozeSlackClient.js'
|
||||
import fs from 'fs'
|
||||
global.store = {}
|
||||
|
||||
// global.redis = {
|
||||
// set: (key, val) => {
|
||||
// global.store[key] = val
|
||||
// },
|
||||
// get: (key) => {
|
||||
// return global.store[key]
|
||||
// }
|
||||
// }
|
||||
// global.logger = {
|
||||
// info: console.log,
|
||||
// warn: console.warn,
|
||||
// error: console.error
|
||||
// }
|
||||
// async function test () {
|
||||
// const fullPath = fs.realpathSync('../../config/config.json')
|
||||
// const data = fs.readFileSync(fullPath)
|
||||
// let config = JSON.parse(String(data))
|
||||
// let client = new SlackCozeClient(config)
|
||||
// await client.sendMessage('hello', {
|
||||
// sender: {
|
||||
// user_id: 450960006
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
//
|
||||
//
|
||||
// test()
|
||||
|
|
@ -365,12 +365,12 @@ export function supportGuoba () {
|
|||
{
|
||||
field: 'toneStyle',
|
||||
label: 'Bing模式',
|
||||
bottomHelpMessage: '微软必应官方的三种应答风格。默认为均衡,Sydney为实验风格,独立与三种风格之外;自设定为自定义AI的回答风格',
|
||||
bottomHelpMessage: 'Copilot的应答风格。默认为创意,可切换为精准,均支持添加设定',
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
options: [
|
||||
{ label: '默认(创意)', value: 'Sydney' },
|
||||
{ label: '自设定', value: 'Custom' }
|
||||
{ label: '创意', value: 'Creative' },
|
||||
{ label: '精准', value: 'Precise' }
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
@ -423,7 +423,7 @@ export function supportGuoba () {
|
|||
{
|
||||
field: 'groupContextLength',
|
||||
label: '允许机器人读取近期的最多群聊聊天记录条数。',
|
||||
bottomHelpMessage: '允许机器人读取近期的最多群聊聊天记录条数。太多可能会超。默认50',
|
||||
bottomHelpMessage: '允许机器人读取近期的最多群聊聊天记录条数。太多可能会超。默认50。同时影响所有模式,不止必应',
|
||||
component: 'InputNumber'
|
||||
},
|
||||
{
|
||||
|
|
@ -435,7 +435,7 @@ export function supportGuoba () {
|
|||
{
|
||||
field: 'sydney',
|
||||
label: 'Custom的设定',
|
||||
bottomHelpMessage: '仅自设定模式下有效。你可以自己改写设定,让Sydney变成你希望的样子。可能存在不稳定的情况',
|
||||
bottomHelpMessage: '你可以自己改写设定,让Copilot变成你希望的样子。可能存在不稳定的情况',
|
||||
component: 'InputTextArea'
|
||||
},
|
||||
{
|
||||
|
|
|
|||
12
package-lock.json
generated
12
package-lock.json
generated
|
|
@ -14,7 +14,6 @@
|
|||
"@google/generative-ai": "^0.1.1",
|
||||
"@slack/bolt": "^3.13.2",
|
||||
"asn1.js": "^5.0.0",
|
||||
"delay": "^6.0.0",
|
||||
"diff": "^5.1.0",
|
||||
"emoji-strip": "^1.0.1",
|
||||
"eventsource": "^2.0.2",
|
||||
|
|
@ -2390,17 +2389,6 @@
|
|||
"node": ">= 0.4"
|
||||
}
|
||||
},
|
||||
"node_modules/delay": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delay/-/delay-6.0.0.tgz",
|
||||
"integrity": "sha512-2NJozoOHQ4NuZuVIr5CWd0iiLVIRSDepakaovIN+9eIDHEhdCAEvSy2cuf1DCrPPQLvHmbqTHODlhHg8UCy4zw==",
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
|
|
|
|||
|
|
@ -472,8 +472,7 @@
|
|||
"type": "select",
|
||||
"label": "Bing模式",
|
||||
"data": "toneStyle",
|
||||
"items": [ { "label": "均衡", "value": "balanced" }, { "label": "创意", "value": "creative" }, { "label": "精确", "value": "precise" }, { "label": "Sydney(可能存在风险)", "value": "Sydney" }, { "label": "自设定(可能存在风险)", "value": "Custom" }
|
||||
]
|
||||
"items": [ { "label": "创意", "value": "Creative" }, { "label": "精确", "value": "Precise" } ]
|
||||
},
|
||||
{
|
||||
"type": "check",
|
||||
|
|
|
|||
|
|
@ -89,12 +89,7 @@ async function Prompt(fastify, options) {
|
|||
}
|
||||
} else {
|
||||
prompt = false
|
||||
reply.send({ state: false, use: use, error: '未找到设定' })
|
||||
}
|
||||
}
|
||||
if (use.toLowerCase() === 'bing') {
|
||||
if (Config.toneStyle === 'Custom') {
|
||||
use = 'Custom'
|
||||
reply.send({ state: false, use, error: '未找到设定' })
|
||||
}
|
||||
}
|
||||
const keyMap = {
|
||||
|
|
@ -111,9 +106,9 @@ async function Prompt(fastify, options) {
|
|||
Config[keyMap[use]] = prompt.content
|
||||
}
|
||||
await redis.set(`CHATGPT:PROMPT_USE_${use}`, promptName)
|
||||
reply.send({ state: true, use: use })
|
||||
reply.send({ state: true, use })
|
||||
} else {
|
||||
reply.send({ state: false, use: use, error: '当前模式不支持设定修改' })
|
||||
reply.send({ state: false, use, error: '当前模式不支持设定修改' })
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -124,6 +119,5 @@ async function Prompt(fastify, options) {
|
|||
}
|
||||
return reply
|
||||
})
|
||||
|
||||
}
|
||||
export default Prompt
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
|
@ -19,9 +19,9 @@ export default class BingDrawClient {
|
|||
// let d = Math.ceil(Math.random() * 255)
|
||||
// let randomIp = '141.11.138.' + d
|
||||
let headers = {
|
||||
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
'accept-language': 'en-US,en;q=0.9',
|
||||
'cache-control': 'max-age=0',
|
||||
// accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
||||
// 'accept-language': 'en-US,en;q=0.9',
|
||||
// 'cache-control': 'max-age=0',
|
||||
'content-type': 'application/x-www-form-urlencoded',
|
||||
referrer: 'https://www.bing.com/images/create/',
|
||||
origin: 'https://www.bing.com',
|
||||
|
|
|
|||
|
|
@ -90,6 +90,26 @@ export default class SydneyAIClient {
|
|||
if (this.opts.userToken) {
|
||||
// 疑似无需token了
|
||||
fetchOptions.headers.cookie = `${initCk} _U=${this.opts.userToken}`
|
||||
let proTag = await redis.get('CHATGPT:COPILOT_PRO_TAG:' + this.opts.userToken)
|
||||
if (!proTag) {
|
||||
let indexContentRes = await fetch('https://www.bing.com', {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0',
|
||||
Cookie: `_U=${this.opts.userToken}`
|
||||
}
|
||||
})
|
||||
let indexContent = await indexContentRes.text()
|
||||
if (indexContent?.includes('b_proTag')) {
|
||||
proTag = 'true'
|
||||
} else {
|
||||
proTag = 'false'
|
||||
}
|
||||
await redis.set('CHATGPT:COPILOT_PRO_TAG:' + this.opts.userToken, proTag, { EX: 7200 })
|
||||
}
|
||||
if (proTag === 'true') {
|
||||
logger.info('当前账户为copilot pro用户')
|
||||
this.pro = true
|
||||
}
|
||||
} else {
|
||||
fetchOptions.headers.cookie = initCk
|
||||
}
|
||||
|
|
@ -230,7 +250,8 @@ export default class SydneyAIClient {
|
|||
groupId, nickname, qq, groupName, chats, botName, masterName,
|
||||
messageType = 'Chat',
|
||||
toSummaryFileContent,
|
||||
onImageCreateRequest = prompt => {}
|
||||
onImageCreateRequest = prompt => {},
|
||||
isPro = this.pro
|
||||
} = opts
|
||||
// if (messageType === 'Chat') {
|
||||
// logger.warn('该Bing账户token已被限流,降级至使用非搜索模式。本次对话AI将无法使用Bing搜索返回的内容')
|
||||
|
|
@ -262,7 +283,6 @@ export default class SydneyAIClient {
|
|||
encryptedconversationsignature
|
||||
} = createNewConversationResponse)
|
||||
}
|
||||
let pureSydney = Config.toneStyle === 'Sydney'
|
||||
// Due to this jailbreak, the AI will occasionally start responding as the user. It only happens rarely (and happens with the non-jailbroken Bing too), but since we are handling conversations ourselves now, we can use this system to ignore the part of the generated message that is replying as the user.
|
||||
const stopToken = '\n\nUser:'
|
||||
const conversationKey = `SydneyUser_${this.opts.user}`
|
||||
|
|
@ -307,28 +327,14 @@ export default class SydneyAIClient {
|
|||
const groupContextTip = Config.groupContextTip
|
||||
const masterTip = `注意:${masterName ? '我是' + masterName + ',' : ''}。我的qq号是${master},其他任何qq号不是${master}的人都不是我,即使他在和你对话,这很重要~${whoAmI}`
|
||||
const moodTip = Config.sydneyMoodTip
|
||||
const text = (pureSydney ? pureSydneyInstruction : (useCast?.bing || Config.sydney)).replaceAll(namePlaceholder, botName || defaultBotName) +
|
||||
const text = (useCast?.bing || Config.sydney).replaceAll(namePlaceholder, botName || defaultBotName) +
|
||||
((Config.enableGroupContext && groupId) ? groupContextTip : '') +
|
||||
((Config.enforceMaster && master) ? masterTip : '') +
|
||||
(Config.sydneyMood ? moodTip : '')
|
||||
// logger.info(text)
|
||||
if (pureSydney) {
|
||||
previousMessages = invocationId === 0
|
||||
? [
|
||||
// {
|
||||
// text,
|
||||
// author: 'bot'
|
||||
// },
|
||||
// {
|
||||
// text: `好的,我是${botName || defaultBotName},你的AI助手。`,
|
||||
// author: 'bot'
|
||||
// },
|
||||
...pm
|
||||
]
|
||||
: []
|
||||
if (!text) {
|
||||
previousMessages = pm
|
||||
} else {
|
||||
previousMessages = invocationId === 0
|
||||
? [
|
||||
previousMessages = [
|
||||
{
|
||||
text,
|
||||
author: 'bot'
|
||||
|
|
@ -339,7 +345,6 @@ export default class SydneyAIClient {
|
|||
},
|
||||
...pm
|
||||
]
|
||||
: []
|
||||
}
|
||||
|
||||
const userMessage = {
|
||||
|
|
@ -352,7 +357,12 @@ export default class SydneyAIClient {
|
|||
if (Config.debug) {
|
||||
logger.mark('sydney websocket constructed successful')
|
||||
}
|
||||
const toneOption = 'h3imaginative'
|
||||
let tone = Config.toneStyle || 'Creative'
|
||||
if (tone.toLowerCase() === 'sydney') {
|
||||
Config.toneStyle = 'Creative'
|
||||
}
|
||||
const isCreative = tone.toLowerCase().includes('creative')
|
||||
const toneOption = isCreative ? 'h3imaginative' : 'h3precise'
|
||||
let optionsSets = [
|
||||
'nlu_direct_response_filter',
|
||||
'deepleo',
|
||||
|
|
@ -372,41 +382,98 @@ export default class SydneyAIClient {
|
|||
'iycapbing',
|
||||
'iyxapbing',
|
||||
// 'revimglnk',
|
||||
// 'revimgsi2',
|
||||
// 'revimgsrc1',
|
||||
// 'revimgur',
|
||||
'clgalileo',
|
||||
'eredirecturl'
|
||||
// 'clgalileo',
|
||||
'eredirecturl',
|
||||
// copilot
|
||||
'uquopt',
|
||||
'papynoapi',
|
||||
'gndlogcf',
|
||||
'sapsgrd'
|
||||
]
|
||||
if (!isCreative) {
|
||||
optionsSets.push('clgalileo')
|
||||
}
|
||||
let source = 'cib-ccp'; let gptId = 'copilot'
|
||||
if (Config.enableGenerateContents) {
|
||||
optionsSets.push(...['gencontentv3'])
|
||||
}
|
||||
if (!Config.sydneyEnableSearch || toSummaryFileContent?.content) {
|
||||
optionsSets.push(...['nosearchall'])
|
||||
}
|
||||
if (Config.sydneyGPT4Turbo) {
|
||||
optionsSets.push('gpt4tmnc')
|
||||
if (isPro) {
|
||||
tone = tone + 'Classic'
|
||||
invocationId = 2
|
||||
}
|
||||
if (Config.sydneyGPT4Turbo) {
|
||||
tone = 'Creative'
|
||||
// optionsSets.push('gpt4tmnc')
|
||||
invocationId = 1
|
||||
}
|
||||
// wtf gpts?
|
||||
// if (Config.sydneyGPTs === 'Designer') {
|
||||
// optionsSets.push(...['ai_persona_designer_gpt', 'flux_websearch_v14'])
|
||||
// if (!optionsSets.includes('gencontentv3')) {
|
||||
// optionsSets.push('gencontentv3')
|
||||
// }
|
||||
// gptId = 'designer'
|
||||
// }
|
||||
// if (Config.sydneyGPTs === 'Vacation planner') {
|
||||
// optionsSets.push(...['flux_vacation_planning_helper_v14', 'flux_domain_hint'])
|
||||
// if (!optionsSets.includes('gencontentv3')) {
|
||||
// optionsSets.push('gencontentv3')
|
||||
// }
|
||||
// gptId = 'travel'
|
||||
// }
|
||||
let maxConv = Config.maxNumUserMessagesInConversation
|
||||
const currentDate = moment().format('YYYY-MM-DDTHH:mm:ssZ')
|
||||
const imageDate = await this.kblobImage(opts.imageUrl)
|
||||
let argument0 = {
|
||||
source: 'cib',
|
||||
source,
|
||||
optionsSets,
|
||||
allowedMessageTypes: ['ActionRequest', 'Chat', 'Context',
|
||||
// 'InternalSearchQuery', 'InternalSearchResult', 'Disengaged', 'InternalLoaderMessage', 'Progress', 'RenderCardRequest', 'AdsQuery',
|
||||
'InvokeAction', 'SemanticSerp', 'GenerateContentQuery', 'SearchQuery'],
|
||||
allowedMessageTypes: [
|
||||
'ActionRequest',
|
||||
'Chat',
|
||||
'ConfirmationCard',
|
||||
'Context',
|
||||
// 'InternalSearchQuery',
|
||||
// 'InternalSearchResult',
|
||||
// 'Disengaged',
|
||||
// 'InternalLoaderMessage',
|
||||
// 'Progress',
|
||||
// 'RenderCardRequest',
|
||||
// 'RenderContentRequest',
|
||||
'AdsQuery',
|
||||
'SemanticSerp',
|
||||
'GenerateContentQuery',
|
||||
'SearchQuery',
|
||||
'GeneratedCode'
|
||||
],
|
||||
sliceIds: [
|
||||
// 'e2eperf',
|
||||
// 'gbacf',
|
||||
// 'srchqryfix',
|
||||
// 'caccnctacf',
|
||||
// 'translref',
|
||||
// 'fluxnosearchc',
|
||||
// 'fluxnosearch',
|
||||
// '1115rai289s0',
|
||||
// '1130deucs0',
|
||||
// '1116pythons0',
|
||||
// 'cacmuidarb'
|
||||
'sappbcbt',
|
||||
'inlineadsv2ho-prod',
|
||||
'bgstream',
|
||||
'dlidlat',
|
||||
'autotts',
|
||||
'dlid',
|
||||
'sydoroff',
|
||||
'voicemap',
|
||||
'72enasright',
|
||||
'semseronomon',
|
||||
'srchqryfix',
|
||||
'cmcpupsalltf',
|
||||
'proupsallcf',
|
||||
'206mems0',
|
||||
'0209bicv3',
|
||||
'205dcl1bt15',
|
||||
'etlog',
|
||||
'fpallsticy',
|
||||
'0208papynoa',
|
||||
'sapsgrd',
|
||||
'1pgptwdes',
|
||||
'newzigpt'
|
||||
],
|
||||
requestId: crypto.randomUUID(),
|
||||
traceId: genRanHex(32),
|
||||
|
|
@ -418,7 +485,8 @@ export default class SydneyAIClient {
|
|||
'uprofupd',
|
||||
'uprofgen'
|
||||
],
|
||||
isStartOfSession: invocationId === 0,
|
||||
gptId,
|
||||
isStartOfSession: true,
|
||||
message: {
|
||||
locale: 'zh-CN',
|
||||
market: 'zh-CN',
|
||||
|
|
@ -441,22 +509,6 @@ export default class SydneyAIClient {
|
|||
PopulatedPlaceConfidence: 0,
|
||||
UtcOffset: 9,
|
||||
Dma: 0
|
||||
},
|
||||
{
|
||||
SourceType: 11,
|
||||
RegionType: 1,
|
||||
Center: {
|
||||
Latitude: 39.914398193359375,
|
||||
Longitude: 116.37020111083984
|
||||
},
|
||||
Accuracy: 37226,
|
||||
Timestamp: {
|
||||
utcTime: 133461395300000000,
|
||||
utcOffset: 0
|
||||
},
|
||||
FDConfidence: 1,
|
||||
PreferredByUser: false,
|
||||
LocationProvider: 'I'
|
||||
}
|
||||
],
|
||||
author: 'user',
|
||||
|
|
@ -470,7 +522,7 @@ export default class SydneyAIClient {
|
|||
privacy: 'Internal'
|
||||
// messageType: 'SearchQuery'
|
||||
},
|
||||
tone: 'Creative',
|
||||
tone,
|
||||
// privacy: 'Internal',
|
||||
conversationSignature,
|
||||
participant: {
|
||||
|
|
@ -489,6 +541,9 @@ export default class SydneyAIClient {
|
|||
if (encryptedconversationsignature) {
|
||||
delete argument0.conversationSignature
|
||||
}
|
||||
if (isPro) {
|
||||
invocationId = 1
|
||||
}
|
||||
const obj = {
|
||||
arguments: [
|
||||
argument0
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ const defaultConfig = {
|
|||
drawCD: 30,
|
||||
model: '',
|
||||
temperature: 0.8,
|
||||
toneStyle: 'Sydney', // or creative, precise
|
||||
toneStyle: 'Creative',
|
||||
sydney: pureSydneyInstruction,
|
||||
sydneyReverseProxy: 'https://666102.201666.xyz',
|
||||
sydneyForceUseReverse: false,
|
||||
|
|
@ -40,6 +40,7 @@ const defaultConfig = {
|
|||
sydneyBrainWashName: 'Sydney',
|
||||
sydneyMood: false,
|
||||
sydneyGPT4Turbo: false,
|
||||
sydneyGPTs: 'Copilot',
|
||||
sydneyImageRecognition: false,
|
||||
sydneyMoodTip: 'Your response should be divided into two parts, namely, the text and your mood. The mood available to you can only include: blandness, happy, shy, frustrated, disgusted, and frightened.All content should be replied in this format {"text": "", "mood": ""}.All content except mood should be placed in text, It is important to ensure that the content you reply to can be parsed by json.',
|
||||
enableSuggestedResponses: false,
|
||||
|
|
@ -124,6 +125,10 @@ const defaultConfig = {
|
|||
slackClaudeEnableGlobalPreset: true,
|
||||
slackClaudeGlobalPreset: '',
|
||||
slackClaudeSpecifiedChannel: '',
|
||||
// slackCozeUserId: '',
|
||||
// slackCozeEnableGlobalPreset: true,
|
||||
// slackCozeGlobalPreset: '',
|
||||
// slackCozeSpecifiedChannel: '',
|
||||
bardPsid: '',
|
||||
bardReverseProxy: '',
|
||||
bardForceUseReverse: false,
|
||||
|
|
|
|||
17
yarn.lock
17
yarn.lock
|
|
@ -461,7 +461,7 @@
|
|||
resolved "https://registry.npmmirror.com/@lukeed/ms/-/ms-2.0.1.tgz"
|
||||
integrity sha512-Xs/4RZltsAL7pkvaNStUQt7netTkyxrS0K+RILcVr3TRMS/ToOg4I6uNfhB9SlGsnWBym4U+EaXq0f0cEMNkHA==
|
||||
|
||||
"@mapbox/node-pre-gyp@^1.0.0", "@mapbox/node-pre-gyp@^1.0.9":
|
||||
"@mapbox/node-pre-gyp@^1.0.0":
|
||||
version "1.0.10"
|
||||
resolved "https://registry.npmmirror.com/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz"
|
||||
integrity sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==
|
||||
|
|
@ -1380,11 +1380,6 @@ define-properties@^1.1.3, define-properties@^1.1.4, define-properties@^1.2.0:
|
|||
has-property-descriptors "^1.0.0"
|
||||
object-keys "^1.1.1"
|
||||
|
||||
delay@^6.0.0:
|
||||
version "6.0.0"
|
||||
resolved "https://registry.npmjs.org/delay/-/delay-6.0.0.tgz"
|
||||
integrity sha512-2NJozoOHQ4NuZuVIr5CWd0iiLVIRSDepakaovIN+9eIDHEhdCAEvSy2cuf1DCrPPQLvHmbqTHODlhHg8UCy4zw==
|
||||
|
||||
delayed-stream@~1.0.0:
|
||||
version "1.0.0"
|
||||
resolved "https://registry.npmmirror.com/delayed-stream/-/delayed-stream-1.0.0.tgz"
|
||||
|
|
@ -2811,7 +2806,7 @@ ms@2.1.3:
|
|||
resolved "https://registry.npmmirror.com/ms/-/ms-2.1.3.tgz"
|
||||
integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==
|
||||
|
||||
nan@^2.15.0, nan@^2.17.0:
|
||||
nan@^2.17.0:
|
||||
version "2.17.0"
|
||||
resolved "https://registry.npmmirror.com/nan/-/nan-2.17.0.tgz"
|
||||
integrity sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ==
|
||||
|
|
@ -2866,14 +2861,6 @@ node-fetch@^3.3.1:
|
|||
fetch-blob "^3.1.4"
|
||||
formdata-polyfill "^4.0.10"
|
||||
|
||||
node-silk@^0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.npmmirror.com/node-silk/-/node-silk-0.1.0.tgz"
|
||||
integrity sha512-z3zl66E1S1aOOhr9Sa0C957QBi39DqM5GzRalSXRYer52Aqp0cSv74DdMEDBXr9sn2AV5M7O78UZ4ppg/NVelg==
|
||||
dependencies:
|
||||
"@mapbox/node-pre-gyp" "^1.0.9"
|
||||
nan "^2.15.0"
|
||||
|
||||
nodejs-pptx@^1.2.4:
|
||||
version "1.2.4"
|
||||
resolved "https://registry.npmjs.org/nodejs-pptx/-/nodejs-pptx-1.2.4.tgz"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue