use serde::{Deserialize, Serialize};
pub mod ollama_model {
pub const LLAMA3: &str = "llama3:latest";
pub const LLAMA3_8B: &str = "llama3:8b";
pub const LLAMA3_1_8B: &str = "llama3.1:8b";
pub const PHI3_MINI: &str = "phi3:latest";
pub const CODESTRAL: &str = "codestral:latest";
}
pub mod ollama_embedding_model {
pub const NOMIC_EMBED_TEXT: &str = "nomic-embed-text:latest";
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaApiModelsMetadata {
pub models: Vec<OllamaApiModelMetadata>,
}
#[allow(dead_code)]
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaApiModelMetadata {
pub name: String,
pub model: String,
pub size: usize,
pub digest: String,
pub expires_at: Option<String>,
pub details: OllamaApiModelDetails,
}
#[allow(dead_code)]
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaApiModelDetails {
pub parent_model: String,
pub format: String,
pub family: String,
pub parameter_size: String,
pub quantization_level: String,
}
#[allow(dead_code)]
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaGenerateRequest {
pub model: String,
pub prompt: String,
pub context: Option<Vec<i64>>,
pub images: Option<Vec<String>>,
pub format: Option<String>,
pub stream: Option<bool>,
pub system: Option<String>,
pub keep_alive: Option<String>,
}
impl Default for OllamaGenerateRequest {
fn default() -> Self {
Self {
model: ollama_model::CODESTRAL.to_string(),
prompt: "".to_string(),
stream: Some(false),
format: None,
images: None,
system: Some("You are a helpful assistant".to_string()),
keep_alive: Some("5m".to_string()),
context: None,
}
}
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OllamaGenerateResponse {
Success(OllamaGenerateResponseSuccess),
Error(OllamaGenerateResponseError),
}
#[derive(Debug, Serialize, Deserialize)]
#[allow(dead_code)]
pub struct OllamaGenerateResponseSuccess {
pub model: String,
pub created_at: String,
pub response: String,
pub context: Option<Vec<i64>>,
pub total_duration: usize,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaGenerateResponseError {
pub error: String,
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum OllamaGenerateStreamItemResponse {
Success(OllamaGenerateStreamItemResponseSuccess),
Error(OllamaGenerateStreamItemResponseError),
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaGenerateStreamItemResponseSuccess {
pub model: String,
pub created_at: String,
pub response: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaGenerateStreamItemResponseError {
pub error: String,
}
#[allow(dead_code)]
#[derive(Debug, Serialize, Deserialize, Default)]
pub struct OllamaEmbeddingsRequest {
pub prompt: String,
pub model: String,
}
#[allow(dead_code)]
#[derive(Debug, Serialize, Deserialize)]
pub struct OllamaEmbeddingsResponse {
pub embedding: Vec<f32>,
}