openai-interface 0.10.0

A low-level Rust interface for the OpenAI API
Documentation
//! Turn audio into text or text into audio.
//!
//! Submodules: `speech` (text-to-speech, binary response),
//! `transcriptions` (speech-to-text in the input language), and
//! `translations` (speech-to-English). Streaming transcriptions (`stream`)
//! and `stream_format` audio streaming are not supported yet.
//!
//! > ![warn] The endpoints in this module are untested!
//! > No OpenAI-compatible provider accessible to this project (DeepSeek,
//! > Alibaba Cloud Model Studio) implements the `/audio/*` endpoints, and
//! > no OpenAI API key was available for testing. If you encounter any
//! > issues, please report them on the repository.

pub mod speech;
pub mod transcriptions;
pub mod translations;

use serde::Serialize;

/// The format of the transcription/translation output, in one of these
/// options: `json`, `text`, `srt`, `verbose_json`, or `vtt`.
///
/// `diarized_json` (for `gpt-4o-transcribe-diarize`) is not covered by this
/// type yet; pass it through the request's `extra_body`-style escape hatch
/// if needed.
#[derive(Debug, Serialize, Clone, Copy, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum AudioResponseFormat {
    Json,
    Text,
    Srt,
    VerboseJson,
    Vtt,
}

/// Serializes a unit-variant enum value to its bare string literal, e.g.
/// `Json` -> `"json"`. Used for multipart text fields.
pub(super) fn enum_to_literal<T: Serialize>(value: &T) -> Result<String, crate::errors::OapiError> {
    serde_json::to_string(value)
        .map(|json| json.trim_matches('"').to_string())
        .map_err(|e| {
            crate::errors::OapiError::ResponseError(format!("Failed to serialize field: {e}"))
        })
}