192 lines
4.1 KiB
Rust
192 lines
4.1 KiB
Rust
use serde::{Deserialize, Serialize};
|
|
use utoipa::ToSchema;
|
|
|
|
#[derive(Debug, Serialize, ToSchema)]
|
|
pub struct ErrorResponse {
|
|
pub error: String,
|
|
}
|
|
|
|
impl ErrorResponse {
|
|
pub fn new(msg: impl Into<String>) -> Self {
|
|
Self { error: msg.into() }
|
|
}
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct ModelsResponse {
|
|
pub models: Vec<ModelInfo>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct ModelInfo {
|
|
pub name: String,
|
|
pub family: Option<String>,
|
|
pub parameter_size: Option<String>,
|
|
pub quantization: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct LoadModelResponse {
|
|
pub model: String,
|
|
pub status: String,
|
|
pub keep_alive: String,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct LoadModelBody {
|
|
pub keep_alive: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct UnloadModelResponse {
|
|
pub model: String,
|
|
pub status: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, ToSchema, Default)]
|
|
pub struct BaseLLMRequest {
|
|
pub model: String,
|
|
|
|
#[serde(default)]
|
|
pub stream: bool,
|
|
|
|
pub temperature: Option<f32>,
|
|
pub top_p: Option<f32>,
|
|
|
|
// Ollama-native
|
|
pub top_k: Option<u32>,
|
|
pub repeat_penalty: Option<f32>,
|
|
pub seed: Option<i64>,
|
|
|
|
pub num_ctx: Option<u32>,
|
|
pub num_predict: Option<u32>,
|
|
|
|
pub stop: Option<Vec<String>>,
|
|
|
|
pub keep_alive: Option<String>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, ToSchema)]
|
|
pub struct CompletionRequest {
|
|
#[serde(flatten)]
|
|
pub base: BaseLLMRequest,
|
|
|
|
pub prompt: String,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum CompletionObject {
|
|
TextCompletion,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
|
|
#[serde(rename_all = "snake_case")]
|
|
pub enum FinishReason {
|
|
Stop,
|
|
Length,
|
|
ContentFilter,
|
|
ToolCalls,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct CompletionResponse {
|
|
pub id: String,
|
|
pub object: CompletionObject,
|
|
pub created: u64,
|
|
pub model: String,
|
|
pub choices: Vec<Choice>,
|
|
pub usage: Usage,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct Choice {
|
|
pub text: String,
|
|
pub index: u32,
|
|
pub finish_reason: FinishReason,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct Usage {
|
|
pub prompt_tokens: u32,
|
|
pub completion_tokens: u32,
|
|
pub total_tokens: u32,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct CompletionChunk {
|
|
pub id: String,
|
|
pub object: String,
|
|
pub choices: Vec<Choice>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, ToSchema)]
|
|
pub struct ChatRequest {
|
|
#[serde(flatten)]
|
|
pub base: BaseLLMRequest,
|
|
|
|
pub messages: Vec<Message>,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, ToSchema)]
|
|
pub struct Message {
|
|
pub role: Role,
|
|
pub content: String,
|
|
}
|
|
|
|
#[derive(Debug, Deserialize, Serialize, ToSchema, PartialEq, Eq)]
|
|
#[serde(rename_all = "lowercase")]
|
|
pub enum Role {
|
|
System,
|
|
User,
|
|
Assistant,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct ChatCompletionResponse {
|
|
pub id: String,
|
|
pub object: String,
|
|
pub created: u64,
|
|
pub model: String,
|
|
pub choices: Vec<ChatChoice>,
|
|
pub usage: Option<Usage>, // optional (Ollama may not always provide)
|
|
}
|
|
|
|
#[derive(Debug, Serialize, Deserialize, ToSchema)]
|
|
pub struct ChatChoice {
|
|
pub index: u32,
|
|
pub message: Message,
|
|
pub finish_reason: FinishReason,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, ToSchema)]
|
|
pub struct ChatCompletionChunk {
|
|
pub id: String,
|
|
pub object: String,
|
|
pub choices: Vec<ChatChunkChoice>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, ToSchema)]
|
|
pub struct ChatChunkChoice {
|
|
pub index: u32,
|
|
pub delta: ChatDelta,
|
|
pub finish_reason: Option<FinishReason>,
|
|
}
|
|
|
|
#[derive(Debug, Serialize, ToSchema)]
|
|
pub struct ChatDelta {
|
|
pub role: Option<Role>,
|
|
pub content: Option<String>,
|
|
}
|
|
|
|
#[derive(serde::Deserialize)]
|
|
pub struct CreateApiKeyRequest {
|
|
pub name: String,
|
|
pub scopes: Vec<String>,
|
|
}
|
|
|
|
#[derive(serde::Serialize)]
|
|
pub struct CreateApiKeyResponse {
|
|
pub api_key: String, // ONLY returned once
|
|
}
|