Sebas Tin angelegt und Synology Chat connected
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
use crate::types::Result;
|
||||
use crate::error::NazarickError;
|
||||
|
||||
/// Verantwortlich für das Zusammensetzen des System-Prompts.
|
||||
/// Liest soul_core.md und soul_personality.md und kombiniert
|
||||
/// sie in der richtigen Reihenfolge.
|
||||
///
|
||||
/// Reihenfolge ist bewusst gewählt:
|
||||
/// 1. soul_core.md IMMER zuerst — Kernregeln haben höchste Priorität
|
||||
/// 2. soul_personality.md danach — Ton und Stil
|
||||
/// So kann soul_personality niemals soul_core überschreiben.
|
||||
pub struct PromptBuilder {
|
||||
/// Pfad zu soul_core.md — unveränderliche Kernregeln
|
||||
soul_core_path: String,
|
||||
/// Pfad zu soul_personality.md — entwickelbarer Persönlichkeitsteil
|
||||
soul_personality_path: String,
|
||||
}
|
||||
|
||||
impl PromptBuilder {
|
||||
/// Erstellt einen neuen PromptBuilder mit den angegebenen Dateipfaden.
|
||||
pub fn new(
|
||||
soul_core_path: impl Into<String>,
|
||||
soul_personality_path: impl Into<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
soul_core_path: soul_core_path.into(),
|
||||
soul_personality_path: soul_personality_path.into(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Liest beide soul-Dateien und kombiniert sie zum finalen System-Prompt.
|
||||
/// Fehlt soul_personality.md wird nur soul_core.md verwendet —
|
||||
/// das System bleibt funktionsfähig auch ohne Persönlichkeitsdatei.
|
||||
pub fn build(&self) -> Result<String> {
|
||||
// soul_core.md ist Pflicht — ohne Kernregeln kein Start
|
||||
let core = std::fs::read_to_string(&self.soul_core_path)
|
||||
.map_err(|e| NazarickError::Config(
|
||||
format!("soul_core.md nicht gefunden unter '{}': {}",
|
||||
self.soul_core_path, e)
|
||||
))?;
|
||||
|
||||
// soul_personality.md ist optional — graceful fallback
|
||||
let personality = match std::fs::read_to_string(&self.soul_personality_path) {
|
||||
Ok(content) => content,
|
||||
Err(_) => {
|
||||
// Kein Fehler — leere Persönlichkeit ist valid beim ersten Start
|
||||
String::new()
|
||||
}
|
||||
};
|
||||
|
||||
// Zusammensetzen: Core immer zuerst
|
||||
let system_prompt = if personality.is_empty() {
|
||||
core
|
||||
} else {
|
||||
format!("{}\n\n---\n\n{}", core, personality)
|
||||
};
|
||||
|
||||
Ok(system_prompt)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user