Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

优化歌曲消息匹配,适配更多模型支持生成歌曲 #694

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions apps/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -832,13 +832,25 @@ export class chatgpt extends plugin {
}
}
// 处理suno生成
if ((use === 'bing' || use === 'xh' || use === 'gemini') && Config.enableChatSuno) {
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: lyrics },
markdown: null,
origin: lyrics
}
)
}
}
for (let suno of sunoList) {
if (suno.json.option == 'Suno') {
chatMessage.text = chatMessage.text.replace(suno.markdown, `歌曲 《${suno.json.title}》`)
chatMessage.text = chatMessage.text.replace(suno.origin, `歌曲 《${suno.json.title}》`)
logger.info(`开始生成歌曲${suno.json.tags}`)
let client = new BingSunoClient() // 此处使用了bing的suno客户端,后续和本地suno合并
redis.set(`CHATGPT:SUNO:${e.sender.user_id}`, 'c', { EX: 30 }).then(() => {
try {
if (Config.SunoModel == 'local') {
Expand Down
10 changes: 3 additions & 7 deletions model/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,11 +645,9 @@ class Core {
}
promptAddition && (prompt += promptAddition)
option.systemMessage = await handleSystem(e, opts.systemMessage)
/*
if (Config.enableChatSuno) {
option.systemMessage += '如果我要求你生成音乐或写歌,你需要回复适合Suno生成音乐的信息。请使用Verse、Chorus、Bridge、Outro和End等关键字对歌词进行分段,如[Verse]。返回的消息需要使用markdown包裹的JSON格式,结构为```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```。'
option.systemMessage += '如果我要求你生成音乐或写歌,你需要回复适合Suno生成音乐的信息。请使用Verse、Chorus、Bridge、Outro和End等关键字对歌词进行分段,如[Verse 1]。音乐信息需要使用markdown包裹的JSON格式回复给我,结构为```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```。'
}
*/
systemAddition && (option.systemMessage += systemAddition)
opts.completionParams.parameters.tools = Object.keys(funcMap)
.map(k => funcMap[k].function)
Expand Down Expand Up @@ -817,7 +815,7 @@ class Core {
}
}
if (Config.enableChatSuno) {
system += '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 ```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```.'
system += '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 1], The returned message is in JSON format, with a structure of ```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```.'
}
option.system = system
return await client.sendMessage(prompt, option)
Expand All @@ -842,11 +840,9 @@ class Core {
let maxModelTokens = getMaxModelTokens(completionParams.model)
// let system = promptPrefix
let system = await handleSystem(e, promptPrefix, maxModelTokens)
/*
if (Config.enableChatSuno) {
system += '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 ```json{"option": "Suno", "tags": "style", "title": "title of the song", "lyrics": "lyrics"}```.'
system += '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 1], The returned song information needs to be wrapped in JSON format and sent to me in Markdown format. The message structure is ` ` JSON {"option": "Suno", "tags": "style", "title": "title of The Song", "lyrics": "lyrics"} `.'
}
*/
logger.debug(system)
let opts = {
apiBaseUrl: Config.openAiBaseUrl,
Expand Down
Loading