BREAKING CHANGE: Model is now a string-based struct with constructor methods instead of a closed enum. EmbedModel is removed — use Model::mistral_embed() instead. Tool parameters now accept serde_json::Value (JSON Schema) instead of limited enum types. - Replace Model enum with flexible Model(String) supporting all current models: Large 3, Small 4, Medium 3.1, Magistral, Codestral, Devstral, Pixtral, Voxtral, Ministral, and arbitrary strings - Remove EmbedModel enum (consolidated into Model) - Chat: add frequency_penalty, presence_penalty, stop, n, min_tokens, parallel_tool_calls, reasoning_effort, json_schema response format - Embeddings: add output_dimension and output_dtype fields - Tools: accept raw JSON Schema, add tool call IDs and Required choice - Stream delta content is now Option<String> for tool call chunks - Add Length, ModelLength, Error finish reason variants - DRY HTTP transport with shared response handlers - Add DELETE method support and model get/delete endpoints - Make model_list fields more lenient with Option/default for API compat
87 lines
2.3 KiB
Rust
87 lines
2.3 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
|
|
use crate::v1::{common, constants};
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Request
|
|
|
|
#[derive(Debug)]
|
|
pub struct EmbeddingRequestOptions {
|
|
pub encoding_format: Option<EmbeddingRequestEncodingFormat>,
|
|
pub output_dimension: Option<u32>,
|
|
pub output_dtype: Option<EmbeddingOutputDtype>,
|
|
}
|
|
impl Default for EmbeddingRequestOptions {
|
|
fn default() -> Self {
|
|
Self {
|
|
encoding_format: None,
|
|
output_dimension: None,
|
|
output_dtype: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
pub struct EmbeddingRequest {
|
|
pub model: constants::Model,
|
|
pub input: Vec<String>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub encoding_format: Option<EmbeddingRequestEncodingFormat>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub output_dimension: Option<u32>,
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
pub output_dtype: Option<EmbeddingOutputDtype>,
|
|
}
|
|
impl EmbeddingRequest {
|
|
pub fn new(
|
|
model: constants::Model,
|
|
input: Vec<String>,
|
|
options: Option<EmbeddingRequestOptions>,
|
|
) -> Self {
|
|
let opts = options.unwrap_or_default();
|
|
|
|
Self {
|
|
model,
|
|
input,
|
|
encoding_format: opts.encoding_format,
|
|
output_dimension: opts.output_dimension,
|
|
output_dtype: opts.output_dtype,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum EmbeddingRequestEncodingFormat {
|
|
Float,
|
|
Base64,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum EmbeddingOutputDtype {
|
|
Float,
|
|
Int8,
|
|
Uint8,
|
|
Binary,
|
|
Ubinary,
|
|
}
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Response
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct EmbeddingResponse {
|
|
pub object: String,
|
|
pub model: constants::Model,
|
|
pub data: Vec<EmbeddingResponseDataItem>,
|
|
pub usage: common::ResponseUsage,
|
|
}
|
|
|
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
|
pub struct EmbeddingResponseDataItem {
|
|
pub index: u32,
|
|
pub embedding: Vec<f32>,
|
|
pub object: String,
|
|
}
|