feat: 适配copilot pro账户的gpt4-turbo选项

This commit is contained in:
ikechan8370 2024-01-16 20:32:22 +08:00
parent 3709166b2d
commit 8bdf9a3b6d
5 changed files with 60 additions and 32 deletions

View file

@ -71,7 +71,7 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
* @param {{conversationId: string?, parentMessageId: string?, stream: boolean?, onProgress: function?, functionResponse: FunctionResponse?, system: string?, image: string?}} opt * @param {{conversationId: string?, parentMessageId: string?, stream: boolean?, onProgress: function?, functionResponse: FunctionResponse?, system: string?, image: string?}} opt
* @returns {Promise<{conversationId: string?, parentMessageId: string, text: string, id: string}>} * @returns {Promise<{conversationId: string?, parentMessageId: string, text: string, id: string}>}
*/ */
async sendMessage (text, opt) { async sendMessage (text, opt = {}) {
let history = await this.getHistory(opt.parentMessageId) let history = await this.getHistory(opt.parentMessageId)
let systemMessage = opt.system let systemMessage = opt.system
if (systemMessage) { if (systemMessage) {
@ -208,9 +208,10 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
// execute function // execute function
try { try {
let args = Object.assign(functionCall.args, { let args = Object.assign(functionCall.args, {
isAdmin: this.e.group.is_admin, isAdmin: this.e.group?.is_admin,
isOwner: this.e.group.is_owner, isOwner: this.e.group?.is_owner,
sender: this.e.sender sender: this.e.sender,
mode: 'gemini'
}) })
functionResponse.response.content = await chosenTool.func(args, this.e) functionResponse.response.content = await chosenTool.func(args, this.e)
if (this.debug) { if (this.debug) {

View file

@ -403,6 +403,12 @@ export function supportGuoba () {
bottomHelpMessage: '加强主人认知。希望机器人认清主人避免NTR可开启。开启后可能会与自设定的内容有部分冲突。sydney模式可以放心开启', bottomHelpMessage: '加强主人认知。希望机器人认清主人避免NTR可开启。开启后可能会与自设定的内容有部分冲突。sydney模式可以放心开启',
component: 'Switch' component: 'Switch'
}, },
{
field: 'sydneyGPT4Turbo',
label: '使用GPT4-turbo',
bottomHelpMessage: '目前仅Copilot Pro可开启。非pro用户开启会报错。',
component: 'Switch'
},
{ {
field: 'enableGenerateContents', field: 'enableGenerateContents',
label: '允许生成图像等内容', label: '允许生成图像等内容',

View file

@ -383,6 +383,9 @@ export default class SydneyAIClient {
if (!Config.sydneyEnableSearch || toSummaryFileContent?.content) { if (!Config.sydneyEnableSearch || toSummaryFileContent?.content) {
optionsSets.push(...['nosearchall']) optionsSets.push(...['nosearchall'])
} }
if (Config.sydneyGPT4Turbo) {
optionsSets.push('gpt4tmnc')
}
let maxConv = Config.maxNumUserMessagesInConversation let maxConv = Config.maxNumUserMessagesInConversation
const currentDate = moment().format('YYYY-MM-DDTHH:mm:ssZ') const currentDate = moment().format('YYYY-MM-DDTHH:mm:ssZ')
const imageDate = await this.kblobImage(opts.imageUrl) const imageDate = await this.kblobImage(opts.imageUrl)
@ -482,6 +485,7 @@ export default class SydneyAIClient {
// } // }
] ]
} }
if (encryptedconversationsignature) { if (encryptedconversationsignature) {
delete argument0.conversationSignature delete argument0.conversationSignature
} }

View file

@ -39,6 +39,7 @@ const defaultConfig = {
sydneyBrainWashStrength: 15, sydneyBrainWashStrength: 15,
sydneyBrainWashName: 'Sydney', sydneyBrainWashName: 'Sydney',
sydneyMood: false, sydneyMood: false,
sydneyGPT4Turbo: false,
sydneyImageRecognition: false, 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.', 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, enableSuggestedResponses: false,

View file

@ -5,6 +5,7 @@ import fetch from 'node-fetch'
import proxy from 'https-proxy-agent' import proxy from 'https-proxy-agent'
import { getMaxModelTokens } from '../common.js' import { getMaxModelTokens } from '../common.js'
import { ChatGPTPuppeteer } from '../browser.js' import { ChatGPTPuppeteer } from '../browser.js'
import { CustomGoogleGeminiClient } from '../../client/CustomGoogleGeminiClient.js'
export class WebsiteTool extends AbstractTool { export class WebsiteTool extends AbstractTool {
name = 'website' name = 'website'
@ -19,7 +20,7 @@ export class WebsiteTool extends AbstractTool {
} }
func = async function (opts) { func = async function (opts) {
let { url } = opts let { url, mode, e } = opts
try { try {
// let res = await fetch(url, { // let res = await fetch(url, {
// headers: { // headers: {
@ -58,6 +59,20 @@ export class WebsiteTool extends AbstractTool {
.replace(/[\n\r]/gi, '') // 去除回车换行 .replace(/[\n\r]/gi, '') // 去除回车换行
.replace(/\s{2}/g, '') // 多个空格只保留一个空格 .replace(/\s{2}/g, '') // 多个空格只保留一个空格
.replace('<!DOCTYPE html>', '') // 去除<!DOCTYPE>声明 .replace('<!DOCTYPE html>', '') // 去除<!DOCTYPE>声明
if (mode === 'gemini') {
let client = new CustomGoogleGeminiClient({
e,
userId: e?.sender?.user_id,
key: Config.geminiKey,
model: Config.geminiModel,
baseUrl: Config.geminiBaseUrl,
debug: Config.debug
})
const htmlContentSummaryRes = await client.sendMessage(`去除与主体内容无关的部分从中整理出主体内容并转换成md格式不需要主观描述性的语言与冗余的空白行。${text}`)
let htmlContentSummary = htmlContentSummaryRes.text
return `this is the main content of website:\n ${htmlContentSummary}`
} else {
let maxModelTokens = getMaxModelTokens(Config.model) let maxModelTokens = getMaxModelTokens(Config.model)
text = text.slice(0, Math.min(text.length, maxModelTokens - 1600)) text = text.slice(0, Math.min(text.length, maxModelTokens - 1600))
let completionParams = { let completionParams = {
@ -86,6 +101,7 @@ export class WebsiteTool extends AbstractTool {
const htmlContentSummaryRes = await api.sendMessage(`去除与主体内容无关的部分从中整理出主体内容并转换成md格式不需要主观描述性的语言与冗余的空白行。${text}`, { completionParams }) const htmlContentSummaryRes = await api.sendMessage(`去除与主体内容无关的部分从中整理出主体内容并转换成md格式不需要主观描述性的语言与冗余的空白行。${text}`, { completionParams })
let htmlContentSummary = htmlContentSummaryRes.text let htmlContentSummary = htmlContentSummaryRes.text
return `this is the main content of website:\n ${htmlContentSummary}` return `this is the main content of website:\n ${htmlContentSummary}`
}
} catch (err) { } catch (err) {
return `failed to visit the website, error: ${err.toString()}` return `failed to visit the website, error: ${err.toString()}`
} }