use chrono::{DateTime, Utc};
use serde;
use serde_json::Value;
use std::collections::HashMap;
use std::fmt;
use uuid::Uuid;
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct UserInfo {
pub id: String,
pub name: String,
pub api_key: String,
pub perm_superuser: bool,
pub perm_load_llm: bool,
pub perm_unload_llm: bool,
pub perm_download_llm: bool,
pub perm_session: bool, pub perm_request_download: bool,
pub perm_request_load: bool,
pub perm_request_unload: bool,
pub perm_view_llms: bool,
pub perm_bare_model: bool,
}
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum CapabilityType {
General,
Assistant,
Writing,
Coding,
}
#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct LLMStatus {
pub id: String,
pub family_id: String,
pub organization: String,
pub name: String,
pub homepage: String,
pub license: String,
pub description: String,
pub capabilities: HashMap<CapabilityType, i32>,
pub requirements: String,
pub tags: Vec<String>,
pub url: String,
pub local: bool,
pub connector_type: String,
pub download_progress: f32,
pub config: HashMap<String, Value>,
pub parameters: HashMap<String, Value>, pub user_parameters: Vec<String>, pub session_parameters: HashMap<String, Value>, pub user_session_parameters: Vec<String>, pub uuid: String, pub running: bool,
}
#[derive(serde::Deserialize, serde::Serialize, Debug)]
pub struct LLMRunningStatus {
pub llm_info: LLMStatus,
pub uuid: String,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct DownloadRequest {
pub llm_registry_entry: LLMRegistryEntry,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct PermissionRequest {
pub requested_permissions: UserPermissions,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct LoadRequest {
pub llm_id: String,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct UnloadRequest {
pub llm_id: String,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(tag = "type")]
pub enum UserRequestType {
DownloadRequest(DownloadRequest),
PermissionRequest(PermissionRequest),
LoadRequest(LoadRequest),
UnloadRequest(UnloadRequest),
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct UserRequestStatus {
pub id: Uuid,
pub user_id: Uuid,
pub timestamp: DateTime<Utc>,
pub request: UserRequestType,
pub accepted: bool,
pub complete: bool,
}
#[derive(Clone, serde::Deserialize, serde::Serialize, Debug)]
pub struct LLMEvent {
pub stream_id: Uuid,
pub timestamp: DateTime<Utc>,
pub call_timestamp: DateTime<Utc>,
pub parameters: HashMap<String, Value>,
pub input: String,
pub llm_uuid: Uuid,
pub session: LLMSessionStatus,
pub event: LLMEventInternal,
}
#[derive(Clone, serde::Deserialize, serde::Serialize, Debug)]
#[serde(tag = "type")]
pub enum LLMEventInternal {
PromptProgress { previous: String, next: String }, PromptCompletion { previous: String }, PromptError { message: String },
Other,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct UserPermissions {
pub perm_superuser: bool,
pub perm_load_llm: bool,
pub perm_unload_llm: bool,
pub perm_download_llm: bool,
pub perm_session: bool, pub perm_request_download: bool,
pub perm_request_load: bool,
pub perm_request_unload: bool,
pub perm_view_llms: bool,
pub perm_bare_model: bool,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct LLMSessionStatus {
pub id: Uuid, pub llm_uuid: Uuid,
pub user_id: Uuid,
pub started: DateTime<Utc>,
pub last_called: DateTime<Utc>,
pub session_parameters: HashMap<String, Value>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct LLMRegistryEntry {
pub id: String,
pub family_id: String,
pub organization: String,
pub name: String,
pub license: String,
pub description: String,
pub homepage: String,
pub capabilities: HashMap<String, i32>,
pub tags: Vec<String>,
pub requirements: String,
#[serde(default)]
pub backend_uuid: String,
pub url: String,
pub config: HashMap<String, Value>,
pub local: bool,
pub connector_type: LLMConnectorType,
pub parameters: HashMap<String, Value>,
pub user_parameters: Vec<String>,
pub session_parameters: HashMap<String, Value>,
pub user_session_parameters: Vec<String>,
}
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
#[serde(rename_all = "lowercase")]
pub enum LLMConnectorType {
GenericAPI,
LLMrs,
OpenAI,
}
impl fmt::Display for LLMConnectorType {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
LLMConnectorType::GenericAPI => write!(f, "GenericAPI"),
LLMConnectorType::LLMrs => write!(f, "LLMrs"),
LLMConnectorType::OpenAI => write!(f, "OpenAI"),
}
}
}