pub struct SystemInjector { /* private fields */ }Expand description
Injects system prompt content based on turn or token thresholds.
Add rules with SystemInjector::add_rule, then call SystemInjector::check
each turn to get any content that should be injected.
§Example
use neuron_context::{SystemInjector, InjectionTrigger};
let mut injector = SystemInjector::new();
injector.add_rule(InjectionTrigger::EveryNTurns(5), "Reminder: be concise.".into());
injector.add_rule(InjectionTrigger::OnTokenThreshold(50_000), "Context is getting long.".into());
// Turn 5, under token threshold
let injected = injector.check(5, 10_000);
assert!(injected.contains(&"Reminder: be concise.".to_string()));
// Turn 1, over token threshold
let injected = injector.check(1, 60_000);
assert!(injected.contains(&"Context is getting long.".to_string()));Implementations§
Source§impl SystemInjector
impl SystemInjector
Sourcepub fn add_rule(&mut self, trigger: InjectionTrigger, content: String)
pub fn add_rule(&mut self, trigger: InjectionTrigger, content: String)
Adds an injection rule.
§Arguments
trigger— when this rule firescontent— the text to inject when triggered
Trait Implementations§
Source§impl Default for SystemInjector
impl Default for SystemInjector
Source§fn default() -> SystemInjector
fn default() -> SystemInjector
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for SystemInjector
impl RefUnwindSafe for SystemInjector
impl Send for SystemInjector
impl Sync for SystemInjector
impl Unpin for SystemInjector
impl UnsafeUnpin for SystemInjector
impl UnwindSafe for SystemInjector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more