Update to latest Mistral AI API (v1.0.0)
- Replace closed Model enum with flexible string-based Model type with constructor methods for all current models (Mistral Large 3, Small 4, Magistral, Codestral, Devstral, Pixtral, Voxtral, etc.) - Add new API endpoints: FIM completions, Files, Fine-tuning, Batch jobs, OCR, Audio transcription, Moderations/Classifications, and Agent completions (sync + async for all) - Add new chat fields: frequency_penalty, presence_penalty, stop, n, parallel_tool_calls, reasoning_effort, min_tokens, json_schema response format - Add embedding fields: output_dimension, output_dtype - Tool parameters now accept raw JSON Schema (serde_json::Value) instead of limited enum types - Add tool call IDs and Required tool choice variant - Add DELETE HTTP method support and multipart file upload - Bump thiserror to v2, add reqwest multipart feature - Remove strum dependency (no longer needed) - Update all tests and examples for new API
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::from_str;
|
||||
|
||||
use crate::v1::{chat, common, constants, error};
|
||||
use crate::v1::{chat, common, constants, error, tool};
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Response
|
||||
@@ -11,12 +11,11 @@ pub struct ChatStreamChunk {
|
||||
pub id: String,
|
||||
pub object: String,
|
||||
/// Unix timestamp (in seconds).
|
||||
pub created: u32,
|
||||
pub created: u64,
|
||||
pub model: constants::Model,
|
||||
pub choices: Vec<ChatStreamChunkChoice>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub usage: Option<common::ResponseUsage>,
|
||||
// TODO Check this prop (seen in API responses but undocumented).
|
||||
// pub logprobs: ???,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
@@ -24,14 +23,15 @@ pub struct ChatStreamChunkChoice {
|
||||
pub index: u32,
|
||||
pub delta: ChatStreamChunkChoiceDelta,
|
||||
pub finish_reason: Option<String>,
|
||||
// TODO Check this prop (seen in API responses but undocumented).
|
||||
// pub logprobs: ???,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct ChatStreamChunkChoiceDelta {
|
||||
pub role: Option<chat::ChatMessageRole>,
|
||||
pub content: String,
|
||||
#[serde(default)]
|
||||
pub content: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tool_calls: Option<Vec<tool::ToolCall>>,
|
||||
}
|
||||
|
||||
/// Extracts serialized chunks from a stream message.
|
||||
@@ -47,7 +47,6 @@ pub fn get_chunk_from_stream_message_line(
|
||||
return Ok(Some(vec![]));
|
||||
}
|
||||
|
||||
// Attempt to deserialize the JSON string into ChatStreamChunk
|
||||
match from_str::<ChatStreamChunk>(chunk_as_json) {
|
||||
Ok(chunk) => Ok(Some(vec![chunk])),
|
||||
Err(e) => Err(error::ApiError {
|
||||
|
||||
Reference in New Issue
Block a user