pub struct ChatGPT {
    pub session_id: String,
    pub chat_context: ChatContext,
    /* private fields */
}

Fields§

§session_id: String§chat_context: ChatContext

Implementations§

source§

impl ChatGPT

source

pub fn new( openai_api_token: String, chat_context: Option<ChatContext>, session_id: Option<String> ) -> Result<ChatGPT>

source

pub async fn completion(&mut self) -> Result<ChatResponse>

source

pub async fn completion_with_message( &mut self, message: Message ) -> Result<ChatResponse>

source

pub async fn completion_with_user_content( &mut self, content: String ) -> Result<ChatResponse>

source

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(())
}
source

pub fn push_message(&mut self, message: Message)

source

pub fn set_messages(&mut self, messages: Vec<Message>)

source

pub fn push_function(&mut self, function: FunctionSpecification)

source

pub fn set_functions(&mut self, functions: Vec<FunctionSpecification>)

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more