oxirs_embed/api/
config.rs1#[cfg(feature = "api-server")]
7use crate::{CacheManager, EmbeddingModel, ModelRegistry};
8use std::collections::HashMap;
9use std::sync::Arc;
10use tokio::sync::RwLock;
11use uuid::Uuid;
12
13#[derive(Clone)]
15pub struct ApiState {
16 pub registry: Arc<ModelRegistry>,
18 pub cache_manager: Arc<CacheManager>,
20 pub models: Arc<RwLock<HashMap<Uuid, Arc<dyn EmbeddingModel + Send + Sync>>>>,
22 pub config: ApiConfig,
24}
25
26#[derive(Debug, Clone)]
28pub struct ApiConfig {
29 pub host: String,
31 pub port: u16,
33 pub timeout_seconds: u64,
35 pub request_timeout_secs: u64,
37 pub max_batch_size: usize,
39 pub rate_limit: RateLimitConfig,
41 pub auth: AuthConfig,
43 pub enable_logging: bool,
45 pub enable_cors: bool,
47}
48
49impl Default for ApiConfig {
50 fn default() -> Self {
51 Self {
52 host: "0.0.0.0".to_string(),
53 port: 8080,
54 timeout_seconds: 30,
55 request_timeout_secs: 30,
56 max_batch_size: 1000,
57 rate_limit: RateLimitConfig::default(),
58 auth: AuthConfig::default(),
59 enable_logging: true,
60 enable_cors: true,
61 }
62 }
63}
64
65#[derive(Debug, Clone)]
67pub struct RateLimitConfig {
68 pub requests_per_minute: u32,
70 pub enabled: bool,
72}
73
74impl Default for RateLimitConfig {
75 fn default() -> Self {
76 Self {
77 requests_per_minute: 1000,
78 enabled: true,
79 }
80 }
81}
82
83#[derive(Debug, Clone, Default)]
85pub struct AuthConfig {
86 pub require_api_key: bool,
88 pub api_keys: Vec<String>,
90 pub enable_jwt: bool,
92 pub jwt_secret: Option<String>,
94}