Struct chat_gpt_lib_rs::client::ChatGPTClient

source ·
pub struct ChatGPTClient { /* private fields */ }
Expand description

Main ChatGPTClient struct.

Implementations§

source§

impl ChatGPTClient

source

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.
source

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§

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