mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: move files
This commit is contained in:
parent
d08e9e4102
commit
479028584e
4 changed files with 52 additions and 28 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import plugin from '../../../../lib/plugins/plugin.js'
|
||||
import { Config } from '../../utils/config.js'
|
||||
import plugin from '../../../lib/plugins/plugin.js'
|
||||
import { Config } from '../utils/config.js'
|
||||
|
||||
const PLUGIN_CHAT = 'ChatGpt 对话'
|
||||
const PLUGIN_MANAGEMENT = 'ChatGPT-Plugin 管理'
|
||||
|
|
@ -823,7 +823,9 @@ export class chatgpt extends plugin {
|
|||
}
|
||||
}
|
||||
let response = chatMessage?.text?.replace('\n\n\n', '\n')
|
||||
|
||||
if (handler.has('chatgpt.response.post')) {
|
||||
logger.debug('调用后处理器: chatgpt.response.post')
|
||||
handler.call('chatgpt.response.post', this.e, {
|
||||
content: response,
|
||||
use,
|
||||
|
|
|
|||
48
apps/example_handler.js
Normal file
48
apps/example_handler.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
/**
|
||||
* 示例后处理器。你可以在example下面写一个新的。默认会调用所有此key的处理器
|
||||
*/
|
||||
export class ChatGPTResponsePostHandler extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
name: 'chatgpt文本回复后处理器',
|
||||
priority: -100,
|
||||
namespace: 'chatgpt-plugin',
|
||||
handler: [{
|
||||
key: 'chatgpt.response.post', // key必须是chatgpt.response.post
|
||||
fn: 'postHandler'
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
async postHandler (e, options, reject) {
|
||||
const { content, use, prompt } = options
|
||||
// 你可以在这里处理返回的文本,比如使用自定义的语音api来合成语音
|
||||
// const audio = customTTS(content)
|
||||
// e.reply(segment.record(audio))
|
||||
// 返回值会被忽略
|
||||
const response = await fetch('https://api.fish.audio/v1/tts', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Authorization: 'Bearer 5e614bcc80a34789837fdb0f1269b2c4',
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify({
|
||||
text: content,
|
||||
reference_id: '1aacaeb1b840436391b835fd5513f4c4',
|
||||
format: 'mp3',
|
||||
latency: 'normal'
|
||||
})
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`无法从服务器获取音频数据:${response.statusText}`)
|
||||
}
|
||||
|
||||
const audio = await response.blob()
|
||||
// to Buffer
|
||||
const buffer = await audio.arrayBuffer()
|
||||
e.reply(segment.record(Buffer.from(buffer)))
|
||||
// e.reply(segment.record(audio))
|
||||
}
|
||||
}
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
import plugin from '../../../../lib/plugins/plugin.js'
|
||||
|
||||
/**
|
||||
* 示例后处理器。你可以在example下面写一个新的。默认会调用所有此key的处理器
|
||||
*/
|
||||
export class ChatGPTResponsePostHandler extends plugin {
|
||||
constructor () {
|
||||
super({
|
||||
name: 'chatgpt文本回复后处理器',
|
||||
priority: 999999,
|
||||
namespace: 'chatgpt-plugin',
|
||||
handler: [{
|
||||
key: 'chatgpt.response.post', // key必须是chatgpt.response.post
|
||||
fn: 'postHandler'
|
||||
}]
|
||||
})
|
||||
}
|
||||
|
||||
async postHandler (e, options, reject) {
|
||||
const { content, use, prompt } = options
|
||||
// 你可以在这里处理返回的文本,比如使用自定义的语音api来合成语音
|
||||
// const audio = customTTS(content)
|
||||
// e.reply(segment.audio(audio))
|
||||
// 返回值会被忽略
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue