mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 13:57:10 +00:00
Merge branch 'ikechan8370:v2' into v2
This commit is contained in:
commit
d537e8abc6
22 changed files with 1218 additions and 2838 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { exec } from 'child_process'
|
||||
import { Config } from '../utils/config.js'
|
||||
import {
|
||||
formatDuration,
|
||||
|
|
@ -126,6 +127,11 @@ export class ChatgptManagement extends plugin {
|
|||
fnc: 'useClaudeAISolution',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt切换(Gemini|gemini)$',
|
||||
fnc: 'useGeminiSolution',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt切换星火$',
|
||||
fnc: 'useXinghuoBasedSolution',
|
||||
|
|
@ -184,6 +190,11 @@ export class ChatgptManagement extends plugin {
|
|||
fnc: 'setAPIKey',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt设置(Gemini|gemini)(Key|key)$',
|
||||
fnc: 'setGeminiKey',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt设置(API|api)设定$',
|
||||
fnc: 'setAPIPromptPrefix',
|
||||
|
|
@ -319,6 +330,11 @@ export class ChatgptManagement extends plugin {
|
|||
reg: '^#chatgpt设置星火模型$',
|
||||
fnc: 'setXinghuoModel',
|
||||
permission: 'master'
|
||||
},
|
||||
{
|
||||
reg: '^#chatgpt修补Gemini$',
|
||||
fnc: 'patchGemini',
|
||||
permission: 'master'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
|
@ -914,6 +930,16 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
}
|
||||
}
|
||||
|
||||
async useGeminiSolution () {
|
||||
let use = await redis.get('CHATGPT:USE')
|
||||
if (use !== 'gemini') {
|
||||
await redis.set('CHATGPT:USE', 'gemini')
|
||||
await this.reply('已切换到基于Google Gemini的解决方案')
|
||||
} else {
|
||||
await this.reply('当前已经是gemini模式了')
|
||||
}
|
||||
}
|
||||
|
||||
async useXinghuoBasedSolution () {
|
||||
let use = await redis.get('CHATGPT:USE')
|
||||
if (use !== 'xh') {
|
||||
|
|
@ -944,6 +970,57 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
}
|
||||
}
|
||||
|
||||
async patchGemini () {
|
||||
const _path = process.cwd()
|
||||
let packageJson = fs.readFileSync(`${_path}/package.json`)
|
||||
packageJson = JSON.parse(String(packageJson))
|
||||
const packageName = '@google/generative-ai@0.1.1'
|
||||
const patchLoc = 'plugins/chatgpt-plugin/patches/@google__generative-ai@0.1.1.patch'
|
||||
if (!packageJson.pnpm) {
|
||||
packageJson.pnpm = {
|
||||
patchedDependencies: {
|
||||
[packageName]: patchLoc
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (packageJson.pnpm.patchedDependencies) {
|
||||
packageJson.pnpm.patchedDependencies[packageName] = patchLoc
|
||||
} else {
|
||||
packageJson.pnpm.patchedDependencies = {
|
||||
[packageName]: patchLoc
|
||||
}
|
||||
}
|
||||
}
|
||||
fs.writeFileSync(`${_path}/package.json`, JSON.stringify(packageJson, null, 2))
|
||||
|
||||
function execSync (cmd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
exec(cmd, (error, stdout, stderr) => {
|
||||
resolve({ error, stdout, stderr })
|
||||
})
|
||||
})
|
||||
}
|
||||
async function checkPnpm () {
|
||||
let npm = 'npm'
|
||||
let ret = await execSync('pnpm -v')
|
||||
if (ret.stdout) npm = 'pnpm'
|
||||
return npm
|
||||
}
|
||||
let npmv = await checkPnpm()
|
||||
if (npmv === 'pnpm') {
|
||||
exec('pnpm i', {}, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
logger.error(error)
|
||||
logger.error(stderr)
|
||||
logger.info(stdout)
|
||||
this.e.reply('失败,请查看日志手动操作')
|
||||
} else {
|
||||
this.e.reply('修补完成,请手动重启')
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async useQwenSolution () {
|
||||
let use = await redis.get('CHATGPT:USE')
|
||||
if (use !== 'qwen') {
|
||||
|
|
@ -1160,6 +1237,21 @@ azure语音:Azure 语音是微软 Azure 平台提供的一项语音服务,
|
|||
this.finish('saveAPIKey')
|
||||
}
|
||||
|
||||
async setGeminiKey (e) {
|
||||
this.setContext('saveGeminiKey')
|
||||
await this.reply('请发送Gemini API Key.获取地址:https://makersuite.google.com/app/apikey', true)
|
||||
return false
|
||||
}
|
||||
|
||||
async saveGeminiKey () {
|
||||
if (!this.e.msg) return
|
||||
let token = this.e.msg
|
||||
// todo
|
||||
Config.geminiKey = token
|
||||
await this.reply('请发送Gemini API Key设置成功', true)
|
||||
this.finish('saveGeminiKey')
|
||||
}
|
||||
|
||||
async setXinghuoToken () {
|
||||
this.setContext('saveXinghuoToken')
|
||||
await this.reply('请发送星火的ssoSessionId', true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue