pub struct Chat { /* private fields */ }
Expand description
A struct that represents a chat session
This struct makes it easy to interact with the chat api, as well as remembering messages.
This struct guarantees that messages are sent and stored in the order that ask
is called.
Requests to the API are only sent when get_response
is called.
You can build a new chat session with ChatBuilder
.
Implementations§
Source§impl Chat
impl Chat
Sourcepub async fn get_messages(&self) -> Vec<ChatMessage>
pub async fn get_messages(&self) -> Vec<ChatMessage>
Get the messages that have been sent and received including the system and assistan messages.
Sourcepub async fn ask(&self, message: &str) -> Result<(), Box<dyn Error>>
pub async fn ask(&self, message: &str) -> Result<(), Box<dyn Error>>
Adds a message to the queue to be sent to the API.
Sourcepub async fn get_response(
&self,
user: Option<String>,
) -> Result<ChatMessage, Box<dyn Error>>
pub async fn get_response( &self, user: Option<String>, ) -> Result<ChatMessage, Box<dyn Error>>
Sends the message history to the API including the last question asked, and returns the response.
Auto Trait Implementations§
impl !Freeze for Chat
impl !RefUnwindSafe for Chat
impl Send for Chat
impl Sync for Chat
impl Unpin for Chat
impl UnwindSafe for Chat
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