Skip to content

Commit

Permalink
feat: 适配copilot pro账户的gpt4-turbo选项
Browse files Browse the repository at this point in the history
  • Loading branch information
ikechan8370 committed Jan 16, 2024
1 parent 3709166 commit 8bdf9a3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 32 deletions.
9 changes: 5 additions & 4 deletions client/CustomGoogleGeminiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @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 systemMessage = opt.system
if (systemMessage) {
Expand Down Expand Up @@ -208,9 +208,10 @@ export class CustomGoogleGeminiClient extends GoogleGeminiClient {
// execute function
try {
let args = Object.assign(functionCall.args, {
isAdmin: this.e.group.is_admin,
isOwner: this.e.group.is_owner,
sender: this.e.sender
isAdmin: this.e.group?.is_admin,
isOwner: this.e.group?.is_owner,
sender: this.e.sender,
mode: 'gemini'
})
functionResponse.response.content = await chosenTool.func(args, this.e)
if (this.debug) {
Expand Down
6 changes: 6 additions & 0 deletions guoba.support.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,12 @@ export function supportGuoba () {
bottomHelpMessage: '加强主人认知。希望机器人认清主人,避免NTR可开启。开启后可能会与自设定的内容有部分冲突。sydney模式可以放心开启',
component: 'Switch'
},
{
field: 'sydneyGPT4Turbo',
label: '使用GPT4-turbo',
bottomHelpMessage: '目前仅Copilot Pro可开启。非pro用户开启会报错。',
component: 'Switch'
},
{
field: 'enableGenerateContents',
label: '允许生成图像等内容',
Expand Down
4 changes: 4 additions & 0 deletions utils/SydneyAIClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ export default class SydneyAIClient {
if (!Config.sydneyEnableSearch || toSummaryFileContent?.content) {
optionsSets.push(...['nosearchall'])
}
if (Config.sydneyGPT4Turbo) {
optionsSets.push('gpt4tmnc')
}
let maxConv = Config.maxNumUserMessagesInConversation
const currentDate = moment().format('YYYY-MM-DDTHH:mm:ssZ')
const imageDate = await this.kblobImage(opts.imageUrl)
Expand Down Expand Up @@ -482,6 +485,7 @@ export default class SydneyAIClient {
// }
]
}

if (encryptedconversationsignature) {
delete argument0.conversationSignature
}
Expand Down
1 change: 1 addition & 0 deletions utils/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const defaultConfig = {
sydneyBrainWashStrength: 15,
sydneyBrainWashName: 'Sydney',
sydneyMood: false,
sydneyGPT4Turbo: 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.',
enableSuggestedResponses: false,
Expand Down
72 changes: 44 additions & 28 deletions utils/tools/WebsiteTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import fetch from 'node-fetch'
import proxy from 'https-proxy-agent'
import { getMaxModelTokens } from '../common.js'
import { ChatGPTPuppeteer } from '../browser.js'
import { CustomGoogleGeminiClient } from '../../client/CustomGoogleGeminiClient.js'
export class WebsiteTool extends AbstractTool {
name = 'website'

Expand All @@ -19,7 +20,7 @@ export class WebsiteTool extends AbstractTool {
}

func = async function (opts) {
let { url } = opts
let { url, mode, e } = opts
try {
// let res = await fetch(url, {
// headers: {
Expand Down Expand Up @@ -58,34 +59,49 @@ export class WebsiteTool extends AbstractTool {
.replace(/[\n\r]/gi, '') // 去除回车换行
.replace(/\s{2}/g, '') // 多个空格只保留一个空格
.replace('<!DOCTYPE html>', '') // 去除<!DOCTYPE>声明
let maxModelTokens = getMaxModelTokens(Config.model)
text = text.slice(0, Math.min(text.length, maxModelTokens - 1600))
let completionParams = {
// model: Config.model
model: 'gpt-3.5-turbo-16k'

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)
text = text.slice(0, Math.min(text.length, maxModelTokens - 1600))
let completionParams = {
// model: Config.model
model: 'gpt-3.5-turbo-16k'
}
let api = new ChatGPTAPI({
apiBaseUrl: Config.openAiBaseUrl,
apiKey: Config.apiKey,
debug: false,
completionParams,
fetch: (url, options = {}) => {
const defaultOptions = Config.proxy
? {
agent: proxy(Config.proxy)
}
: {}
const mergedOptions = {
...defaultOptions,
...options
}
return fetch(url, mergedOptions)
},
maxModelTokens
})
const htmlContentSummaryRes = await api.sendMessage(`去除与主体内容无关的部分,从中整理出主体内容并转换成md格式,不需要主观描述性的语言与冗余的空白行。${text}`, { completionParams })
let htmlContentSummary = htmlContentSummaryRes.text
return `this is the main content of website:\n ${htmlContentSummary}`
}
let api = new ChatGPTAPI({
apiBaseUrl: Config.openAiBaseUrl,
apiKey: Config.apiKey,
debug: false,
completionParams,
fetch: (url, options = {}) => {
const defaultOptions = Config.proxy
? {
agent: proxy(Config.proxy)
}
: {}
const mergedOptions = {
...defaultOptions,
...options
}
return fetch(url, mergedOptions)
},
maxModelTokens
})
const htmlContentSummaryRes = await api.sendMessage(`去除与主体内容无关的部分,从中整理出主体内容并转换成md格式,不需要主观描述性的语言与冗余的空白行。${text}`, { completionParams })
let htmlContentSummary = htmlContentSummaryRes.text
return `this is the main content of website:\n ${htmlContentSummary}`
} catch (err) {
return `failed to visit the website, error: ${err.toString()}`
}
Expand Down

0 comments on commit 8bdf9a3

Please sign in to comment.