pub struct ChatHistoryChain<T>where
T: AsyncChatClient,{ /* private fields */ }
Expand description
§ChatHistoryChain
The chat history chain executes the workflow of saving each message in the conversation history. that is then resent with each subsequent request to the chat client. So previous messages can be
T
- The type of the chat client to be used
§Examples
use rag_toolchain::clients::*;
use rag_toolchain::chains::*;
async fn run_chain() {
const SYSTEM_MESSAGE: &'static str = "You are a chat bot that must answer questions accurately";
let system_prompt = PromptMessage::SystemMessage(SYSTEM_MESSAGE.into());
let client = OpenAIChatCompletionClient::try_new(OpenAIModel::Gpt3Point5Turbo).unwrap();
let chain = ChatHistoryChain::new(client, system_prompt);
let user_prompt1 = PromptMessage::HumanMessage("Please tell me about the weather".into());
let response1 = chain.invoke_chain(user_prompt1).await.unwrap();
let user_prompt2 =
PromptMessage::HumanMessage("What was the last question I just asked ?".into());
let response2 = chain.invoke_chain(user_prompt2).await.unwrap();
println!("Response 1: {}", response1.content());
println!("Response 2: {}", response2.content());
}
Implementations§
Source§impl<T> ChatHistoryChain<T>where
T: AsyncChatClient,
impl<T> ChatHistoryChain<T>where
T: AsyncChatClient,
Sourcepub fn new(chat_client: T, system_prompt: PromptMessage) -> Self
pub fn new(chat_client: T, system_prompt: PromptMessage) -> Self
§ChatHistoryChain::new
This constructor to create a new ChatHistoryChain.
§Arguments
chat_client
:T
- The chat client to be usedsystem_prompt
:PromptMessage
- The system prompt, please usePromptMessage::SystemMessage
Sourcepub async fn invoke_chain(
&self,
user_message: PromptMessage,
) -> Result<PromptMessage, ChainError<T::ErrorType>>
pub async fn invoke_chain( &self, user_message: PromptMessage, ) -> Result<PromptMessage, ChainError<T::ErrorType>>
§ChatHistoryChain::invoke_chain
function to execute the ChatHistoryChain given a new user prompt. Each time this method is invoked, the user message is added to the chat history.
§Arguments
user_message
:PromptMessage
- the user prompt that will be sent to the LLM along with the chat history.
§Errors
ChainError::ChatClientError
if the chat client invocation fails.
§Returns
PromptMessage::AIMessage
- the response from the chat client.
Trait Implementations§
Source§impl<T> Clone for ChatHistoryChain<T>where
T: AsyncChatClient + Clone,
impl<T> Clone for ChatHistoryChain<T>where
T: AsyncChatClient + Clone,
Source§fn clone(&self) -> ChatHistoryChain<T>
fn clone(&self) -> ChatHistoryChain<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T> Debug for ChatHistoryChain<T>where
T: AsyncChatClient + Debug,
impl<T> Debug for ChatHistoryChain<T>where
T: AsyncChatClient + Debug,
Source§impl<T> PartialEq for ChatHistoryChain<T>where
T: AsyncChatClient + PartialEq,
impl<T> PartialEq for ChatHistoryChain<T>where
T: AsyncChatClient + PartialEq,
impl<T> Eq for ChatHistoryChain<T>where
T: AsyncChatClient + Eq,
impl<T> StructuralPartialEq for ChatHistoryChain<T>where
T: AsyncChatClient,
Auto Trait Implementations§
impl<T> !Freeze for ChatHistoryChain<T>
impl<T> !RefUnwindSafe for ChatHistoryChain<T>
impl<T> Send for ChatHistoryChain<T>where
T: Send,
impl<T> !Sync for ChatHistoryChain<T>
impl<T> Unpin for ChatHistoryChain<T>where
T: Unpin,
impl<T> UnwindSafe for ChatHistoryChain<T>where
T: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more