fix: claude.ai

This commit is contained in:
ikechan8370 2024-03-05 12:21:12 +08:00
parent ae7d86720d
commit c3b30923c7
6 changed files with 45 additions and 14 deletions

View file

@ -1,4 +1,5 @@
import plugin from '../../../lib/plugins/plugin.js'
import {Config} from "../utils/config.js";
const PLUGIN_CHAT = 'ChatGpt 对话'
const PLUGIN_MANAGEMENT = 'ChatGPT-Plugin 管理'
@ -52,8 +53,8 @@ export class ChatGPTButtonHandler extends plugin {
}
async btnHandler (e, options, reject) {
logger.mark('[chatgpt按钮处理器]')
if (e.adapter !== 'shamrock' && (!segment.button || segment.button(1)?.content !== 1)) {
// logger.mark('[chatgpt按钮处理器]')
if (!Config.enableMd || (e.adapter !== 'shamrock' && (!segment.button || segment.button(1)?.content !== 1))) {
return null
}
const fnc = e.logFnc
@ -192,8 +193,8 @@ export class ChatGPTButtonHandler extends plugin {
{
buttons: [
createButtonBase('恢复本群回复', '#chatgpt本群张嘴', false),
createButtonBase('开启上下文', '#chatgpt打开上下文'),
createButtonBase('关闭上下文 ', '#chatgpt关闭上下文')
createButtonBase('开启上下文', '#打开群聊上下文'),
createButtonBase('关闭上下文 ', '#关闭群聊上下文')
]
},

View file

@ -173,7 +173,7 @@ export class chatgpt extends plugin {
},
{
/** 命令正则匹配 */
reg: '^#claude2[sS]*',
reg: '^#claude(2|3|.ai)[sS]*',
/** 执行方法 */
fnc: 'claude2'
},
@ -907,7 +907,7 @@ export class chatgpt extends plugin {
* #chatgpt
*/
async chatgpt (e) {
let msg = (Version.isTrss || e.adapter === 'shamrock') ? e.msg : e.raw_message
let msg = e.msg
let prompt
if (this.toggleMode === 'at') {
if (!msg || e.msg?.startsWith('#')) {
@ -959,7 +959,7 @@ export class chatgpt extends plugin {
}
return false
}
prompt = _.replace(e.raw_message.trimStart(), '#chat', '').trim()
prompt = _.replace(e.msg.trimStart(), '#chat', '').trim()
if (prompt.length === 0) {
return false
}
@ -1506,7 +1506,7 @@ export class chatgpt extends plugin {
}
async claude2 (e) {
return await this.otherMode(e, 'claude2')
return await this.otherMode(e, 'claude2', /^#claude(2|3|.ai)/)
}
async claude (e) {
@ -2798,6 +2798,13 @@ export class chatgpt extends plugin {
return await this.chatGPTApi.sendMessage(prompt, sendMessageOption)
}
/**
* 其他模式
* @param e
* @param mode
* @param {string|RegExp} pattern
* @returns {Promise<boolean>}
*/
async otherMode (e, mode, pattern = `#${mode}`) {
if (!Config.allowOtherMode) {
return false
@ -2809,7 +2816,7 @@ export class chatgpt extends plugin {
}
return false
}
let prompt = _.replace(e.raw_message.trimStart(), pattern, '').trim()
let prompt = _.replace(e.msg.trimStart(), pattern, '').trim()
if (prompt.length === 0) {
return false
}

View file

@ -1,5 +1,6 @@
import plugin from '../../../lib/plugins/plugin.js'
import cfg from '../../../lib/config/config.js'
import {Config} from '../utils/config.js'
export class ChatGPTMarkdownHandler extends plugin {
constructor () {
super({
@ -15,11 +16,25 @@ export class ChatGPTMarkdownHandler extends plugin {
async mdHandler (e, options, reject) {
const { content, prompt, use } = options
if (cfg.bot.global_md || e.adapter === 'shamrock') {
let md = `> ${prompt}\n\n---\n${content}\n\n---\n*当前模式:${use}*`
return md
if (Config.enableMd && (e.adapter === 'shamrock')) {
let mode = transUse(use)
return `> ${prompt}\n\n---\n${content}\n\n---\n*当前模式:${mode}*`
} else {
return content
}
}
}
function transUse (use) {
let useMap = {
api: Config.model,
bing: '必应(Copilot)',
gemini: Config.geminiModel,
xh: '讯飞星火',
qwen: '同义千问',
claude2: 'Claude 3 Sonnet',
glm4: 'ChatGLM4',
chat3: 'ChatGPT官网'
}
return useMap[use] || use
}

View file

@ -57,6 +57,12 @@ export function supportGuoba () {
bottomHelpMessage: '将输出更多调试信息,如果不希望控制台刷屏的话,可以关闭',
component: 'Switch'
},
{
field: 'enableMd',
label: 'QQ开启markdown',
bottomHelpMessage: 'qq的第三方md非QQBot。需要适配器实现segment.markdown和segment.button方可使用否则不建议开启会造成各种错误。默认关闭',
component: 'Switch'
},
{
field: 'translateSource',
label: '翻译来源',

View file

@ -132,7 +132,8 @@ export class ClaudeAIClient {
let body = {
attachments,
files: [],
model: 'claude-2.1',
// 官方更新后这里没有传值了
// model: 'claude-2.1',
prompt: text,
timezone: 'Asia/Hong_Kong'
}

View file

@ -179,6 +179,7 @@ const defaultConfig = {
sunoSessToken: '',
sunoClientToken: '',
translateSource: 'openai',
enableMd: false, // 第三方md非QQBot。需要适配器实现segment.markdown和segment.button方可使用否则不建议开启会造成各种错误
version: 'v2.7.10'
}
const _path = process.cwd()