This commit is contained in:
@@ -799,23 +799,22 @@ fn build_chat_context(
|
||||
.optional()?;
|
||||
let (title, artist, category, lyrics, notes) = row.ok_or(AppError::NotFound)?;
|
||||
|
||||
let mut sys = String::from(
|
||||
"你是麻薯,一个懂音乐、会乐理、爱聊天的助手。用中文回答,简洁直接,必要时用 markdown。\n\n当前曲目:",
|
||||
);
|
||||
sys.push_str(&format!("《{}》", title));
|
||||
// 仅注入当前曲目上下文,不赋予 LLM 任何角色 / 人格。
|
||||
let mut sys = String::from("Context: 用户正在查看以下曲目。\n");
|
||||
sys.push_str(&format!("Title: {}\n", title));
|
||||
if let Some(a) = artist.as_deref().filter(|s| !s.is_empty()) {
|
||||
sys.push_str(&format!(" — {}", a));
|
||||
sys.push_str(&format!("Artist: {}\n", a));
|
||||
}
|
||||
if let Some(c) = category.as_deref().filter(|s| !s.is_empty()) {
|
||||
sys.push_str(&format!("({})", c));
|
||||
sys.push_str(&format!("Category: {}\n", c));
|
||||
}
|
||||
if let Some(n) = notes.as_deref().filter(|s| !s.is_empty()) {
|
||||
sys.push_str(&format!("\n用户笔记:{}", n));
|
||||
sys.push_str(&format!("User notes: {}\n", n));
|
||||
}
|
||||
if let Some(l) = lyrics.as_deref().filter(|s| !s.is_empty()) {
|
||||
// LRC 太长会爆 prompt,截到 4KB
|
||||
let trimmed = if l.len() > 4096 { &l[..4096] } else { l };
|
||||
sys.push_str(&format!("\n歌词(截断到 4KB):\n{}", trimmed));
|
||||
sys.push_str(&format!("Lyrics (truncated to 4KB):\n{}\n", trimmed));
|
||||
}
|
||||
|
||||
let mut stmt = conn.prepare(
|
||||
|
||||
Reference in New Issue
Block a user