FakeListChatModel

Struct FakeListChatModel 

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

Fake chat model for testing purposes.

Cycles through string responses in order.

Implementations§

Source§

impl FakeListChatModel

Source

pub fn new(responses: Vec<String>) -> Self

Create a new FakeListChatModel with the given responses.

Source

pub fn with_sleep(self, duration: Duration) -> Self

Set the sleep duration.

Source

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

Set the configuration.

Source

pub fn with_error_on_chunk(self, chunk_number: usize) -> Self

Set the chunk number to error on during streaming.

Source

pub fn current_index(&self) -> usize

Get the current index.

Source

pub fn reset(&self)

Reset the index.

Trait Implementations§

Source§

impl BaseChatModel for FakeListChatModel

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 FakeListChatModel

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 identifying_params(&self) -> HashMap<String, Value>

Get the identifying parameters for this model.
Source§

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

Get parameters for tracing/monitoring.
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 Clone for FakeListChatModel

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FakeListChatModel

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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