Struct chat_gpt_lib_rs::client::ChatGPTClient
source · pub struct ChatGPTClient { /* private fields */ }
Expand description
Main ChatGPTClient struct.
Implementations§
source§impl ChatGPTClient
impl ChatGPTClient
sourcepub fn new(api_key: &str, base_url: &str) -> Self
pub fn new(api_key: &str, base_url: &str) -> Self
Creates a new ChatGPTClient with the given API key and base URL.
§Arguments
api_key
- The API key for the ChatGPT API.base_url
- The base URL for the ChatGPT API.
sourcepub async fn chat(&self, input: ChatInput) -> Result<ChatResponse, ChatGPTError>
pub async fn chat(&self, input: ChatInput) -> Result<ChatResponse, ChatGPTError>
Sends a request to the ChatGPT API with the given input and returns the response.
§Arguments
input
- A ChatInput struct representing the input for the chat API call.
§Examples
use chat_gpt_lib_rs::{ChatGPTClient, ChatInput, Message, Model, Role};
async fn example() {
let chat_gpt = ChatGPTClient::new("your_api_key", "https://api.openai.com");
let input = ChatInput {
model: Model::Gpt_4,
messages: vec![
Message {
role: Role::System,
content: "You are a helpful assistant.".to_string(),
},
Message {
role: Role::User,
content: "Who is the best field hockey player in the world".to_string(),
},
],
..Default::default()
};
let response = chat_gpt.chat(input).await.unwrap();
}
§Errors
Returns a ChatGPTError if the request fails.
Auto Trait Implementations§
impl Freeze for ChatGPTClient
impl !RefUnwindSafe for ChatGPTClient
impl Send for ChatGPTClient
impl Sync for ChatGPTClient
impl Unpin for ChatGPTClient
impl !UnwindSafe for ChatGPTClient
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