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
impl ChatGPT
Sourcepub fn new<S: Into<String>>(api_key: S) -> Result<Self>
pub fn new<S: Into<String>>(api_key: S) -> Result<Self>
Constructs a new ChatGPT API client with provided API key and default configuration
Sourcepub fn new_with_proxy<S: Into<String>>(api_key: S, proxy: Proxy) -> Result<Self>
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
Sourcepub fn new_with_config<S: Into<String>>(
api_key: S,
config: ModelConfiguration,
) -> Result<Self>
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
Sourcepub fn new_with_config_proxy<S: Into<String>>(
api_key: S,
config: ModelConfiguration,
proxy: Proxy,
) -> Result<Self>
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
Sourcepub async fn restore_conversation_json<P: AsRef<Path>>(
&self,
file: P,
) -> Result<Conversation>
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()
.
Sourcepub async fn restore_conversation_postcard<P: AsRef<Path>>(
&self,
file: P,
) -> Result<Conversation>
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()
.
Sourcepub fn new_conversation(&self) -> Conversation
pub fn new_conversation(&self) -> Conversation
Starts a new conversation with a default starting message.
Conversations record message history.
Sourcepub fn new_conversation_directed<S: Into<String>>(
&self,
direction_message: S,
) -> Conversation
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.
Sourcepub async fn send_history(
&self,
history: &Vec<ChatMessage>,
) -> Result<CompletionResponse>
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()
Sourcepub async fn send_history_streaming(
&self,
history: &Vec<ChatMessage>,
) -> Result<impl Stream<Item = ResponseChunk>>
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
Sourcepub async fn send_message<S: Into<String>>(
&self,
message: S,
) -> Result<CompletionResponse>
pub async fn send_message<S: Into<String>>( &self, message: S, ) -> Result<CompletionResponse>
Sends a single message to the API without preserving message history.
Sourcepub async fn send_message_streaming<S: Into<String>>(
&self,
message: S,
) -> Result<impl Stream<Item = ResponseChunk>>
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
Sourcepub async fn send_message_functions<S: Into<String>, A: FunctionArgument>(
&self,
message: S,
functions: Vec<FunctionDescriptor<A>>,
) -> Result<CompletionResponse>
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.
Sourcepub async fn send_message_functions_baked<S: Into<String>>(
&self,
message: S,
baked_functions: Vec<Value>,
) -> Result<CompletionResponse>
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.
Sourcepub async fn send_history_functions(
&self,
history: &Vec<ChatMessage>,
functions: &Vec<Value>,
) -> Result<CompletionResponse>
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§
Auto Trait Implementations§
impl Freeze for ChatGPT
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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