限制并清理视觉绑定提示备注
为节点描述和返工备注增加长度上限并移除控制字符、代码围栏字符。
This commit is contained in:
+24
-2
@@ -1,5 +1,24 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use ts_rs::TS;
|
||||
use super::MAX_REWORK_NOTE_CHARS;
|
||||
|
||||
pub const MAX_NOTE_DESCRIPTION_CHARS: usize = 1024;
|
||||
|
||||
pub fn sanitize_prompt_text(value: &str, max_chars: usize) -> String {
|
||||
value
|
||||
.chars()
|
||||
.filter_map(|character| {
|
||||
if character.is_control() {
|
||||
Some(' ')
|
||||
} else if character == '`' {
|
||||
Some(''')
|
||||
} else {
|
||||
Some(character)
|
||||
}
|
||||
})
|
||||
.take(max_chars)
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize, TS)]
|
||||
#[ts(export, export_to = concat!(env!("CARGO_MANIFEST_DIR"), "/../src/features/ui-editor/types/"))]
|
||||
@@ -10,12 +29,15 @@ 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, MAX_NOTE_DESCRIPTION_CHARS)
|
||||
);
|
||||
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, MAX_REWORK_NOTE_CHARS));
|
||||
}
|
||||
}
|
||||
prompt
|
||||
|
||||
Reference in New Issue
Block a user