mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
后台和工具箱适配、添加群消息合并、优化bing绘图、修复引用空标题 (#530)
* 修复后台API反代地址未能正确显示的问题 * 更新渲染页面配置 * 添加个人聊天模式配置 * 将用户数据获取改到common中 * 修复错误的渲染页面参数 * 修复bug * 添加Live2D * 修复渲染页面错误 * 修复渲染传入值 * 更新渲染 * 修复图表渲染bug * 调整live2d模型大小 * 修复live2d无法关闭问题 * 修复错误的传值 * 修复ai命名 * 更新渲染 * 添加用户独立设定 * 更新渲染配置适配个人设置 * 修复合并导致的渲染文件异常删除 * 修复用户数据缺失问题 * 修复旧版本数据缺失问题 * 修复bing参数不存在问题,兼容miao的截图 * 修复受限token重试时不被排除的问题 * 修复个人模式下结束对话的模式错误 * 更新渲染页面,将预览版转为正式版 * 修复传统渲染无法调用截图功能的问题 * 文字模式也进行一次缓存 * 更新README * Update README.md * 更新渲染 * 更新渲染页面 * 添加版本信息 * 遗漏参数 * 丢失引用 * 补充路由 * 添加云转码功能 * 判断node-silk是否正常合成 * 云转码提示 * 修复图片渲染出错 * 云转码支持发送Buffer * 添加云转码模式支持 * 更新描述 * 更新后台渲染页面 * 更新配置 * 更新渲染页面 * 添加云渲染 * 修复错误的接口调用 * 修复遗漏的数据转换 * 修复获取的图片数据异常问题 * 更新后台配置 * 更新渲染页面 * 修复云渲染访问地址错误 * 更新渲染页面 * 修复遗漏的模型文件 * 修复live2d问题 * 更新live2d以及相关配置 * 修复遗漏的数据参数 * 修复新live2d情况下云渲染错误的问题 * 适配云渲染1.1.2等待参数 * 添加云服务api检查 * 更新渲染页面 * 添加live2d加载检测 * 修复错误的属性判断 * 添加云渲染DPR * 更新sydney支持内容生成 * 修改文件模式语音转码接收模式 * 添加云转码时recordUrl检查 * 更新后台配置项 * 修复错误的文本描述 * 更新后台页面 * 添加全局对话模式设置,更新后台面板 * 添加第三方渲染服务适配 * 修复第三方服务器live2d加载导致的渲染失败问题 * 修复后台地址无法实时保存的问题 * 添加live2d模型透明度设置 * 合并更新 * 更新渲染页面 * 更新渲染页面 * 使dpr对本地渲染也生效 * 更新渲染页面 * 添加网页截图功能 * 添加后台配置项 * 添加配置导出和导入功能 * 运行通过参数传递用户token * 登录时将token作为参数返回 * 修复错误 * 添加密码修改和用户删除接口 * 修正密码比对 * 修复user错误 * 优化数据保存时的返回值 * 添加系统额外服务检查api * 添加AccessToken配置 * 修复错误的导入提示 * 添加ws连接 * 添加ws用户信息获取 * 修复错误的循环 * 修正ws参数 * 添加群消息获取权限 * 添加用户多端登录支持 * 修复错误的路径引用 * 修复错误的路径引用 * 修复错误 * 修复页面数据获取失败问题 * 修复异常的中断 * 添加配置视图 * 更新配置面板 * 添加用户版本信息 * 更新配置视图 * 修复错误的视图绑定 * 修改视图文件位置,添加mediaLink相关代码 * 修复错误的视图配置绑定 * 更新依赖,添加qq消息组件初始化信息获取 * 修复异常的群名称无法获取问题 * 修改注释 * 撤销对management的错误合并 * 添加Sydney图片识别功能 * 更新配置文件和后台页面 * 修改view配置 * 修复node版本过低导致的FormData无法调用,尝试添加反代 * 国外图片识别不使用反代 * fix: 修复云转码导致的语音重复发送问题 * fix: 修复qq消息可越权获取的问题 * feat: 添加代理post操作 * fix: 修复一些字符串格式的数字导致的配置加载错误 * fix: 修复错误的云服务api网址格式 * fix: 修复错误的云转码接口调用格式 * fix: 修复错误的精度 * 添加配置项适配 * feat: 添加群消息合并功能 * 添加历史记录的消息已读标签 * feat: 添加设定相关接口 * improvement: 在多少绘图失败后尝试使用cn进行绘图 * fix: 修复bing可能存在的无标题引用导致的错误 * fix: 修复绘图获取失败的问题 --------- Co-authored-by: ikechan8370 <geyinchibuaa@gmail.com>
This commit is contained in:
parent
4c26d7781a
commit
7ce058c4a5
23 changed files with 276 additions and 118 deletions
84
apps/chat.js
84
apps/chat.js
|
|
@ -99,8 +99,8 @@ const defaultPropmtPrefix = ', a large language model trained by OpenAI. You ans
|
|||
const newFetch = (url, options = {}) => {
|
||||
const defaultOptions = Config.proxy
|
||||
? {
|
||||
agent: proxy(Config.proxy)
|
||||
}
|
||||
agent: proxy(Config.proxy)
|
||||
}
|
||||
: {}
|
||||
const mergedOptions = {
|
||||
...defaultOptions,
|
||||
|
|
@ -110,7 +110,7 @@ const newFetch = (url, options = {}) => {
|
|||
return fetch(url, mergedOptions)
|
||||
}
|
||||
export class chatgpt extends plugin {
|
||||
constructor () {
|
||||
constructor() {
|
||||
let toggleMode = Config.toggleMode
|
||||
super({
|
||||
/** 功能名称 */
|
||||
|
|
@ -276,7 +276,7 @@ export class chatgpt extends plugin {
|
|||
* @param e
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async getConversations (e) {
|
||||
async getConversations(e) {
|
||||
// todo 根据use返回不同的对话列表
|
||||
let keys = await redis.keys('CHATGPT:CONVERSATIONS:*')
|
||||
if (!keys || keys.length === 0) {
|
||||
|
|
@ -299,7 +299,7 @@ export class chatgpt extends plugin {
|
|||
* @param e
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async destroyConversations (e) {
|
||||
async destroyConversations(e) {
|
||||
const userData = await getUserData(e.user_id)
|
||||
const use = (userData.mode === 'default' ? null : userData.mode) || await redis.get('CHATGPT:USE')
|
||||
await redis.del(`CHATGPT:WRONG_EMOTION:${e.sender.user_id}`)
|
||||
|
|
@ -451,7 +451,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async endAllConversations (e) {
|
||||
async endAllConversations(e) {
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
let deleted = 0
|
||||
switch (use) {
|
||||
|
|
@ -535,7 +535,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply(`结束了${deleted}个用户的对话。`, true)
|
||||
}
|
||||
|
||||
async deleteConversation (e) {
|
||||
async deleteConversation(e) {
|
||||
let ats = e.message.filter(m => m.type === 'at')
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
if (use !== 'api3') {
|
||||
|
|
@ -593,7 +593,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async switch2Picture (e) {
|
||||
async switch2Picture(e) {
|
||||
let userReplySetting = await redis.get(`CHATGPT:USER:${e.sender.user_id}`)
|
||||
if (!userReplySetting) {
|
||||
userReplySetting = getDefaultReplySetting()
|
||||
|
|
@ -606,7 +606,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply('ChatGPT回复已转换为图片模式')
|
||||
}
|
||||
|
||||
async switch2Text (e) {
|
||||
async switch2Text(e) {
|
||||
let userSetting = await getUserReplySetting(this.e)
|
||||
userSetting.usePicture = false
|
||||
userSetting.useTTS = false
|
||||
|
|
@ -614,7 +614,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply('ChatGPT回复已转换为文字模式')
|
||||
}
|
||||
|
||||
async switch2Audio (e) {
|
||||
async switch2Audio(e) {
|
||||
switch (Config.ttsMode) {
|
||||
case 'vits-uma-genshin-honkai':
|
||||
if (!Config.ttsSpace) {
|
||||
|
|
@ -642,7 +642,7 @@ export class chatgpt extends plugin {
|
|||
await this.reply('ChatGPT回复已转换为语音模式')
|
||||
}
|
||||
|
||||
async switchTTSSource (e) {
|
||||
async switchTTSSource(e) {
|
||||
let target = e.msg.replace(/^#chatgpt语音换源/, '')
|
||||
switch (target.trim()) {
|
||||
case '1': {
|
||||
|
|
@ -665,7 +665,7 @@ export class chatgpt extends plugin {
|
|||
await e.reply('语音转换源已切换为' + Config.ttsMode)
|
||||
}
|
||||
|
||||
async setDefaultRole (e) {
|
||||
async setDefaultRole(e) {
|
||||
if (Config.ttsMode === 'vits-uma-genshin-honkai' && !Config.ttsSpace) {
|
||||
await this.reply('您没有配置vits-uma-genshin-honkai API,请前往后台管理或锅巴面板进行配置')
|
||||
return
|
||||
|
|
@ -749,7 +749,7 @@ export class chatgpt extends plugin {
|
|||
/**
|
||||
* #chatgpt
|
||||
*/
|
||||
async chatgpt (e) {
|
||||
async chatgpt(e) {
|
||||
let prompt
|
||||
if (this.toggleMode === 'at') {
|
||||
if (!e.raw_message || e.msg?.startsWith('#')) {
|
||||
|
|
@ -815,7 +815,7 @@ export class chatgpt extends plugin {
|
|||
await this.abstractChat(e, prompt, use)
|
||||
}
|
||||
|
||||
async abstractChat (e, prompt, use) {
|
||||
async abstractChat(e, prompt, use) {
|
||||
// 关闭私聊通道后不回复
|
||||
if (!e.isMaster && e.isPrivate && !Config.enablePrivateChat) {
|
||||
return false
|
||||
|
|
@ -961,7 +961,7 @@ export class chatgpt extends plugin {
|
|||
let key
|
||||
if (use === 'api3') {
|
||||
// api3 支持对话穿插,因此不按照qq号来进行判断了
|
||||
let conversationId = await redis.get(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`)
|
||||
let conversationId = await redis.get(`CHATGPT:QQ_CONVERSATION:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`)
|
||||
if (conversationId) {
|
||||
let lastMessageId = await redis.get(`CHATGPT:CONVERSATION_LAST_MESSAGE_ID:${conversationId}`)
|
||||
if (!lastMessageId) {
|
||||
|
|
@ -986,23 +986,23 @@ export class chatgpt extends plugin {
|
|||
} else if (use !== 'poe' && use !== 'claude') {
|
||||
switch (use) {
|
||||
case 'api': {
|
||||
key = `CHATGPT:CONVERSATIONS:${e.sender.user_id}`
|
||||
key = `CHATGPT:CONVERSATIONS:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`
|
||||
break
|
||||
}
|
||||
case 'bing': {
|
||||
key = `CHATGPT:CONVERSATIONS_BING:${e.sender.user_id}`
|
||||
key = `CHATGPT:CONVERSATIONS_BING:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`
|
||||
break
|
||||
}
|
||||
case 'chatglm': {
|
||||
key = `CHATGPT:CONVERSATIONS_CHATGLM:${e.sender.user_id}`
|
||||
key = `CHATGPT:CONVERSATIONS_CHATGLM:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`
|
||||
break
|
||||
}
|
||||
case 'browser': {
|
||||
key = `CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}`
|
||||
key = `CHATGPT:CONVERSATIONS_BROWSER:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`
|
||||
break
|
||||
}
|
||||
case 'xh': {
|
||||
key = `CHATGPT:CONVERSATIONS_XH:${e.sender.user_id}`
|
||||
key = `CHATGPT:CONVERSATIONS_XH:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
@ -1283,7 +1283,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async chatgpt1 (e) {
|
||||
async chatgpt1(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1302,7 +1302,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async chatgpt3 (e) {
|
||||
async chatgpt3(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1321,7 +1321,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async chatglm (e) {
|
||||
async chatglm(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1340,7 +1340,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async bing (e) {
|
||||
async bing(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1359,7 +1359,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async claude (e) {
|
||||
async claude(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1378,7 +1378,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async xh (e) {
|
||||
async xh(e) {
|
||||
if (!Config.allowOtherMode) {
|
||||
return false
|
||||
}
|
||||
|
|
@ -1397,7 +1397,7 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async cacheContent (e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
async cacheContent(e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
let cacheData = { file: '', cacheUrl: Config.cacheUrl, status: '' }
|
||||
cacheData.file = randomString()
|
||||
const cacheresOption = {
|
||||
|
|
@ -1437,7 +1437,7 @@ export class chatgpt extends plugin {
|
|||
return cacheData
|
||||
}
|
||||
|
||||
async renderImage (e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
async renderImage(e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
|
||||
let cacheData = await this.cacheContent(e, use, content, prompt, quote, mood, suggest, imgUrls)
|
||||
const template = use !== 'bing' ? 'content/ChatGPT/index' : 'content/Bing/index'
|
||||
if (!Config.oldview) {
|
||||
|
|
@ -1485,7 +1485,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async sendMessage (prompt, conversation = {}, use, e) {
|
||||
async sendMessage(prompt, conversation = {}, use, e) {
|
||||
if (!conversation) {
|
||||
conversation = {
|
||||
timeoutMs: Config.defaultTimeoutMs
|
||||
|
|
@ -1641,7 +1641,7 @@ export class chatgpt extends plugin {
|
|||
response.quote = []
|
||||
for (let quote of response.details.sourceAttributions) {
|
||||
response.quote.push({
|
||||
text: quote.providerDisplayName,
|
||||
text: quote.providerDisplayName || '',
|
||||
url: quote.seeMoreUrl,
|
||||
imageLink: quote.imageLink || ''
|
||||
})
|
||||
|
|
@ -1782,7 +1782,7 @@ export class chatgpt extends plugin {
|
|||
await redis.set(`CHATGPT:CONVERSATION_LAST_MESSAGE_PROMPT:${sendMessageResult.conversationId}`, prompt)
|
||||
// 更新最后一条messageId
|
||||
await redis.set(`CHATGPT:CONVERSATION_LAST_MESSAGE_ID:${sendMessageResult.conversationId}`, sendMessageResult.id)
|
||||
await redis.set(`CHATGPT:QQ_CONVERSATION:${e.sender.user_id}`, sendMessageResult.conversationId)
|
||||
await redis.set(`CHATGPT:QQ_CONVERSATION:${(e.isGroup && Config.groupMerge) ? e.group_id.toString() : e.sender.user_id}`, sendMessageResult.conversationId)
|
||||
if (!conversation.conversationId) {
|
||||
// 如果是对话的创建者
|
||||
await redis.set(`CHATGPT:CONVERSATION_CREATER_ID:${sendMessageResult.conversationId}`, e.sender.user_id)
|
||||
|
|
@ -2085,7 +2085,7 @@ export class chatgpt extends plugin {
|
|||
} else {
|
||||
tools.push(new SerpImageTool())
|
||||
tools.push(...[new SearchVideoTool(),
|
||||
new SendVideoTool()])
|
||||
new SendVideoTool()])
|
||||
}
|
||||
let funcMap = {}
|
||||
let fullFuncMap = {}
|
||||
|
|
@ -2168,7 +2168,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async newClaudeConversation (e) {
|
||||
async newClaudeConversation(e) {
|
||||
let presetName = e.msg.replace(/^#claude开启新对话/, '').trim()
|
||||
let client = new SlackClaudeClient({
|
||||
slackUserToken: Config.slackUserToken,
|
||||
|
|
@ -2206,12 +2206,12 @@ export class chatgpt extends plugin {
|
|||
return true
|
||||
}
|
||||
|
||||
async emptyQueue (e) {
|
||||
async emptyQueue(e) {
|
||||
await redis.lTrim('CHATGPT:CHAT_QUEUE', 1, 0)
|
||||
await this.reply('已清空当前等待队列')
|
||||
}
|
||||
|
||||
async removeQueueFirst (e) {
|
||||
async removeQueueFirst(e) {
|
||||
let uid = await redis.lPop('CHATGPT:CHAT_QUEUE', 0)
|
||||
if (!uid) {
|
||||
await this.reply('当前等待队列为空')
|
||||
|
|
@ -2220,7 +2220,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async getAllConversations (e) {
|
||||
async getAllConversations(e) {
|
||||
const use = await redis.get('CHATGPT:USE')
|
||||
if (use === 'api3') {
|
||||
let conversations = await getConversations(e.sender.user_id, newFetch)
|
||||
|
|
@ -2241,7 +2241,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async joinConversation (e) {
|
||||
async joinConversation(e) {
|
||||
let ats = e.message.filter(m => m.type === 'at')
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
// if (use !== 'api3') {
|
||||
|
|
@ -2272,7 +2272,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async attachConversation (e) {
|
||||
async attachConversation(e) {
|
||||
const use = await redis.get('CHATGPT:USE')
|
||||
if (use !== 'api3') {
|
||||
await this.reply('该功能目前仅支持API3模式')
|
||||
|
|
@ -2289,7 +2289,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async totalAvailable (e) {
|
||||
async totalAvailable(e) {
|
||||
// 查询OpenAI API剩余试用额度
|
||||
let subscriptionRes = await newFetch(`${Config.openAiBaseUrl}/dashboard/billing/subscription`, {
|
||||
method: 'GET',
|
||||
|
|
@ -2298,7 +2298,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
})
|
||||
|
||||
function getDates () {
|
||||
function getDates() {
|
||||
const today = new Date()
|
||||
const tomorrow = new Date(today)
|
||||
tomorrow.setDate(tomorrow.getDate() + 1)
|
||||
|
|
@ -2335,7 +2335,7 @@ export class chatgpt extends plugin {
|
|||
* @param prompt 问题
|
||||
* @param conversation 对话
|
||||
*/
|
||||
async chatgptBrowserBased (prompt, conversation) {
|
||||
async chatgptBrowserBased(prompt, conversation) {
|
||||
let option = { markdown: true }
|
||||
if (Config['2captchaToken']) {
|
||||
option.captchaToken = Config['2captchaToken']
|
||||
|
|
@ -2394,7 +2394,7 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
|
||||
async function getAvailableBingToken (conversation, throttled = []) {
|
||||
async function getAvailableBingToken(conversation, throttled = []) {
|
||||
let allThrottled = false
|
||||
if (!await redis.get('CHATGPT:BING_TOKENS')) {
|
||||
return {
|
||||
|
|
|
|||
|
|
@ -217,6 +217,12 @@ export function supportGuoba () {
|
|||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
field: 'groupMerge',
|
||||
label: '群组消息合并',
|
||||
bottomHelpMessage: '开启后,群聊消息将被视为同一对话',
|
||||
component: 'Switch'
|
||||
},
|
||||
{
|
||||
field: 'allowOtherMode',
|
||||
label: '允许其他模式',
|
||||
|
|
|
|||
|
|
@ -29,6 +29,11 @@
|
|||
"model": "redisConfig",
|
||||
"data": "turnConfirm"
|
||||
},
|
||||
{
|
||||
"type": "check",
|
||||
"label": "群组消息合并",
|
||||
"data": "groupMerge"
|
||||
},
|
||||
{
|
||||
"type": "check",
|
||||
"label": "新版帮助",
|
||||
|
|
@ -639,6 +644,12 @@
|
|||
"type": "check",
|
||||
"label": "允许生成图像等内容",
|
||||
"data": "enableGenerateContents"
|
||||
},
|
||||
{
|
||||
"type": "url",
|
||||
"label": "必应验证码pass服务",
|
||||
"placeholder": "必应出验证码会自动用该服务绕过",
|
||||
"data": "bingCaptchaOneShotUrl"
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { getPublicIP, getUserData, getMasterQQ, randomString } from '../utils/co
|
|||
|
||||
import webRoute from './modules/web_route.js'
|
||||
import webUser from './modules/user.js'
|
||||
import webPrompt from './modules/prompts.js'
|
||||
import SettingView from './modules/setting_view.js'
|
||||
|
||||
const __dirname = path.resolve()
|
||||
|
|
@ -82,6 +83,7 @@ await server.register(fastifyCookie)
|
|||
await server.register(webRoute)
|
||||
await server.register(webUser)
|
||||
await server.register(SettingView)
|
||||
await server.register(webPrompt)
|
||||
|
||||
// 无法访问端口的情况下创建与media的通讯
|
||||
async function mediaLink() {
|
||||
|
|
@ -390,7 +392,8 @@ export async function createServer() {
|
|||
rand: e.rand,
|
||||
message: e.message,
|
||||
user_name: e.sender.nickname,
|
||||
}
|
||||
},
|
||||
read: true
|
||||
}
|
||||
await connection.socket.send(JSON.stringify(messageData))
|
||||
})
|
||||
|
|
|
|||
129
server/modules/prompts.js
Normal file
129
server/modules/prompts.js
Normal file
|
|
@ -0,0 +1,129 @@
|
|||
import { UserInfo } from './user_data.js'
|
||||
import { Config } from '../../utils/config.js'
|
||||
import { deleteOnePrompt, getPromptByName, readPrompts, saveOnePrompt } from '../../utils/prompts.js'
|
||||
|
||||
async function Prompt(fastify, options) {
|
||||
// 获取设定列表
|
||||
fastify.post('/getPromptList', async (request, reply) => {
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = UserInfo(token)
|
||||
if (!user) {
|
||||
reply.send({ err: '未登录' })
|
||||
} else if (user.autho === 'admin') {
|
||||
reply.send([
|
||||
{
|
||||
name: 'Sydney默认',
|
||||
content: Config.sydney
|
||||
},
|
||||
{
|
||||
name: 'API默认',
|
||||
content: Config.promptPrefixOverride
|
||||
},
|
||||
...readPrompts()
|
||||
])
|
||||
} else {
|
||||
reply.send({ err: '权限不足' })
|
||||
}
|
||||
return reply
|
||||
})
|
||||
// 添加设定
|
||||
fastify.post('/addPrompt', async (request, reply) => {
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = UserInfo(token)
|
||||
if (!user) {
|
||||
reply.send({ err: '未登录' })
|
||||
} else if (user.autho === 'admin') {
|
||||
const body = request.body || {}
|
||||
if (body.prompt && body.content) {
|
||||
saveOnePrompt(body.prompt, body.content)
|
||||
reply.send({ state: true })
|
||||
} else {
|
||||
reply.send({ err: '参数不足' })
|
||||
}
|
||||
} else {
|
||||
reply.send({ err: '权限不足' })
|
||||
}
|
||||
return reply
|
||||
})
|
||||
// 删除设定
|
||||
fastify.post('/deletePrompt', async (request, reply) => {
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = UserInfo(token)
|
||||
if (!user) {
|
||||
reply.send({ err: '未登录' })
|
||||
} else if (user.autho === 'admin') {
|
||||
const body = request.body || {}
|
||||
if (body.prompt) {
|
||||
deleteOnePrompt(body.prompt)
|
||||
reply.send({ state: true })
|
||||
} else {
|
||||
reply.send({ err: '参数不足' })
|
||||
}
|
||||
} else {
|
||||
reply.send({ err: '权限不足' })
|
||||
}
|
||||
return reply
|
||||
})
|
||||
// 使用设定
|
||||
fastify.post('/usePrompt', async (request, reply) => {
|
||||
const token = request.cookies.token || request.body?.token || 'unknown'
|
||||
let user = UserInfo(token)
|
||||
if (!user) {
|
||||
reply.send({ err: '未登录' })
|
||||
} else if (user.autho === 'admin') {
|
||||
const body = request.body || {}
|
||||
if (body.prompt) {
|
||||
let promptName = body.prompt
|
||||
let prompt = getPromptByName(promptName)
|
||||
let use = await redis.get('CHATGPT:USE') || 'api'
|
||||
if (!prompt) {
|
||||
if (promptName === 'API默认') {
|
||||
prompt = {
|
||||
name: 'API默认',
|
||||
content: Config.promptPrefixOverride
|
||||
}
|
||||
} else if (promptName === 'Sydney默认') {
|
||||
prompt = {
|
||||
name: 'Sydney默认',
|
||||
content: Config.sydney
|
||||
}
|
||||
} else {
|
||||
prompt = false
|
||||
reply.send({ state: false, use: use, error: '未找到设定' })
|
||||
}
|
||||
}
|
||||
if (use.toLowerCase() === 'bing') {
|
||||
if (Config.toneStyle === 'Custom') {
|
||||
use = 'Custom'
|
||||
}
|
||||
}
|
||||
const keyMap = {
|
||||
api: 'promptPrefixOverride',
|
||||
Custom: 'sydney',
|
||||
claude: 'slackClaudeGlobalPreset'
|
||||
}
|
||||
if (prompt) {
|
||||
if (keyMap[use]) {
|
||||
if (Config.ttsMode === 'azure') {
|
||||
Config[keyMap[use]] = prompt.content + '\n' + await AzureTTS.getEmotionPrompt(e)
|
||||
logger.warn(Config[keyMap[use]])
|
||||
} else {
|
||||
Config[keyMap[use]] = prompt.content
|
||||
}
|
||||
await redis.set(`CHATGPT:PROMPT_USE_${use}`, promptName)
|
||||
reply.send({ state: true, use: use })
|
||||
} else {
|
||||
reply.send({ state: false, use: use, error: '当前模式不支持设定修改' })
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reply.send({ err: '参数不足' })
|
||||
}
|
||||
} else {
|
||||
reply.send({ err: '权限不足' })
|
||||
}
|
||||
return reply
|
||||
})
|
||||
|
||||
}
|
||||
export default Prompt
|
||||
|
|
@ -17,4 +17,4 @@
|
|||
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
-->
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="shortcut icon" href="/favicon.ico"/><link rel="apple-touch-icon" sizes="76x76" href="/apple-icon.png"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css"/><script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.6.3/mermaid.min.js"></script><script src="/live2d/live2dcubismcore.min.js"></script><title>ChatGPT-Plugin</title><script defer="defer" type="module" src="/js/chunk-vendors.6ec7d91a.js"></script><script defer="defer" type="module" src="/js/app.d2798a4f.js"></script><link href="/css/chunk-vendors.0ede84b4.css" rel="stylesheet"><link href="/css/app.883f3d58.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.85a486b0.js" nomodule></script><script defer="defer" src="/js/app-legacy.99564aa8.js" nomodule></script></head><body class="text-blueGray-700 antialiased"><noscript><strong>We're sorry but vue-notus doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="shortcut icon" href="/favicon.ico"/><link rel="apple-touch-icon" sizes="76x76" href="/apple-icon.png"/><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css"/><script src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mermaid/8.6.3/mermaid.min.js"></script><script src="/live2d/live2dcubismcore.min.js"></script><title>ChatGPT-Plugin</title><script defer="defer" type="module" src="/js/chunk-vendors.b7a1d693.js"></script><script defer="defer" type="module" src="/js/app.9eedf06d.js"></script><link href="/css/chunk-vendors.0ede84b4.css" rel="stylesheet"><link href="/css/app.a18150c7.css" rel="stylesheet"><script defer="defer" src="/js/chunk-vendors-legacy.a05bfee7.js" nomodule></script><script defer="defer" src="/js/app-legacy.093fe9e5.js" nomodule></script></head><body class="text-blueGray-700 antialiased"><noscript><strong>We're sorry but vue-notus doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div></body></html>
|
||||
21
server/static/js/app-legacy.093fe9e5.js
Normal file
21
server/static/js/app-legacy.093fe9e5.js
Normal file
File diff suppressed because one or more lines are too long
1
server/static/js/app-legacy.093fe9e5.js.map
Normal file
1
server/static/js/app-legacy.093fe9e5.js.map
Normal file
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
21
server/static/js/app.9eedf06d.js
Normal file
21
server/static/js/app.9eedf06d.js
Normal file
File diff suppressed because one or more lines are too long
1
server/static/js/app.9eedf06d.js.map
Normal file
1
server/static/js/app.9eedf06d.js.map
Normal file
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
File diff suppressed because one or more lines are too long
1
server/static/js/chunk-vendors-legacy.a05bfee7.js.map
Normal file
1
server/static/js/chunk-vendors-legacy.a05bfee7.js.map
Normal file
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
|
|
@ -11,7 +11,7 @@ if (Config.proxy) {
|
|||
}
|
||||
}
|
||||
export default class BingDrawClient {
|
||||
constructor (opts) {
|
||||
constructor(opts) {
|
||||
this.opts = opts
|
||||
if (Config.proxy && !Config.sydneyForceUseReverse) {
|
||||
// 如果设置代理,走代理
|
||||
|
|
@ -19,7 +19,7 @@ export default class BingDrawClient {
|
|||
}
|
||||
}
|
||||
|
||||
async getImages (prompt, e) {
|
||||
async getImages(prompt, e) {
|
||||
let urlEncodedPrompt = encodeURIComponent(prompt)
|
||||
let url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=4&FORM=GENCRE`
|
||||
// let d = Math.ceil(Math.random() * 255)
|
||||
|
|
@ -65,14 +65,14 @@ export default class BingDrawClient {
|
|||
let retry = 5
|
||||
let response
|
||||
while (!success && retry >= 0) {
|
||||
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST', credentials: 'include' }))
|
||||
let res = await response.text()
|
||||
if (res.toLowerCase().indexOf('this prompt has been blocked') > -1) {
|
||||
throw new Error('Your prompt has been blocked by Bing. Try to change any bad words and try again.')
|
||||
}
|
||||
if (response.status !== 302) {
|
||||
url = `${this.opts.baseUrl}/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
||||
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST' }))
|
||||
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST', credentials: 'include' }))
|
||||
}
|
||||
if (response.status === 302) {
|
||||
success = true
|
||||
|
|
@ -82,7 +82,15 @@ export default class BingDrawClient {
|
|||
}
|
||||
}
|
||||
if (!success) {
|
||||
throw new Error('绘图失败,请检查Bing token和代理/反代配置')
|
||||
//最后尝试使用https://cn.bing.com进行一次绘图
|
||||
logger.info('尝试使用https://cn.bing.com进行绘图')
|
||||
url = `https://cn.bing.com/images/create?q=${urlEncodedPrompt}&rt=3&FORM=GENCRE`
|
||||
fetchOptions.referrer = 'https://cn.bing.com/images/create/'
|
||||
fetchOptions.origin = 'https://cn.bing.com'
|
||||
response = await fetch(url, Object.assign(fetchOptions, { body, redirect: 'manual', method: 'POST', credentials: 'include' }))
|
||||
if (response.status !== 302) {
|
||||
throw new Error('绘图失败,请检查Bing token和代理/反代配置')
|
||||
}
|
||||
}
|
||||
let redirectUrl = response.headers.get('Location').replace('&nfy=1', '')
|
||||
let requestId = redirectUrl.split('id=')[1]
|
||||
|
|
|
|||
|
|
@ -645,7 +645,7 @@ export default class SydneyAIClient {
|
|||
text: replySoFar.join('')
|
||||
}
|
||||
// 获取到图片内容
|
||||
if (message.contentType === 'IMAGE') {
|
||||
if (messages.some(obj => obj.contentType === "IMAGE")) {
|
||||
message.imageTag = messages.filter(m => m.contentType === 'IMAGE').map(m => m.text).join('')
|
||||
}
|
||||
message.text = messages.filter(m => m.author === 'bot' && m.contentType != 'IMAGE').map(m => m.text).join('')
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ const defaultConfig = {
|
|||
ttsAutoFallbackThreshold: 299,
|
||||
conversationPreserveTime: 0,
|
||||
toggleMode: 'at',
|
||||
groupMerge: false,
|
||||
quoteReply: true,
|
||||
showQRCode: true,
|
||||
cacheUrl: 'https://content.alcedogroup.com',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue