clia_deepseek_rs

Crates.ioclia_deepseek_rs
lib.rsclia_deepseek_rs
version0.1.4
created_at2025-03-04 07:27:07.590624+00
updated_at2025-03-04 07:27:07.590624+00
descriptionA Rust client library for the DeepSeek API (use rustls)
homepage
repositoryhttps://github.com/clia-mod/deepseek_rs
max_upload_size
id1576845
size87,117
clia (clia)

documentation

README

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.

Commit count: 25

cargo fmt