| use serde::{Deserialize, Serialize}; |
|
|
| |
| #[derive(Debug, Clone, Serialize, Deserialize)] |
| pub struct ProxyConfig { |
| |
| pub enabled: bool, |
|
|
| |
| |
| |
| #[serde(default)] |
| pub allow_lan_access: bool, |
|
|
| |
| pub port: u16, |
|
|
| |
| pub api_key: String, |
|
|
| |
| pub auto_start: bool, |
|
|
| |
| #[serde(default)] |
| pub anthropic_mapping: std::collections::HashMap<String, String>, |
|
|
| |
| #[serde(default)] |
| pub openai_mapping: std::collections::HashMap<String, String>, |
|
|
| |
| #[serde(default)] |
| pub custom_mapping: std::collections::HashMap<String, String>, |
|
|
| |
| #[serde(default = "default_request_timeout")] |
| pub request_timeout: u64, |
|
|
| |
| #[serde(default)] |
| pub upstream_proxy: UpstreamProxyConfig, |
| } |
|
|
| |
| #[derive(Debug, Clone, Serialize, Deserialize, Default)] |
| pub struct UpstreamProxyConfig { |
| |
| pub enabled: bool, |
| |
| pub url: String, |
| } |
|
|
| impl Default for ProxyConfig { |
| fn default() -> Self { |
| Self { |
| enabled: false, |
| allow_lan_access: true, |
| port: 7860, |
| api_key: format!("sk-{}", uuid::Uuid::new_v4().simple()), |
| auto_start: true, |
| anthropic_mapping: std::collections::HashMap::new(), |
| openai_mapping: std::collections::HashMap::new(), |
| custom_mapping: std::collections::HashMap::new(), |
| request_timeout: default_request_timeout(), |
| upstream_proxy: UpstreamProxyConfig::default(), |
| } |
| } |
| } |
|
|
| fn default_request_timeout() -> u64 { |
| 120 |
| } |
|
|
| impl ProxyConfig { |
| |
| |
| |
| pub fn get_bind_address(&self) -> &str { |
| if self.allow_lan_access { |
| "0.0.0.0" |
| } else { |
| "127.0.0.1" |
| } |
| } |
| } |
|
|