Struct chatgpt_functions::chat_gpt::ChatGPT
source · pub struct ChatGPT {
pub session_id: String,
pub chat_context: ChatContext,
/* private fields */
}Fields§
§session_id: String§chat_context: ChatContextImplementations§
source§impl ChatGPT
impl ChatGPT
pub fn new( openai_api_token: String, chat_context: Option<ChatContext>, session_id: Option<String> ) -> Result<ChatGPT>
pub async fn completion(&mut self) -> Result<ChatResponse>
pub async fn completion_with_message( &mut self, message: Message ) -> Result<ChatResponse>
pub async fn completion_with_user_content( &mut self, content: String ) -> Result<ChatResponse>
sourcepub async fn completion_with_message_updating_context(
&mut self,
message: Message
) -> Result<Message>
pub async fn completion_with_message_updating_context( &mut self, message: Message ) -> Result<Message>
This function is used to update the context with the response from the AI It assumes that there will only be one choice in the response It returns the response from the AI It does update the context with the response from the AI
Example
use chatgpt_functions::chat_context::ChatContext;
use chatgpt_functions::chat_gpt::ChatGPT;
use chatgpt_functions::message::Message;
use chatgpt_functions::chat_response::ChatResponse;
use anyhow::Result;
#[tokio::main]
async fn main() -> Result<()> {
let mut gpt = ChatGPT::new("key".to_string(), None, None)?;
let mut message = Message::new("role".to_string());
message.set_content("Hi!".to_string());
let response_message = gpt.completion_with_message_updating_context(message).await?;
// The answer from the AI will be stored in the context
assert_eq!(response_message.content.unwrap(), "Hi, how are you?".to_string());
assert_eq!(gpt.chat_context.messages.len(), 2);
Ok(())
}pub fn push_message(&mut self, message: Message)
pub fn set_messages(&mut self, messages: Vec<Message>)
pub fn push_function(&mut self, function: FunctionSpecification)
pub fn set_functions(&mut self, functions: Vec<FunctionSpecification>)
Auto Trait Implementations§
impl !RefUnwindSafe for ChatGPT
impl Send for ChatGPT
impl Sync for ChatGPT
impl Unpin for ChatGPT
impl !UnwindSafe for ChatGPT
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