Expand description
A system prompt as data: a role and named sections, rendered into one system message only when the request is sent, so a layer in between can read, change or move a section by its tag.
use rig_core::completion::{CompletionRequest, Section, SystemPrompt};
let mut prompt = SystemPrompt {
role: "You are a coding agent.".into(),
sections: vec![Section::new("environment", "Today is Monday.")],
};
assert_eq!(
prompt.text(),
"You are a coding agent.\n\n<environment>\nToday is Monday.\n</environment>"
);
let request = CompletionRequest::new("Hello").with_system(&prompt);
assert_eq!(request.system_instructions(), Some(prompt.text().as_str()));
let moved = prompt.take("environment");
assert_eq!(moved.map(|section| section.text), Some("Today is Monday.".into()));
assert_eq!(prompt.text(), "You are a coding agent.");Structsยง
- Section
- A named part of a
SystemPrompt. - System
Prompt - A system prompt in parts: the role, then each non-empty section between
<tag>and</tag>, sent as one system message.