refactor!: modernize core types and client for latest Mistral API
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
This commit is contained in:
@@ -8,42 +8,63 @@ use crate::v1::{common, constants};
|
||||
#[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::EmbedModel,
|
||||
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::EmbedModel,
|
||||
model: constants::Model,
|
||||
input: Vec<String>,
|
||||
options: Option<EmbeddingRequestOptions>,
|
||||
) -> Self {
|
||||
let EmbeddingRequestOptions { encoding_format } = options.unwrap_or_default();
|
||||
let opts = options.unwrap_or_default();
|
||||
|
||||
Self {
|
||||
model,
|
||||
input,
|
||||
encoding_format,
|
||||
encoding_format: opts.encoding_format,
|
||||
output_dimension: opts.output_dimension,
|
||||
output_dtype: opts.output_dtype,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum EmbeddingRequestEncodingFormat {
|
||||
float,
|
||||
Float,
|
||||
Base64,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Deserialize, Serialize)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum EmbeddingOutputDtype {
|
||||
Float,
|
||||
Int8,
|
||||
Uint8,
|
||||
Binary,
|
||||
Ubinary,
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
@@ -51,9 +72,8 @@ pub enum EmbeddingRequestEncodingFormat {
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct EmbeddingResponse {
|
||||
pub id: String,
|
||||
pub object: String,
|
||||
pub model: constants::EmbedModel,
|
||||
pub model: constants::Model,
|
||||
pub data: Vec<EmbeddingResponseDataItem>,
|
||||
pub usage: common::ResponseUsage,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user