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_tokento 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
impl GenericFakeChatModel
Sourcepub fn new<I>(messages: I) -> Self
pub fn new<I>(messages: I) -> Self
Create a new GenericFakeChatModel with an iterator of messages.
Sourcepub fn from_strings(messages: Vec<String>) -> Self
pub fn from_strings(messages: Vec<String>) -> Self
Create from a vector of strings (converted to AIMessages).
Sourcepub fn with_config(self, config: ChatModelConfig) -> Self
pub fn with_config(self, config: ChatModelConfig) -> Self
Set the configuration.
Trait Implementations§
Source§impl BaseChatModel for GenericFakeChatModel
impl BaseChatModel for GenericFakeChatModel
Source§fn chat_config(&self) -> &ChatModelConfig
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,
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>
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>
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,
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 moreSource§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,
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>
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>
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>
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>
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
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
fn has_stream_impl(&self) -> bool
Check if
_stream is implemented (not the default). Read moreSource§fn has_astream_impl(&self) -> bool
fn has_astream_impl(&self) -> bool
Check if
_astream is implemented (not the default). Read moreSource§fn has_streaming_field(&self) -> Option<bool>
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
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,
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,
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,
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,
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>>
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,
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,
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<()>
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>
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,
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,
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,
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
fn get_chat_ls_params(&self, stop: Option<&[String]>) -> LangSmithParams
Get standard params for tracing.
Source§fn to_dict(&self) -> HashMap<String, Value>
fn to_dict(&self) -> HashMap<String, Value>
Get a dictionary representation of the model. Read more
Source§impl BaseLanguageModel for GenericFakeChatModel
impl BaseLanguageModel for GenericFakeChatModel
Source§fn model_name(&self) -> &str
fn model_name(&self) -> &str
Get the model name/identifier.
Source§fn config(&self) -> &LanguageModelConfig
fn config(&self) -> &LanguageModelConfig
Get the configuration 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,
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
fn get_ls_params(&self, stop: Option<&[String]>) -> LangSmithParams
Get parameters for tracing/monitoring.
Source§fn identifying_params(&self) -> HashMap<String, Value>
fn identifying_params(&self) -> HashMap<String, Value>
Get the identifying parameters for this model.
Source§fn get_token_ids(&self, text: &str) -> Vec<u32>
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
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
fn get_num_tokens_from_messages(&self, messages: &[BaseMessage]) -> usize
Get the number of tokens in the messages. Read more
Auto Trait Implementations§
impl !Freeze for GenericFakeChatModel
impl !RefUnwindSafe for GenericFakeChatModel
impl Send for GenericFakeChatModel
impl Sync for GenericFakeChatModel
impl Unpin for GenericFakeChatModel
impl !UnwindSafe for GenericFakeChatModel
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