FunctionCallbackHandler

Struct FunctionCallbackHandler 

Source
pub struct FunctionCallbackHandler<F>
where F: Fn(&str) + Send + Sync,
{ /* private fields */ }
Expand description

Tracer that calls a function with a single string parameter.

Implementations§

Source§

impl<F> FunctionCallbackHandler<F>
where F: Fn(&str) + Send + Sync,

Source

pub fn new(function: F) -> Self

Create a new FunctionCallbackHandler.

§Arguments
  • function - The callback function to call.
Source

pub fn get_parents(&self, run: &Run) -> Vec<Run>

Get the parents of a run.

§Arguments
  • run - The run to get the parents of.
§Returns

A list of parent runs.

Source

pub fn get_breadcrumbs(&self, run: &Run) -> String

Get the breadcrumbs of a run.

§Arguments
  • run - The run to get the breadcrumbs of.
§Returns

A string with the breadcrumbs of the run.

Trait Implementations§

Source§

impl<F> BaseTracer for FunctionCallbackHandler<F>
where F: Fn(&str) + Send + Sync + Debug,

Source§

fn persist_run_impl(&mut self, _run: &Run)

Persist a run (required implementation).
Source§

fn start_trace_impl(&mut self, run: &mut Run)

Start a trace for a run.
Source§

fn end_trace_impl(&mut self, run: &Run)

End a trace for a run.
Source§

fn handle_chat_model_start( &mut self, serialized: HashMap<String, Value>, messages: &[Vec<BaseMessage>], run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, extra: HashMap<String, Value>, ) -> Result<Run, TracerError>

Handle chat model start.
Source§

fn handle_llm_start( &mut self, serialized: HashMap<String, Value>, prompts: &[String], run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, extra: HashMap<String, Value>, ) -> Run

Handle LLM start.
Source§

fn handle_llm_new_token( &mut self, token: &str, run_id: Uuid, chunk: Option<&dyn Any>, parent_run_id: Option<Uuid>, ) -> Result<Run, TracerError>

Handle new LLM token.
Source§

fn handle_retry( &mut self, retry_state: &HashMap<String, Value>, run_id: Uuid, ) -> Result<Run, TracerError>

Handle retry event.
Source§

fn handle_llm_end( &mut self, response: &LLMResult, run_id: Uuid, ) -> Result<Run, TracerError>

Handle LLM end.
Source§

fn handle_llm_error( &mut self, error: &dyn Error, run_id: Uuid, response: Option<&LLMResult>, ) -> Result<Run, TracerError>

Handle LLM error.
Source§

fn handle_chain_start( &mut self, serialized: HashMap<String, Value>, inputs: HashMap<String, Value>, run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, run_type: Option<String>, name: Option<String>, extra: HashMap<String, Value>, ) -> Run

Handle chain start.
Source§

fn handle_chain_end( &mut self, outputs: HashMap<String, Value>, run_id: Uuid, inputs: Option<HashMap<String, Value>>, ) -> Result<Run, TracerError>

Handle chain end.
Source§

fn handle_chain_error( &mut self, error: &dyn Error, run_id: Uuid, inputs: Option<HashMap<String, Value>>, ) -> Result<Run, TracerError>

Handle chain error.
Source§

fn handle_tool_start( &mut self, serialized: HashMap<String, Value>, input_str: &str, run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, inputs: Option<HashMap<String, Value>>, extra: HashMap<String, Value>, ) -> Run

Handle tool start.
Source§

fn handle_tool_end( &mut self, output: Value, run_id: Uuid, ) -> Result<Run, TracerError>

Handle tool end.
Source§

fn handle_tool_error( &mut self, error: &dyn Error, run_id: Uuid, ) -> Result<Run, TracerError>

Handle tool error.
Source§

fn handle_retriever_start( &mut self, serialized: HashMap<String, Value>, query: &str, run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, extra: HashMap<String, Value>, ) -> Run

Handle retriever start.
Source§

fn handle_retriever_end( &mut self, documents: Vec<Value>, run_id: Uuid, ) -> Result<Run, TracerError>

Handle retriever end.
Source§

fn handle_retriever_error( &mut self, error: &dyn Error, run_id: Uuid, ) -> Result<Run, TracerError>

Handle retriever error.
Source§

impl<F> Debug for FunctionCallbackHandler<F>
where F: Fn(&str) + Send + Sync + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<F> TracerCore for FunctionCallbackHandler<F>
where F: Fn(&str) + Send + Sync + Debug,

Source§

fn config(&self) -> &TracerCoreConfig

Get the configuration for this tracer.
Source§

fn config_mut(&mut self) -> &mut TracerCoreConfig

Get the mutable configuration for this tracer.
Source§

fn run_map(&self) -> &HashMap<String, Run>

Get the run map.
Source§

fn run_map_mut(&mut self) -> &mut HashMap<String, Run>

Get the mutable run map.
Source§

fn order_map(&self) -> &HashMap<Uuid, (Uuid, String)>

Get the order map (run_id -> (trace_id, dotted_order)).
Source§

fn order_map_mut(&mut self) -> &mut HashMap<Uuid, (Uuid, String)>

Get the mutable order map.
Source§

fn persist_run(&mut self, _run: &Run)

Persist a run.
Source§

fn on_chain_start(&mut self, run: &Run)

Called when a chain run starts.
Source§

fn on_chain_end(&mut self, run: &Run)

Called when a chain run ends.
Source§

fn on_chain_error(&mut self, run: &Run)

Called when a chain run errors.
Source§

fn on_llm_start(&mut self, run: &Run)

Called when an LLM run starts.
Source§

fn on_llm_end(&mut self, run: &Run)

Called when an LLM run ends.
Source§

fn on_llm_error(&mut self, run: &Run)

Called when an LLM run errors.
Source§

fn on_tool_start(&mut self, run: &Run)

Called when a tool run starts.
Source§

fn on_tool_end(&mut self, run: &Run)

Called when a tool run ends.
Source§

fn on_tool_error(&mut self, run: &Run)

Called when a tool run errors.
Source§

fn add_child_run(&mut self, parent_run: &mut Run, child_run: Run)

Add a child run to a parent run.
Source§

fn get_stacktrace(error: &dyn Error) -> String

Get the stacktrace of an error.
Source§

fn start_trace(&mut self, run: &mut Run)

Start a trace for a run.
Source§

fn end_trace(&mut self, run: &Run)

End a trace for a run.
Source§

fn get_run( &self, run_id: Uuid, run_type: Option<&[&str]>, ) -> Result<Run, TracerError>

Get a run by ID.
Source§

fn get_run_mut(&mut self, run_id: Uuid) -> Option<&mut Run>

Get a mutable run by ID.
Source§

fn create_chat_model_run( &self, serialized: HashMap<String, Value>, messages: &[Vec<BaseMessage>], run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, extra: HashMap<String, Value>, ) -> Result<Run, TracerError>

Create a chat model run.
Source§

fn create_llm_run( &self, serialized: HashMap<String, Value>, prompts: &[String], run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, extra: HashMap<String, Value>, ) -> Run

Create an LLM run.
Source§

fn llm_run_with_token_event( &mut self, token: &str, run_id: Uuid, chunk: Option<&dyn Any>, _parent_run_id: Option<Uuid>, ) -> Result<Run, TracerError>

Process an LLM run with a new token event.
Source§

fn llm_run_with_retry_event( &mut self, retry_state: &HashMap<String, Value>, run_id: Uuid, ) -> Result<Run, TracerError>

Process an LLM run with a retry event.
Source§

fn complete_llm_run( &mut self, response: &LLMResult, run_id: Uuid, ) -> Result<Run, TracerError>

Complete an LLM run.
Source§

fn errored_llm_run( &mut self, error: &dyn Error, run_id: Uuid, response: Option<&LLMResult>, ) -> Result<Run, TracerError>

Mark an LLM run as errored.
Source§

fn create_chain_run( &self, serialized: HashMap<String, Value>, inputs: HashMap<String, Value>, run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, run_type: Option<String>, name: Option<String>, extra: HashMap<String, Value>, ) -> Run

Create a chain run.
Source§

fn get_chain_inputs( &self, inputs: HashMap<String, Value>, ) -> HashMap<String, Value>

Get chain inputs based on schema format.
Source§

fn get_chain_outputs( &self, outputs: HashMap<String, Value>, ) -> HashMap<String, Value>

Get chain outputs based on schema format.
Source§

fn complete_chain_run( &mut self, outputs: HashMap<String, Value>, run_id: Uuid, inputs: Option<HashMap<String, Value>>, ) -> Result<Run, TracerError>

Complete a chain run.
Source§

fn errored_chain_run( &mut self, error: &dyn Error, run_id: Uuid, inputs: Option<HashMap<String, Value>>, ) -> Result<Run, TracerError>

Mark a chain run as errored.
Source§

fn create_tool_run( &self, serialized: HashMap<String, Value>, input_str: &str, run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, inputs: Option<HashMap<String, Value>>, extra: HashMap<String, Value>, ) -> Run

Create a tool run.
Source§

fn complete_tool_run( &mut self, output: Value, run_id: Uuid, ) -> Result<Run, TracerError>

Complete a tool run.
Source§

fn errored_tool_run( &mut self, error: &dyn Error, run_id: Uuid, ) -> Result<Run, TracerError>

Mark a tool run as errored.
Source§

fn create_retrieval_run( &self, serialized: HashMap<String, Value>, query: &str, run_id: Uuid, parent_run_id: Option<Uuid>, tags: Option<Vec<String>>, metadata: Option<HashMap<String, Value>>, name: Option<String>, extra: HashMap<String, Value>, ) -> Run

Create a retrieval run.
Source§

fn complete_retrieval_run( &mut self, documents: Vec<Value>, run_id: Uuid, ) -> Result<Run, TracerError>

Complete a retrieval run.
Source§

fn errored_retrieval_run( &mut self, error: &dyn Error, run_id: Uuid, ) -> Result<Run, TracerError>

Mark a retrieval run as errored.
Source§

fn on_run_create(&mut self, _run: &Run)

Called when a run is created.
Source§

fn on_run_update(&mut self, _run: &Run)

Called when a run is updated.
Source§

fn on_llm_new_token( &mut self, _run: &Run, _token: &str, _chunk: Option<&dyn Any>, )

Called when a new LLM token is received.
Source§

fn on_chat_model_start(&mut self, _run: &Run)

Called when a chat model run starts.
Source§

fn on_retriever_start(&mut self, _run: &Run)

Called when a retriever run starts.
Source§

fn on_retriever_end(&mut self, _run: &Run)

Called when a retriever run ends.
Source§

fn on_retriever_error(&mut self, _run: &Run)

Called when a retriever run errors.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more