pub struct Strings<F: Fn(&mut String) -> bool + Send + Sync>(pub F);Expand description
Every string, keys included, of every value: messages and asides through their serde form, saved values, text and every file. Redaction and path remapping are this. A string that is part of a message’s or an aside’s form, such as a field name or a tag, is left as it is where changing it would make the value unreadable.
use rig_core::conversation::Author;
use rig_core::message::Message;
use rig_memory::{MemoryStore, Session, Strings, load, rewrite, save};
let store = MemoryStore::default();
let mut conversation = load(&store, "main")?;
conversation.push(Message::user("my key is sk-123"));
save(&store, "main", &mut conversation)?;
let redact = Strings(|text: &mut String| {
let hit = text.contains("sk-123");
if hit {
*text = text.replace("sk-123", "[REDACTED]");
}
hit
});
let rewritten = rewrite(&store, Author::plugin("redact"), &redact)?;
assert_eq!(rewritten.logs.len(), 1);
let main = Session::read(&store)?.agents.remove(0);
assert_eq!(main.conversation.messages(), [Message::user("my key is [REDACTED]").into()]);Tuple Fields§
§0: FTrait Implementations§
Source§impl<F: Fn(&mut String) -> bool + Send + Sync> Rewrite for Strings<F>
impl<F: Fn(&mut String) -> bool + Send + Sync> Rewrite for Strings<F>
Source§fn message(&self, _: &Place<'_>, message: &mut Message) -> bool
fn message(&self, _: &Place<'_>, message: &mut Message) -> bool
A message of a push, a splice or a reset. Images are as stored:
blob:<sha256>.<ext> in a push or a splice, inline in a reset;
inline data put in a push or a splice is stored as a blob.Auto Trait Implementations§
impl<F> Freeze for Strings<F>where
F: Freeze,
impl<F> RefUnwindSafe for Strings<F>where
F: RefUnwindSafe,
impl<F> Send for Strings<F>
impl<F> Sync for Strings<F>
impl<F> Unpin for Strings<F>where
F: Unpin,
impl<F> UnsafeUnpin for Strings<F>where
F: UnsafeUnpin,
impl<F> UnwindSafe for Strings<F>where
F: UnwindSafe,
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