Struct llm_chain::chains::conversation::Chain
source · pub struct Chain<E: Executor> { /* private fields */ }
Expand description
Chain
represents a conversation between an entity and an LLM.
It holds the conversation state and provides methods for sending messages and receiving responses.
Implementations§
source§impl<E: Executor> Chain<E>
impl<E: Executor> Chain<E>
sourcepub fn new(state: PromptTemplate) -> Result<Chain<E>, Error<E::Error>>
pub fn new(state: PromptTemplate) -> Result<Chain<E>, Error<E::Error>>
Constructs a new Chain
with the given conversation state.
Self,
Arguments
state
- The initial prompt state to use.
sourcepub fn new_with_message_collection(
state: &ChatMessageCollection<String>
) -> Chain<E>
pub fn new_with_message_collection( state: &ChatMessageCollection<String> ) -> Chain<E>
Constructs a new Chain
with the given conversation state by passing a ChatMessageCollection
Arguments
state
- The initial prompt state to use.
sourcepub async fn send_message(
&mut self,
step: Step<E>,
parameters: &Parameters,
exec: &E
) -> Result<E::Output, Error<E::Error>>
pub async fn send_message( &mut self, step: Step<E>, parameters: &Parameters, exec: &E ) -> Result<E::Output, Error<E::Error>>
Sends a message to the LLM and returns the response.
This method sends a message to the LLM, adding it and the response to the internal state.
Arguments
step
- The step to send.parameters
- The parameters to use when formatting the step.exec
- The executor to use.
Returns
A Result
containing the LLM’s response as E::Output
on success or an Error
variant on failure.
sourcepub async fn send_message_raw(
&mut self,
options: Option<&<E as Executor>::PerInvocationOptions>,
prompt: &Prompt,
is_streaming: Option<bool>,
exec: &E
) -> Result<E::Output, Error<E::Error>>
pub async fn send_message_raw( &mut self, options: Option<&<E as Executor>::PerInvocationOptions>, prompt: &Prompt, is_streaming: Option<bool>, exec: &E ) -> Result<E::Output, Error<E::Error>>
Sends a message to the LLM and returns the response.
This method takes a ready prompt and options and sends it to the LLM, adding it and the response to the internal state.
Arguments
options
- The options to use when executing the prompt.prompt
- The prompt to send.exec
- The executor to use.
Returns
A Result
containing the LLM’s response as E::Output
on success or an Error
variant on failure.