fix: streaming
CI / Rust CI (push) Successful in 5m19s

This commit is contained in:
2026-06-05 18:16:48 +02:00
parent 28352d8bdb
commit 77bd729d95
16 changed files with 408 additions and 385 deletions
+54 -54
View File
@@ -6,43 +6,43 @@ use uuid::Uuid;
// ------ Models ------
#[derive(Debug, Serialize, ToSchema)]
pub struct ModelInfo {
pub struct ApiModelInfo {
pub name: String,
pub family: Option<String>,
pub parameter_size: Option<String>,
pub metadata: ModelMetadata,
pub metadata: ApiModelMetadata,
}
#[derive(Debug, Clone, Default, Serialize, ToSchema)]
pub struct ModelMetadata {
pub struct ApiModelMetadata {
pub extra: HashMap<String, String>,
}
// ------ Endpoint: /models ------
#[derive(Debug, Serialize, ToSchema)]
pub struct ModelsResponse {
pub models: Vec<ModelInfo>,
pub struct ApiModelsResponse {
pub models: Vec<ApiModelInfo>,
}
// ------ Endpoint: /models/{model}/load ------
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct LoadModelResponse {
pub struct ApiLoadModelResponse {
pub model: String,
pub status: String,
pub keep_alive: String,
}
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct LoadModelRequest {
pub struct ApiLoadModelRequest {
pub keep_alive: String,
}
// ------ Endpoint: /models/{model}/unload ------
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct UnloadModelResponse {
pub struct ApiUnloadModelResponse {
pub model: String,
pub status: String,
}
@@ -50,7 +50,7 @@ pub struct UnloadModelResponse {
// ------ Completions ------
#[derive(Debug, Deserialize, Serialize, ToSchema, Default)]
pub struct LLMOptions {
pub struct ApiLlmOptions {
#[serde(default)]
pub stream: bool,
@@ -74,18 +74,18 @@ pub struct LLMOptions {
// ------ Endpoint: /completions ------
#[derive(Debug, Deserialize, Serialize, ToSchema)]
pub struct CompletionRequest {
pub struct ApiCompletionRequest {
#[serde(flatten)]
pub options: LLMOptions,
pub options: ApiLlmOptions,
pub model: String,
pub prompt: String,
}
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct CompletionResponse {
pub struct ApiCompletionResponse {
pub id: Uuid,
pub object: CompletionObject,
pub object: ApiCompletionObject,
pub created: String,
pub model: String,
pub choices: Vec<Choice>,
@@ -94,7 +94,7 @@ pub struct CompletionResponse {
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum CompletionObject {
pub enum ApiCompletionObject {
TextCompletion,
}
@@ -102,7 +102,7 @@ pub enum CompletionObject {
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum FinishReason {
pub enum ApiFinishReason {
Stop,
Length,
ContentFilter,
@@ -114,7 +114,7 @@ pub enum FinishReason {
pub struct Choice {
pub text: String,
pub index: u32,
pub finish_reason: FinishReason,
pub finish_reason: ApiFinishReason,
}
#[derive(Debug, Serialize, Deserialize, ToSchema, Clone, Copy)]
@@ -132,12 +132,12 @@ pub struct CompletionChunk {
}
#[derive(Debug, Deserialize, Serialize, ToSchema)]
pub struct ChatRequest {
pub struct ApiChatRequest {
#[serde(flatten)]
pub base: LLMOptions,
pub base: ApiLlmOptions,
pub model: String,
pub message: Message,
pub message: ApiMessage,
// Non standard Open AI
pub conversation_id: Option<Uuid>,
@@ -145,36 +145,36 @@ pub struct ChatRequest {
}
#[derive(Debug, Deserialize, Serialize, ToSchema)]
pub struct Message {
pub role: Role,
pub struct ApiMessage {
pub role: ApiRole,
pub content: String,
}
#[derive(Debug, Deserialize, Serialize, ToSchema, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum Role {
pub enum ApiRole {
System,
User,
Assistant,
}
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct ChatResponse {
pub id: String,
pub object: String,
pub created: u64,
pub struct ApiChatResponse {
pub id: Uuid,
pub object: ApiCompletionObject,
pub created: String,
pub model: String,
pub choices: Vec<ChatChoice>,
pub choices: Vec<ApiChatChoice>,
pub usage: Usage,
pub conversation_id: Uuid,
}
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct ChatChoice {
pub struct ApiChatChoice {
pub index: u32,
pub message: Message,
pub finish_reason: FinishReason,
pub message: ApiMessage,
pub finish_reason: ApiFinishReason,
}
#[derive(Debug, Serialize, Deserialize, ToSchema)]
@@ -189,39 +189,39 @@ pub struct ChatCompletionChunk {
pub struct ChatChunkChoice {
pub index: u32,
pub delta: Delta,
pub finish_reason: Option<FinishReason>,
pub finish_reason: Option<ApiFinishReason>,
}
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct Delta {
pub content: Option<String>,
pub role: Option<Role>,
pub role: Option<ApiRole>,
}
// #[derive(Debug, Serialize, Deserialize, ToSchema)]
// pub struct StartEventData {
// pub conversation_id: Uuid,
// pub created: u64,
// pub id: Uuid,
// }
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct StartEventData {
pub conversation_id: Uuid,
pub created: u64,
pub id: Uuid,
}
// #[derive(Debug, Serialize, Deserialize, ToSchema)]
// pub struct EndEventData {
// pub created: u64,
// pub id: Uuid,
// pub usage: Usage,
// }
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct EndEventData {
pub created: u64,
pub id: Uuid,
pub usage: Usage,
}
// #[derive(Debug, Serialize, Deserialize, ToSchema)]
// #[serde(tag = "type", content = "data")]
// pub enum StreamEvent {
// #[serde(rename = "start")]
// Start(StartEventData),
// #[serde(rename = "end")]
// End(EndEventData),
// #[serde(rename = "delta")]
// Delta(ChatCompletionChunk),
// }
#[derive(Debug, Serialize, Deserialize, ToSchema)]
#[serde(tag = "type", content = "data")]
pub enum StreamEvent {
#[serde(rename = "start")]
Start(StartEventData),
#[serde(rename = "end")]
End(EndEventData),
#[serde(rename = "delta")]
Delta(ChatCompletionChunk),
}
// ------ Api Key ------