pub struct UsageMetadataCallbackGuard { /* private fields */ }Expand description
Guard type for the get_usage_metadata_callback function.
This guard provides access to the underlying UsageMetadataCallbackHandler
and can be used with a callback manager to track usage metadata.
When the guard is dropped, any cleanup is performed automatically.
§Example
ⓘ
use agent_chain_core::callbacks::get_usage_metadata_callback;
let callback_guard = get_usage_metadata_callback();
// Use callback_guard.handler() with your callback manager
// The handler can be cloned and added to managers
let usage = callback_guard.usage_metadata();
for (model, metadata) in usage.iter() {
println!("{}: {} tokens", model, metadata.total_tokens);
}Implementations§
Source§impl UsageMetadataCallbackGuard
impl UsageMetadataCallbackGuard
Sourcepub fn handler(&self) -> &UsageMetadataCallbackHandler
pub fn handler(&self) -> &UsageMetadataCallbackHandler
Get a reference to the underlying handler.
Sourcepub fn handler_mut(&mut self) -> &mut UsageMetadataCallbackHandler
pub fn handler_mut(&mut self) -> &mut UsageMetadataCallbackHandler
Get a mutable reference to the underlying handler.
Sourcepub fn usage_metadata(&self) -> HashMap<String, UsageMetadata>
pub fn usage_metadata(&self) -> HashMap<String, UsageMetadata>
Get the collected usage metadata.
Sourcepub fn as_arc_handler(&self) -> Arc<dyn BaseCallbackHandler>
pub fn as_arc_handler(&self) -> Arc<dyn BaseCallbackHandler>
Get an Arc-wrapped handler suitable for use with callback managers.
Methods from Deref<Target = UsageMetadataCallbackHandler>§
Sourcepub fn usage_metadata(&self) -> HashMap<String, UsageMetadata>
pub fn usage_metadata(&self) -> HashMap<String, UsageMetadata>
Get the collected usage metadata.
Returns a clone of the current usage metadata map, keyed by model name.
Trait Implementations§
Source§impl Deref for UsageMetadataCallbackGuard
impl Deref for UsageMetadataCallbackGuard
Auto Trait Implementations§
impl Freeze for UsageMetadataCallbackGuard
impl RefUnwindSafe for UsageMetadataCallbackGuard
impl Send for UsageMetadataCallbackGuard
impl Sync for UsageMetadataCallbackGuard
impl Unpin for UsageMetadataCallbackGuard
impl UnwindSafe for UsageMetadataCallbackGuard
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