pub struct ClearToolOutputs {
pub keep_tokens: usize,
pub keep_under: usize,
}Expand description
Frees context by clearing the outputs of older tool calls: walking back
from the end, the outputs within the first keep_tokens stay, and every
older one is replaced by a placeholder. The last message is never
touched: it is what the model must answer. Error results stay, being
short and telling the model what went wrong, and so do outputs under
keep_under tokens, which free little. The calls themselves stay, so
the conversation keeps its shape. Each size missing from its serde form
is the default’s.
Fields§
§keep_tokens: usizeTokens of the newest tool output kept.
keep_under: usizeTokens under which an output is never cleared.
Implementations§
Source§impl ClearToolOutputs
impl ClearToolOutputs
Sourcepub const PLACEHOLDER: &'static str = "[output cleared to fit the context window; run the tool again if needed]"
pub const PLACEHOLDER: &'static str = "[output cleared to fit the context window; run the tool again if needed]"
What a cleared output says.
Sourcepub fn new(keep_tokens: usize) -> Self
pub fn new(keep_tokens: usize) -> Self
Keep the newest keep_tokens of tool output, counted by the default
HeuristicTokenCounter, and say Self::PLACEHOLDER instead of
the rest but outputs under the default keep_under: the serde form
that names only keep_tokens.
use rig_memory::ClearToolOutputs;
let config: ClearToolOutputs = serde_json::from_str(r#"{"keep_tokens": 8000}"#)?;
assert_eq!(ClearToolOutputs::new(8000), config);Sourcepub fn clear(&self, messages: &mut [Arc<Message>]) -> Cleared
pub fn clear(&self, messages: &mut [Arc<Message>]) -> Cleared
Clears older tool outputs of messages in place.
Sourcepub fn clear_conversation(
&self,
conversation: &mut Conversation,
by: Author,
) -> Cleared
pub fn clear_conversation( &self, conversation: &mut Conversation, by: Author, ) -> Cleared
Clears older tool outputs of conversation, as Self::clear
does, rewriting the entries that change in place by by
(Conversation::edit_each), so they keep their ids.
Sourcepub fn plan(&self, conversation: &Conversation) -> ClearPlan
pub fn plan(&self, conversation: &Conversation) -> ClearPlan
Which tool outputs of conversation Self::clear_conversation
would clear, by message id, so the plan still applies once messages
arrive or a copy of the conversation is edited.
Trait Implementations§
Source§impl Clone for ClearToolOutputs
impl Clone for ClearToolOutputs
Source§impl Debug for ClearToolOutputs
impl Debug for ClearToolOutputs
Source§impl Default for ClearToolOutputs
impl Default for ClearToolOutputs
Source§impl<'de> Deserialize<'de> for ClearToolOutputswhere
ClearToolOutputs: Default,
impl<'de> Deserialize<'de> for ClearToolOutputswhere
ClearToolOutputs: Default,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ClearToolOutputs
Source§impl PartialEq for ClearToolOutputs
impl PartialEq for ClearToolOutputs
Source§impl Serialize for ClearToolOutputs
impl Serialize for ClearToolOutputs
impl StructuralPartialEq for ClearToolOutputs
Auto Trait Implementations§
impl Freeze for ClearToolOutputs
impl RefUnwindSafe for ClearToolOutputs
impl Send for ClearToolOutputs
impl Sync for ClearToolOutputs
impl Unpin for ClearToolOutputs
impl UnsafeUnpin for ClearToolOutputs
impl UnwindSafe for ClearToolOutputs
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.