5 releases
new 0.1.4 | Jan 28, 2025 |
---|---|
0.1.3 | Jan 26, 2025 |
0.1.2 | Jan 25, 2025 |
0.1.1 | Jan 25, 2025 |
0.1.0 | Jan 25, 2025 |
#254 in Asynchronous
283 downloads per month
40KB
900 lines
DeepSeek Rust Client
A Rust client library for the DeepSeek API.
Features
- Fully async Rust implementation with
tokio
- Type-safe chat completions API
- Ergonomic builder pattern for requests
- Comprehensive error handling using Rust's
Result
type - First-class
serde
serialization support
Installation
Add this to your Cargo.toml
:
[dependencies]
deepseek_rs = "0.1.2"
Usage
Here's a basic example of how to use the DeepSeek Rust client:
use deepseek::client::Client;
#[tokio::main]
async fn main() {
let client = Client::new("your_api_key");
let request = RequestBody::new_messages(
vec![Message::new_user_message("Hello".to_string())]
);
let response = client.chat_completion(request).await.unwrap();
println!("{}", response);
}
Examples
Basic Usage
use deepseek_rs::{DeepSeekClient, client::chat_completions::request::{Message, RequestBody}};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = DeepSeekClient::default()?;
let request = RequestBody::new_messages(vec![
Message::new_user_message("Hello".to_string())
]);
let response = client.chat_completions(request).await?;
println!("{}", response.choices[0].message.content.unwrap());
Ok(())
}
Using the Reasoning Model
use deepseek_rs::{
DeepSeekClient,
client::chat_completions::request::{Message, Model, RequestBody}
};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = DeepSeekClient::default()?;
let request = RequestBody::new_messages(vec![
Message::new_user_message("What is 15 * 7?".to_string())
])
.with_model(Model::DeepSeekReasoner);
let response = client.chat_completions(request).await?;
println!("Reasoning: {}", response.choices[0].message.reasoning_content.unwrap());
println!("Answer: {}", response.choices[0].message.content.unwrap());
Ok(())
}
For more examples, check out the examples directory.
Documentation
For more detailed information, please refer to the API documentation.
License
This project is licensed under the MIT License.
Dependencies
~8–20MB
~265K SLoC