Struct ChatGPT

Source
pub struct ChatGPT {
    pub config: ModelConfiguration,
    /* private fields */
}
Expand description

The client that operates the ChatGPT API

Fields§

§config: ModelConfiguration

The configuration for this ChatGPT client

Implementations§

Source§

impl ChatGPT

Source

pub fn new<S: Into<String>>(api_key: S) -> Result<Self>

Constructs a new ChatGPT API client with provided API key and default configuration

Source

pub fn new_with_proxy<S: Into<String>>(api_key: S, proxy: Proxy) -> Result<Self>

Constructs a new ChatGPT API client with provided API key, default configuration and a reqwest proxy

Source

pub fn new_with_config<S: Into<String>>( api_key: S, config: ModelConfiguration, ) -> Result<Self>

Constructs a new ChatGPT API client with provided API Key and Configuration

Source

pub fn new_with_config_proxy<S: Into<String>>( api_key: S, config: ModelConfiguration, proxy: Proxy, ) -> Result<Self>

Constructs a new ChatGPT API client with provided API Key, Configuration and Reqwest proxy

Source

pub async fn restore_conversation_json<P: AsRef<Path>>( &self, file: P, ) -> Result<Conversation>

Restores a conversation from local conversation JSON file. The conversation file can originally be saved using the Conversation::save_history_json().

Source

pub async fn restore_conversation_postcard<P: AsRef<Path>>( &self, file: P, ) -> Result<Conversation>

Restores a conversation from local conversation postcard file. The conversation file can originally be saved using the Conversation::save_history_postcard().

Source

pub fn new_conversation(&self) -> Conversation

Starts a new conversation with a default starting message.

Conversations record message history.

Source

pub fn new_conversation_directed<S: Into<String>>( &self, direction_message: S, ) -> Conversation

Starts a new conversation with a specified starting message.

Conversations record message history.

Source

pub async fn send_history( &self, history: &Vec<ChatMessage>, ) -> Result<CompletionResponse>

Explicitly sends whole message history to the API.

In most cases, if you would like to store message history, you should be looking at the Conversation struct, and Self::new_conversation() and Self::new_conversation_directed()

Source

pub async fn send_history_streaming( &self, history: &Vec<ChatMessage>, ) -> Result<impl Stream<Item = ResponseChunk>>

Explicitly sends whole message history to the API and returns the response as stream. Stream will be empty if any errors are returned from the server.

In most cases, if you would like to store message history, you should be looking at the Conversation struct, and Self::new_conversation() and Self::new_conversation_directed()

Requires the streams crate feature

Source

pub async fn send_message<S: Into<String>>( &self, message: S, ) -> Result<CompletionResponse>

Sends a single message to the API without preserving message history.

Source

pub async fn send_message_streaming<S: Into<String>>( &self, message: S, ) -> Result<impl Stream<Item = ResponseChunk>>

Sends a single message to the API, and returns the response as stream, without preserving message history. Stream will be empty if any errors are returned from the server.

Requires the streams crate feature

Source

pub async fn send_message_functions<S: Into<String>, A: FunctionArgument>( &self, message: S, functions: Vec<FunctionDescriptor<A>>, ) -> Result<CompletionResponse>

Sends a message with specified function descriptors. ChatGPT is then able to call these functions.

NOTE: Functions are processed as tokens on the backend, so you might want to limit the amount of functions or their description.

Source

pub async fn send_message_functions_baked<S: Into<String>>( &self, message: S, baked_functions: Vec<Value>, ) -> Result<CompletionResponse>

Sends a message with specified pre-baked function descriptors. ChatGPT is then able to call these functions.

NOTE: Functions are processed as tokens on the backend, so you might want to limit the amount of functions or their description.

Source

pub async fn send_history_functions( &self, history: &Vec<ChatMessage>, functions: &Vec<Value>, ) -> Result<CompletionResponse>

Sends whole message history alongside with defined baked functions.

Trait Implementations§

Source§

impl Clone for ChatGPT

Source§

fn clone(&self) -> ChatGPT

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ChatGPT

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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 T
where 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> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T