mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
对原始数据进行编辑
This commit is contained in:
parent
f66b4a8548
commit
123e5304a7
2 changed files with 42 additions and 19 deletions
|
|
@ -338,7 +338,7 @@ export default class SydneyAIClient {
|
|||
((Config.enableGroupContext && groupId) ? groupContextTip : '') +
|
||||
((Config.enforceMaster && master) ? masterTip : '') +
|
||||
(Config.sydneyMood ? moodTip : '') +
|
||||
((!Config.enableGenerateSuno && Config.bingSuno != 'bing' && Config.enableGenerateSunoForger) ? 'If I ask you to generate music or write songs, you need to reply with information suitable for Suno to generate music. The returned message is in JSON format, with a structure of {"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}.' : '')
|
||||
((!Config.enableGenerateSuno && Config.bingSuno != 'bing' && Config.enableGenerateSunoForger) ? 'If I ask you to generate music or write songs, you need to reply with information suitable for Suno to generate music. Please use keywords such as Verse, Chorus, Bridge, Outro, and End to segment the lyrics, such as [Verse], The returned message is in JSON format, with a structure of {"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}.' : '')
|
||||
if (!text) {
|
||||
previousMessages = pm
|
||||
} else {
|
||||
|
|
@ -839,9 +839,10 @@ export default class SydneyAIClient {
|
|||
if (Config.enableGenerateSunoForger) {
|
||||
const sunoList = extractMarkdownJson(message.text)
|
||||
for (let suno of sunoList) {
|
||||
if (suno.option == 'Suno') {
|
||||
logger.info(`开始生成歌曲${suno.tags}`)
|
||||
onSunoCreateRequest(suno)
|
||||
if (suno.json.option == 'Suno') {
|
||||
message.text = message.text.replace(suno.markdown, `歌曲 《${suno.json.title}》`)
|
||||
logger.info(`开始生成歌曲${suno.json.tags}`)
|
||||
onSunoCreateRequest(suno.json)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1250,28 +1250,50 @@ function maskString (str) {
|
|||
*/
|
||||
export function extractMarkdownJson(text) {
|
||||
const lines = text.split('\n')
|
||||
const mdJson = []
|
||||
let currentObj = null
|
||||
const mdJsonPairs = []
|
||||
let currentJson = ''
|
||||
let currentMd = ''
|
||||
|
||||
lines.forEach(line => {
|
||||
if (line.startsWith('```json') && !currentObj) {
|
||||
// 开始一个新的JSON对象
|
||||
currentObj = { json: '' }
|
||||
} else if (line.startsWith('```') && currentObj) {
|
||||
// 结束当前的JSON对象
|
||||
if (line.startsWith('```json')) {
|
||||
// 如果已经在一个 JSON 中,先结束当前的 JSON
|
||||
if (currentJson) {
|
||||
try {
|
||||
const parsedJson = JSON.parse(currentJson)
|
||||
mdJsonPairs.push({ json: parsedJson, markdown: currentMd + '```' })
|
||||
} catch (e) {
|
||||
console.error('JSON解析错误:', e)
|
||||
}
|
||||
}
|
||||
// 开始新的 JSON 和 markdown
|
||||
currentJson = ''
|
||||
currentMd = line + '\n'
|
||||
} else if (line.startsWith('```') && currentJson) {
|
||||
// 结束当前的 JSON
|
||||
try {
|
||||
// 尝试将JSON字符串转换为对象
|
||||
currentObj.json = JSON.parse(currentObj.json)
|
||||
mdJson.push(currentObj)
|
||||
currentObj = null
|
||||
const parsedJson = JSON.parse(currentJson)
|
||||
mdJsonPairs.push({ json: parsedJson, markdown: currentMd + line })
|
||||
} catch (e) {
|
||||
console.error('JSON解析错误:', e)
|
||||
}
|
||||
} else if (currentObj) {
|
||||
// 将行添加到当前的JSON对象
|
||||
currentObj.json += line
|
||||
currentJson = ''
|
||||
currentMd = ''
|
||||
} else {
|
||||
// 如果在 JSON 中,继续添加行
|
||||
currentJson += line + (line ? '\n' : '')
|
||||
currentMd += line + '\n'
|
||||
}
|
||||
})
|
||||
|
||||
return mdJson.map(obj => obj.json)
|
||||
// 检查是否有未结束的 JSON
|
||||
if (currentJson) {
|
||||
try {
|
||||
const parsedJson = JSON.parse(currentJson)
|
||||
mdJsonPairs.push({ json: parsedJson, markdown: currentMd + '```' })
|
||||
} catch (e) {
|
||||
console.error('JSON解析错误:', e)
|
||||
}
|
||||
}
|
||||
|
||||
return mdJsonPairs
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue