Struct DeepSeekClient

Source
pub struct DeepSeekClient { /* private fields */ }
Expand description

A client for interacting with the DeepSeek API.

§Example

#[tokio::main]
async fn main() {
    use deepseek_api::DeepSeekClientBuilder;

    let api_key = "your_api_key".to_string();
    let client = DeepSeekClientBuilder::new(api_key).build().unwrap();

    // Get available models
    let models = client.models().await.unwrap();

    // Get user balance
    let balance = client.balance().await.unwrap();
}

§Fields

  • client - The underlying HTTP client.
  • host - The base URL for the DeepSeek API.

Implementations§

Source§

impl DeepSeekClient

Source

pub async fn models(&self) -> Result<ModelResp>

Retrieves the list of available models from the DeepSeek API.

This method sends a GET request to the /models endpoint of the DeepSeek API and returns a Result containing a ModelResp on success.

§Errors

This function will return an error if the request fails or if the response cannot be deserialized into a ModelResp.

§Example
#[tokio::main]
async fn main() {
    use deepseek_api::DeepSeekClientBuilder;

    let api_key = "your_api_key".to_string();
    let client = DeepSeekClientBuilder::new(api_key).build().unwrap();
    let models = client.models().await.unwrap();
    println!("{:?}", models);
}

For more information, see the DeepSeek API documentation.

Source

pub async fn balance(&self) -> Result<BalanceResp>

Retrieves the balance information of the user from the DeepSeek API.

This method sends a GET request to the /user/balance endpoint of the DeepSeek API and returns a Result containing a BalanceResp on success.

§Errors

This function will return an error if the request fails or if the response cannot be deserialized into a BalanceResp.

§Example
#[tokio::main]
async fn main() {
    use deepseek_api::DeepSeekClientBuilder;

    let api_key = "your_api_key".to_string();
    let client = DeepSeekClientBuilder::new(api_key).build().unwrap();
    let balance = client.balance().await.unwrap();
    println!("{:?}", balance);
}

For more information, see the DeepSeek API documentation.

Source

pub async fn send_completion_request<Builder>( &self, request_builder: Builder, ) -> Result<ChatResponse<Builder::Response, Builder::Item>>
where Builder: RequestBuilder + Send + Sized,

Sends a completion request to the DeepSeek API.

This method constructs a request using the provided RequestBuilder and sends it to the appropriate endpoint of the DeepSeek API. Depending on whether the request is for a beta feature or not, it will target either the /beta/completions or /chat/completions endpoint. The response can be either a full response or a streaming response, based on the stream optional of the RequestBuilder.

§Type Parameters
  • Builder - A type that implements the RequestBuilder trait, used to construct the request payload.
§Arguments
  • request_builder - An instance of a type implementing the RequestBuilder trait, which is used to build the request payload.
§Returns

A Result containing a ChatResponse on success. The ChatResponse can either be a full response or a streaming response, depending on the request.

§Errors

This function will return an error if:

  • The request fails to send.
  • The response contains an API error.
  • The response cannot be deserialized into the expected type.
§Example
#[tokio::main]
async fn main() {
    use deepseek_api::{request::MessageRequest, DeepSeekClientBuilder, CompletionsRequestBuilder};
    use deepseek_api::response::ChatResponse;
    use futures_util::StreamExt;

    let api_key = "your_api_key".to_string();
    let client = DeepSeekClientBuilder::new(api_key).build().unwrap();
    let msgs = &[MessageRequest::user("Hello, DeepSeek!")];
    let request_builder = CompletionsRequestBuilder::new(msgs);

    let response = client.send_completion_request(request_builder).await.unwrap();
    match response {
        ChatResponse::Full(full_response) => println!("{:?}", full_response),
        ChatResponse::Stream(mut stream) => {
            while let Some(item) = stream.next().await {
                println!("{:?}", item);
            }
        }
    }
}

For more information, see the DeepSeek API documentation.

Trait Implementations§

Source§

impl Clone for DeepSeekClient

Source§

fn clone(&self) -> DeepSeekClient

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

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

Performs copy-assignment from source. 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> 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