GenericFakeChatModel

Struct GenericFakeChatModel 

Source
pub struct GenericFakeChatModel { /* private fields */ }
Expand description

Generic fake chat model that can be used to test the chat model interface.

  • Chat model should be usable in both sync and async tests
  • Invokes on_llm_new_token to allow for testing of callback related code for new tokens.
  • Includes logic to break messages into message chunks to facilitate testing of streaming.

Implementations§

Source§

impl GenericFakeChatModel

Source

pub fn new<I>(messages: I) -> Self
where I: Iterator<Item = AIMessage> + Send + 'static,

Create a new GenericFakeChatModel with an iterator of messages.

Source

pub fn from_vec(messages: Vec<AIMessage>) -> Self

Create from a vector of messages.

Source

pub fn from_strings(messages: Vec<String>) -> Self

Create from a vector of strings (converted to AIMessages).

Source

pub fn with_config(self, config: ChatModelConfig) -> Self

Set the configuration.

Trait Implementations§

Source§

impl BaseChatModel for GenericFakeChatModel

Source§

fn chat_config(&self) -> &ChatModelConfig

Get the chat model configuration.
Source§

fn _generate<'life0, 'life1, 'async_trait>( &'life0 self, _messages: Vec<BaseMessage>, _stop: Option<Vec<String>>, _run_manager: Option<&'life1 CallbackManagerForLLMRun>, ) -> Pin<Box<dyn Future<Output = Result<ChatResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Core abstract method to generate a chat result. Read more
Source§

fn _stream( &self, _messages: Vec<BaseMessage>, _stop: Option<Vec<String>>, _run_manager: Option<&CallbackManagerForLLMRun>, ) -> Result<ChatGenerationStream>

Stream the output of the model. Read more
Source§

fn profile(&self) -> Option<&ModelProfile>

Get the model profile, if available.
Source§

fn _agenerate<'life0, 'life1, 'async_trait>( &'life0 self, messages: Vec<BaseMessage>, stop: Option<Vec<String>>, _run_manager: Option<&'life1 AsyncCallbackManagerForLLMRun>, ) -> Pin<Box<dyn Future<Output = Result<ChatResult>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Async version of _generate. Read more
Source§

fn _astream<'life0, 'life1, 'async_trait>( &'life0 self, messages: Vec<BaseMessage>, stop: Option<Vec<String>>, _run_manager: Option<&'life1 AsyncCallbackManagerForLLMRun>, ) -> Pin<Box<dyn Future<Output = Result<ChatGenerationStream>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Async stream the output of the model. Read more
Source§

fn get_first_message(&self, result: &ChatResult) -> Result<AIMessage>

Get the first AI message from a chat result. Read more
Source§

fn _combine_llm_outputs( &self, _llm_outputs: &[Option<HashMap<String, Value>>], ) -> HashMap<String, Value>

Combine LLM outputs from multiple results. Read more
Source§

fn _convert_cached_generations( &self, cache_val: Vec<Generation>, ) -> Vec<ChatGeneration>

Convert cached Generation objects to ChatGeneration objects. Read more
Source§

fn _get_invocation_params( &self, stop: Option<&[String]>, kwargs: Option<&HashMap<String, Value>>, ) -> HashMap<String, Value>

Get invocation parameters for tracing. Read more
Source§

fn _get_llm_string( &self, stop: Option<&[String]>, kwargs: Option<&HashMap<String, Value>>, ) -> String

Get the LLM string for cache key generation. Read more
Source§

fn has_stream_impl(&self) -> bool

Check if _stream is implemented (not the default). Read more
Source§

fn has_astream_impl(&self) -> bool

Check if _astream is implemented (not the default). Read more
Source§

fn has_streaming_field(&self) -> Option<bool>

Check if streaming is enabled via a model field. Read more
Source§

fn _should_stream( &self, async_api: bool, has_tools: bool, stream_kwarg: Option<bool>, run_manager: Option<&[Arc<dyn BaseCallbackHandler>]>, ) -> bool

Determine if a given model call should hit the streaming API. Read more
Source§

fn generate<'life0, 'async_trait>( &'life0 self, messages: Vec<Vec<BaseMessage>>, stop: Option<Vec<String>>, _callbacks: Option<Callbacks>, ) -> Pin<Box<dyn Future<Output = Result<LLMResult>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Generate from a batch of message lists. Read more
Source§

fn agenerate<'life0, 'async_trait>( &'life0 self, messages: Vec<Vec<BaseMessage>>, stop: Option<Vec<String>>, _callbacks: Option<Callbacks>, ) -> Pin<Box<dyn Future<Output = Result<LLMResult>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Async version of generate.
Source§

fn _call_async<'life0, 'async_trait>( &'life0 self, messages: Vec<BaseMessage>, stop: Option<Vec<String>>, callbacks: Option<Callbacks>, ) -> Pin<Box<dyn Future<Output = Result<BaseMessage>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Async call helper. Read more
Source§

fn generate_with_tools<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, messages: Vec<BaseMessage>, _tools: &'life1 [ToolDefinition], _tool_choice: Option<&'life2 ToolChoice>, stop: Option<Vec<String>>, ) -> Pin<Box<dyn Future<Output = Result<AIMessage>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Generate a response from the model with tools. Read more
Source§

fn convert_input(&self, input: LanguageModelInput) -> Result<Vec<BaseMessage>>

Convert input to messages.
Source§

fn invoke<'life0, 'async_trait>( &'life0 self, input: LanguageModelInput, ) -> Pin<Box<dyn Future<Output = Result<AIMessage>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Invoke the model with input.
Source§

fn ainvoke<'life0, 'async_trait>( &'life0 self, input: LanguageModelInput, ) -> Pin<Box<dyn Future<Output = Result<AIMessage>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Async invoke the model.
Source§

fn bind_tools( &self, _tools: &[Arc<dyn BaseTool>], _tool_choice: Option<ToolChoice>, ) -> Result<()>

Bind tools to the model. Read more
Source§

fn get_tool_definitions( &self, tools: &[Arc<dyn BaseTool>], ) -> Vec<ToolDefinition>

Get tool definitions from tools. Read more
Source§

fn stream<'life0, 'async_trait>( &'life0 self, input: LanguageModelInput, stop: Option<Vec<String>>, ) -> Pin<Box<dyn Future<Output = Result<AIMessageChunkStream>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Generate a streaming response from the model. Read more
Source§

fn astream<'life0, 'async_trait>( &'life0 self, input: LanguageModelInput, stop: Option<Vec<String>>, ) -> Pin<Box<dyn Future<Output = Result<AIMessageChunkStream>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait,

Async stream the model output. Read more
Source§

fn stream_generations<'life0, 'life1, 'async_trait>( &'life0 self, messages: Vec<BaseMessage>, stop: Option<Vec<String>>, run_manager: Option<&'life1 CallbackManagerForLLMRun>, ) -> Pin<Box<dyn Future<Output = Result<ChatGenerationStream>> + Send + 'async_trait>>
where Self: Sync + 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Stream ChatGenerationChunk objects from the model. Read more
Source§

fn get_chat_ls_params(&self, stop: Option<&[String]>) -> LangSmithParams

Get standard params for tracing.
Source§

fn to_dict(&self) -> HashMap<String, Value>

Get a dictionary representation of the model. Read more
Source§

fn with_structured_output( &self, _schema: Value, _include_raw: bool, ) -> Result<()>

Create a wrapper that structures model output using a schema. Read more
Source§

fn get_identifying_params(&self) -> HashMap<String, Value>

Get the identifying parameters for this model. Read more
Source§

impl BaseLanguageModel for GenericFakeChatModel

Source§

fn llm_type(&self) -> &str

Return the type identifier for this language model. Read more
Source§

fn model_name(&self) -> &str

Get the model name/identifier.
Source§

fn config(&self) -> &LanguageModelConfig

Get the configuration for this model.
Source§

fn cache(&self) -> Option<&dyn BaseCache>

Get the cache for this model, if any.
Source§

fn callbacks(&self) -> Option<&Callbacks>

Get the callbacks for this model.
Source§

fn generate_prompt<'life0, 'async_trait>( &'life0 self, prompts: Vec<LanguageModelInput>, stop: Option<Vec<String>>, _callbacks: Option<Callbacks>, ) -> Pin<Box<dyn Future<Output = Result<LLMResult>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Pass a sequence of prompts to the model and return model generations. Read more
Source§

fn get_ls_params(&self, stop: Option<&[String]>) -> LangSmithParams

Get parameters for tracing/monitoring.
Source§

fn identifying_params(&self) -> HashMap<String, Value>

Get the identifying parameters for this model.
Source§

fn get_token_ids(&self, text: &str) -> Vec<u32>

Get the ordered IDs of tokens in a text. Read more
Source§

fn get_num_tokens(&self, text: &str) -> usize

Get the number of tokens present in the text. Read more
Source§

fn get_num_tokens_from_messages(&self, messages: &[BaseMessage]) -> usize

Get the number of tokens in the messages. Read more
Source§

impl Debug for GenericFakeChatModel

Source§

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

Formats the value using the given formatter. Read more

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