限制切分提示词中的节点备注

对用户备注清理控制字符和围栏符号并限制长度。
This commit is contained in:
2026-09-11 18:52:59 +08:00
parent cf68b8212d
commit 8d15125f12
@@ -1,6 +1,24 @@
use serde::{Deserialize, Serialize};
use ts_rs::TS;
const MAX_PROMPT_NOTE_CHARS: usize = 512;
fn sanitize_prompt_text(value: &str) -> String {
value
.chars()
.filter_map(|character| {
if character == '`' {
Some('\'')
} else if character.is_control() {
Some(' ')
} else {
Some(character)
}
})
.take(MAX_PROMPT_NOTE_CHARS)
.collect()
}
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, TS)]
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
pub struct SeparationNote {
@@ -10,12 +28,12 @@ pub struct SeparationNote {
impl SeparationNote {
pub fn as_prompt(&self) -> String {
let mut prompt = format!("desc: {}", self.description);
let mut prompt = format!("desc: {}", sanitize_prompt_text(&self.description));
if !self.rework_notes.is_empty() {
prompt.push_str("\nprevious rework notes:");
for note in &self.rework_notes {
prompt.push_str("\n- ");
prompt.push_str(note);
prompt.push_str(&sanitize_prompt_text(note));
}
}
prompt