pub struct Chain { /* 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 Chain
impl Chain
Sourcepub fn new(state: PromptTemplate) -> Result<Chain, StringTemplateError>
pub fn new(state: PromptTemplate) -> Result<Chain, StringTemplateError>
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
pub fn new_with_message_collection( state: &ChatMessageCollection<String>, ) -> Chain
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<E: Executor>(
&mut self,
step: Step,
parameters: &Parameters,
exec: &E,
) -> Result<Output, Error>
pub async fn send_message<E: Executor>( &mut self, step: Step, parameters: &Parameters, exec: &E, ) -> Result<Output, 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<E: Executor>(
&mut self,
options: &Options,
prompt: &Prompt,
exec: &E,
) -> Result<Output, Error>
pub async fn send_message_raw<E: Executor>( &mut self, options: &Options, prompt: &Prompt, exec: &E, ) -> Result<Output, 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.