feat: 添加星火支持(beta)

This commit is contained in:
ikechan8370 2023-05-12 20:11:08 +08:00
parent 76f0328a8e
commit 926f07c8e9
7 changed files with 268 additions and 5 deletions

View file

@ -35,6 +35,7 @@ import { ChatgptManagement } from './management.js'
import { getPromptByName } from '../utils/prompts.js'
import Translate from '../utils/baiduTranslate.js'
import emojiStrip from 'emoji-strip'
import XinghuoClient from "../utils/xinghuo/xinghuo.js";
try {
await import('keyv')
} catch (err) {
@ -115,6 +116,12 @@ export class chatgpt extends plugin {
/** 执行方法 */
fnc: 'claude'
},
{
/** 命令正则匹配 */
reg: '^#xh[sS]*',
/** 执行方法 */
fnc: 'xh'
},
{
/** 命令正则匹配 */
reg: toggleMode === 'at' ? '^[^#][sS]*' : '^#chat[^gpt][sS]*',
@ -239,6 +246,11 @@ export class chatgpt extends plugin {
await e.reply('claude对话已结束')
return
}
if (use === 'xh') {
await redis.del(`CHATGPT:CONVERSATIONS_XH:${e.sender.user_id}`)
await e.reply('星火对话已结束')
return
}
let ats = e.message.filter(m => m.type === 'at')
if (ats.length === 0) {
if (use === 'api3') {
@ -389,6 +401,17 @@ export class chatgpt extends plugin {
}
break
}
case 'xh': {
let cs = await redis.keys('CHATGPT:CONVERSATIONS_XH:*')
for (let i = 0; i < cs.length; i++) {
await redis.del(cs[i])
if (Config.debug) {
logger.info('delete slack conversation of qq: ' + cs[i])
}
deleted++
}
break
}
case 'bing': {
let cs = await redis.keys('CHATGPT:CONVERSATIONS_BING:*')
let we = await redis.keys('CHATGPT:WRONG_EMOTION:*')
@ -929,6 +952,10 @@ export class chatgpt extends plugin {
key = `CHATGPT:CONVERSATIONS_BROWSER:${e.sender.user_id}`
break
}
case 'xh': {
key = `CHATGPT:CONVERSATIONS_XH:${e.sender.user_id}`
break
}
}
let ctime = new Date()
previousConversation = (key ? await redis.get(key) : null) || JSON.stringify({
@ -1351,7 +1378,7 @@ export class chatgpt extends plugin {
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#bing')
logger.mark('艾特别人了,没艾特我,忽略#claude')
}
return false
}
@ -1362,6 +1389,28 @@ export class chatgpt extends plugin {
await this.abstractChat(e, prompt, 'claude')
return true
}
async xh (e) {
if (!e.isMaster && e.isPrivate && !Config.enablePrivateChat) {
// await this.reply('ChatGpt私聊通道已关闭。')
return false
}
if (!Config.allowOtherMode) {
return false
}
let ats = e.message.filter(m => m.type === 'at')
if (!e.atme && ats.length > 0) {
if (Config.debug) {
logger.mark('艾特别人了,没艾特我,忽略#xh')
}
return false
}
let prompt = _.replace(e.raw_message.trimStart(), '#xh', '').trim()
if (prompt.length === 0) {
return false
}
await this.abstractChat(e, prompt, 'xh')
return true
}
async cacheContent (e, use, content, prompt, quote = [], mood = '', suggest = '', imgUrls = []) {
let cacheData = { file: '', cacheUrl: Config.cacheUrl, status: '' }
@ -1744,6 +1793,17 @@ export class chatgpt extends plugin {
text
}
}
case 'xh': {
const ssoSessionId = Config.xinghuoToken
if (!ssoSessionId) {
throw new Error('未绑定星火token请使用#chatgpt设置星火token命令绑定token。获取对话页面的ssoSessionId cookie值')
}
let client = new XinghuoClient({
ssoSessionId
})
let response = await client.sendMessage(prompt, conversation?.conversationId)
return response
}
default: {
let completionParams = {}
if (Config.model) {