deepinfra-client-rs

Crates.iodeepinfra-client-rs
lib.rsdeepinfra-client-rs
version0.1.1
created_at2025-02-20 18:25:25.64501+00
updated_at2025-03-05 18:20:12.948505+00
descriptionA Rust client for the Deepinfra API
homepagehttps://github.com/simoneromano96/deepinfra-client-rs
repositoryhttps://github.com/simoneromano96/deepinfra-client-rs
max_upload_size
id1562962
size60,531
Simone Romano (simoneromano96)

documentation

https://docs.rs/crate/deepinfra-client-rs/latest

README

deepinfra-client-rs

A Rust client for interacting with Deepinfra APIs including chat completions and audio transcriptions.

Overview

deepinfra-client-rs is a lightweight library that provides an easy way to communicate with Deepinfra's API endpoints for chat completions and audio transcriptions. It leverages popular crates like reqwest, serde, and tracing.

Features

  • Chat Completions: Supports generating completions using OpenAI's conversation style protocols.
  • Audio Transcriptions: Enables conversion of audio files to text.
  • Modular Design: Separated modules for chat completions, audio transcriptions, client building, and feature prelude.

Installation

Add the following dependency to your Cargo.toml:

[dependencies]
deepinfra-client-rs = "0.0.1"

Or clone the repository from GitHub and build the project using Cargo.

Usage

Import the required modules:

// ...existing code...
use deepinfra_client_rs::prelude::*;
// ...existing code...

Initialize the client:

// ...existing code...
let client = DeepinfraClient::new("your_token")?;
// ...existing code...

Check out the individual modules for detailed usage examples:

  • chat_completition: For managing chat conversations.
  • audio_transcription: For handling audio transcription requests.

Advanced Usage

Below are quick examples to show how to perform chat completions and audio transcriptions.

Chat Completions

use deepinfra_client_rs::prelude::*;
// ...existing code...

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DeepinfraClient::new("your_token")?;
    let request = ChatCompletionRequestBuilder::default()
        .messages(vec![
            // Build your messages here...
        ])
        .build()
        .expect("Failed to build ChatCompletionRequest");

    let response = client.chat_completition(request).await?;
    println!("{:#?}", response);
    Ok(())
}

Audio Transcriptions

use deepinfra_client_rs::prelude::*;
use deepinfra_client_rs::audio_transcription::{ FileSource, AudioTranscriptionRequestBuilder };
// ...existing code...

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let client = DeepinfraClient::new("your_token")?;
    let transcription_request = AudioTranscriptionRequestBuilder::default()
        .source(FileSource::Filepath("/path/to/audio.wav".into()))
        .build()
        .expect("Failed to build AudioTranscriptionRequest");

    let response = client.audio_transcription(transcription_request).await?;
    println!("Transcribed text: {}", response.text);
    Ok(())
}
Commit count: 9

cargo fmt