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
impl DeepSeekClient
Sourcepub async fn models(&self) -> Result<ModelResp>
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.
Sourcepub async fn balance(&self) -> Result<BalanceResp>
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.
Sourcepub async fn send_completion_request<Builder>(
&self,
request_builder: Builder,
) -> Result<ChatResponse<Builder::Response, Builder::Item>>
pub async fn send_completion_request<Builder>( &self, request_builder: Builder, ) -> Result<ChatResponse<Builder::Response, Builder::Item>>
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 theRequestBuilder
trait, used to construct the request payload.
§Arguments
request_builder
- An instance of a type implementing theRequestBuilder
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
impl Clone for DeepSeekClient
Source§fn clone(&self) -> DeepSeekClient
fn clone(&self) -> DeepSeekClient
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more