mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 05:17:10 +00:00
fix: post processors
This commit is contained in:
parent
20195ecfdf
commit
5add41c982
4 changed files with 138 additions and 42 deletions
51
apps/chat.js
51
apps/chat.js
|
|
@ -2,10 +2,8 @@ import plugin from '../../../lib/plugins/plugin.js'
|
|||
import common from '../../../lib/common/common.js'
|
||||
import _ from 'lodash'
|
||||
import { Config } from '../utils/config.js'
|
||||
import { v4 as uuid } from 'uuid'
|
||||
import AzureTTS from '../utils/tts/microsoft-azure.js'
|
||||
import VoiceVoxTTS from '../utils/tts/voicevox.js'
|
||||
import BingSunoClient from '../utils/BingSuno.js'
|
||||
import {
|
||||
completeJSON,
|
||||
formatDate,
|
||||
|
|
@ -21,8 +19,7 @@ import {
|
|||
makeForwardMsg,
|
||||
randomString,
|
||||
render,
|
||||
renderUrl,
|
||||
extractMarkdownJson
|
||||
renderUrl
|
||||
} from '../utils/common.js'
|
||||
|
||||
import fetch from 'node-fetch'
|
||||
|
|
@ -34,6 +31,7 @@ import XinghuoClient from '../utils/xinghuo/xinghuo.js'
|
|||
import { getProxy } from '../utils/proxy.js'
|
||||
import { generateSuggestedResponse } from '../utils/chat.js'
|
||||
import Core from '../model/core.js'
|
||||
import { collectProcessors } from '../utils/postprocessors/BasicProcessor.js'
|
||||
|
||||
let version = Config.version
|
||||
let proxy = getProxy()
|
||||
|
|
@ -785,45 +783,16 @@ export class chatgpt extends plugin {
|
|||
await redis.set(key, JSON.stringify(previousConversation), Config.conversationPreserveTime > 0 ? { EX: Config.conversationPreserveTime } : {})
|
||||
}
|
||||
}
|
||||
// 处理suno生成
|
||||
if (Config.enableChatSuno) {
|
||||
let client = new BingSunoClient() // 此处使用了bing的suno客户端,后续和本地suno合并
|
||||
const sunoList = extractMarkdownJson(chatMessage.text)
|
||||
if (sunoList.length == 0) {
|
||||
const lyrics = client.extractLyrics(chatMessage.text)
|
||||
if (lyrics !== '') {
|
||||
sunoList.push(
|
||||
{
|
||||
json: { option: 'Suno', tags: client.generateRandomStyle(), title: `${e.sender.nickname}之歌`, lyrics },
|
||||
markdown: null,
|
||||
origin: lyrics
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
for (let suno of sunoList) {
|
||||
if (suno.json.option == 'Suno') {
|
||||
chatMessage.text = chatMessage.text.replace(suno.origin, `歌曲 《${suno.json.title}》`)
|
||||
logger.info(`开始生成歌曲${suno.json.tags}`)
|
||||
redis.set(`CHATGPT:SUNO:${e.sender.user_id}`, 'c', { EX: 30 }).then(() => {
|
||||
try {
|
||||
if (Config.SunoModel == 'local') {
|
||||
// 调用本地Suno配置进行歌曲生成
|
||||
client.getLocalSuno(suno.json, e)
|
||||
} else if (Config.SunoModel == 'api') {
|
||||
// 调用第三方Suno配置进行歌曲生成
|
||||
client.getApiSuno(suno.json, e)
|
||||
}
|
||||
} catch (err) {
|
||||
redis.del(`CHATGPT:SUNO:${e.sender.user_id}`)
|
||||
this.reply('歌曲生成失败:' + err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
let response = chatMessage?.text?.replace('\n\n\n', '\n')
|
||||
let postProcessors = await collectProcessors('post')
|
||||
let thinking = chatMessage.thinking_text
|
||||
for (let processor of postProcessors) {
|
||||
let output = await processor.processInner({
|
||||
text: response, thinking
|
||||
})
|
||||
response = output.text
|
||||
thinking = output.thinking_text
|
||||
}
|
||||
if (handler.has('chatgpt.response.post')) {
|
||||
logger.debug('调用后处理器: chatgpt.response.post')
|
||||
handler.call('chatgpt.response.post', this.e, {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue