Merge pull request #686 from HalcyonAlcedo/v2

部分修复bing问题
This commit is contained in:
HalcyonAlcedo 2024-05-06 22:59:11 +08:00 committed by GitHub
commit a9ef38cbde
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 85 additions and 12 deletions

View file

@ -500,6 +500,11 @@
"label": "是否允许机器人读取近期的群聊聊天记录",
"data": "enableGroupContext"
},
{
"type": "check",
"label": "是否允许必应进行搜索",
"data": "sydneyEnableSearch"
},
{
"type": "number",
"label": "允许机器人读取近期的最多群聊聊天记录条数",
@ -581,6 +586,54 @@
"label": "第三方绘图",
"placeholder": "使用AP插件代替Bing进行绘图",
"data": "bingAPDraw"
},
{
"type": "textarea",
"label": "前置对话第一轮(用户)",
"placeholder": "会强行插入该轮对话,能有效抑制抱歉",
"data": "chatExampleUser1"
},
{
"type": "textarea",
"label": "前置对话第一轮AI",
"placeholder": "会强行插入该轮对话,能有效抑制抱歉",
"data": "chatExampleBot1"
},
{
"type": "textarea",
"label": "前置对话第二轮(用户)",
"placeholder": "会强行插入该轮对话,能有效抑制抱歉",
"data": "chatExampleUser2"
},
{
"type": "textarea",
"label": "前置对话第二轮AI",
"placeholder": "会强行插入该轮对话,能有效抑制抱歉",
"data": "chatExampleBot2"
},
{
"type": "textarea",
"label": "前置对话第三轮(用户)",
"placeholder": "会强行插入该轮对话,能有效抑制抱歉",
"data": "chatExampleUser3"
},
{
"type": "textarea",
"label": "前置对话第三轮AI",
"placeholder": "会强行插入该轮对话,能有效抑制抱歉",
"data": "chatExampleBot3"
}
]
},
{
"title": "智谱清言",
"tab": "chatGLM",
"view": [
{
"type": "password",
"label": "refresh token",
"placeholder": "chatglm_refresh_token 6个月有效期",
"data": "chatglmRefreshToken"
}
]
},
@ -1029,6 +1082,12 @@
"value": "prefix"
}
]
},
{
"type": "text",
"label": "主动发起聊天群聊的群号",
"placeholder": "在这些群聊里会不定时主动说一些随机的打招呼的话用英文逗号隔开。必须配置了OpenAI Key",
"data": "initiativeChatGroups"
}
]
},

View file

@ -2,6 +2,7 @@ import fetch, { FormData } from 'node-fetch'
import { makeForwardMsg } from './common.js'
import { Config } from './config.js'
import { getProxy } from './proxy.js'
import crypto from 'crypto'
let proxy = getProxy()
export default class BingDrawClient {
@ -47,7 +48,7 @@ export default class BingDrawClient {
}
// headers['x-forwarded-for'] = '141.11.138.30'
let body = new FormData()
body.append('q', prompt)
body.append('q', urlEncodedPrompt)
body.append('qs', 'ds')
let fetchOptions = {
headers
@ -65,6 +66,9 @@ export default class BingDrawClient {
throw new Error('Your prompt has been blocked by Bing. Try to change any bad words and try again.')
}
if (response.status !== 302) {
if (this.debug) {
console.debug(`第一次重试绘图:${prompt}`)
}
url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST', credentials: 'include' }))
}

View file

@ -386,7 +386,7 @@ export default class SydneyAIClient {
}
let optionsSets = getOptionSet(Config.toneStyle, Config.enableGenerateContents)
let source = 'cib-ccp'; let gptId = 'copilot'
if (!Config.sydneyEnableSearch || toSummaryFileContent?.content) {
if ((!Config.sydneyEnableSearch && !Config.enableGenerateContents) || toSummaryFileContent?.content) {
optionsSets.push(...['nosearchall'])
}
if (isPro) {
@ -410,7 +410,7 @@ export default class SydneyAIClient {
// }
let maxConv = Config.maxNumUserMessagesInConversation
const currentDate = moment().format('YYYY-MM-DDTHH:mm:ssZ')
const imageDate = await this.kblobImage(opts.imageUrl)
const imageDate = await this.kblobImage(opts.imageUrl, conversationId)
let argument0 = {
source,
optionsSets,
@ -430,7 +430,9 @@ export default class SydneyAIClient {
'SemanticSerp',
'GenerateContentQuery',
'SearchQuery',
'GeneratedCode'
'GeneratedCode',
// 'InternalTasksMessage',
// 'Disclaimer'
],
sliceIds: [],
requestId: crypto.randomUUID(),
@ -880,20 +882,31 @@ export default class SydneyAIClient {
}
}
async kblobImage (url) {
async kblobImage (url, conversationId) {
if (!url) return false
if (!conversationId) return false
// 获取并转换图片为base64
let imgBase64
try {
const response = await fetch(url)
const arrayBuffer = await response.arrayBuffer()
const buffer = Buffer.from(arrayBuffer)
imgBase64 = buffer.toString('base64')
} catch (error) {
console.error(error)
return false
}
const formData = new FormData()
formData.append('knowledgeRequest', JSON.stringify({
imageInfo: {
url
},
imageInfo: {},
knowledgeRequest: {
invokedSkills: ['ImageById'],
subscriptionId: 'Bing.Chat.Multimodal',
invokedSkillsRequestData: { enableFaceBlur: true },
convoData: { convoid: '', convotone: 'Creative' }
convoData: { convoid: conversationId, convotone: 'Creative' }
}
}))
formData.append('imageBase64', imgBase64)
const fetchOptions = {
headers: {
Referer: 'https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx'
@ -1014,8 +1027,5 @@ function getOptionSet (tone, generateContent = false) {
])
break
}
if (generateContent) {
optionset.push('gencontentv3')
}
return optionset
}