Spaces:
Paused
Paused
Update config_provider.py
Browse files- config_provider.py +16 -19
config_provider.py
CHANGED
|
@@ -1,20 +1,24 @@
|
|
| 1 |
"""
|
| 2 |
-
Flare –
|
| 3 |
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 4 |
-
• Global, Project, Version, Intent, API tanımları
|
| 5 |
-
• JSONC yorum temizleme (string literal’lere dokunmaz)
|
| 6 |
-
• Alias’lar (version_number, max_attempts vb.)
|
| 7 |
-
• apis[] artık liste → runtime’da dict’e map’lenir
|
| 8 |
"""
|
| 9 |
|
| 10 |
from __future__ import annotations
|
| 11 |
-
|
| 12 |
-
import json
|
| 13 |
from pathlib import Path
|
| 14 |
from typing import Any, Dict, List, Optional
|
| 15 |
|
| 16 |
-
from pydantic import BaseModel, Field, HttpUrl, ValidationError
|
| 17 |
from utils import log
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
# ---------------- Global -----------------
|
| 20 |
class UserConfig(BaseModel):
|
|
@@ -23,13 +27,6 @@ class UserConfig(BaseModel):
|
|
| 23 |
salt: str
|
| 24 |
|
| 25 |
|
| 26 |
-
class GlobalConfig(BaseModel):
|
| 27 |
-
work_mode: str = Field("hfcloud", pattern=r"^(hfcloud|cloud|on-premise)$")
|
| 28 |
-
cloud_token: Optional[str] = None
|
| 29 |
-
spark_endpoint: HttpUrl
|
| 30 |
-
users: List[UserConfig] = []
|
| 31 |
-
|
| 32 |
-
|
| 33 |
# ---------------- Retry / Proxy ----------
|
| 34 |
class RetryConfig(BaseModel):
|
| 35 |
retry_count: int = Field(3, alias="max_attempts")
|
|
@@ -115,10 +112,10 @@ class VersionConfig(BaseModel):
|
|
| 115 |
caption: Optional[str] = ""
|
| 116 |
published: bool = False
|
| 117 |
general_prompt: str
|
| 118 |
-
llm: LLMConfig
|
| 119 |
-
intents: List[IntentConfig]
|
| 120 |
|
| 121 |
-
class Config:
|
| 122 |
extra = "allow"
|
| 123 |
populate_by_name = True
|
| 124 |
|
|
|
|
| 1 |
"""
|
| 2 |
+
Flare – ConfigProvider (şifreli cloud_token desteği)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
"""
|
| 4 |
|
| 5 |
from __future__ import annotations
|
| 6 |
+
import json, os
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
from typing import Any, Dict, List, Optional
|
| 9 |
|
| 10 |
+
from pydantic import BaseModel, Field, HttpUrl, ValidationError
|
| 11 |
from utils import log
|
| 12 |
+
from encryption_utils import decrypt
|
| 13 |
+
|
| 14 |
+
class GlobalConfig(BaseModel):
|
| 15 |
+
work_mode: str = Field("hfcloud", pattern=r"^(hfcloud|cloud|on-premise)$")
|
| 16 |
+
cloud_token: Optional[str] = None
|
| 17 |
+
spark_endpoint: HttpUrl
|
| 18 |
+
users: List["UserConfig"] = []
|
| 19 |
+
|
| 20 |
+
def get_plain_token(self) -> Optional[str]:
|
| 21 |
+
return decrypt(self.cloud_token) if self.cloud_token else None
|
| 22 |
|
| 23 |
# ---------------- Global -----------------
|
| 24 |
class UserConfig(BaseModel):
|
|
|
|
| 27 |
salt: str
|
| 28 |
|
| 29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
# ---------------- Retry / Proxy ----------
|
| 31 |
class RetryConfig(BaseModel):
|
| 32 |
retry_count: int = Field(3, alias="max_attempts")
|
|
|
|
| 112 |
caption: Optional[str] = ""
|
| 113 |
published: bool = False
|
| 114 |
general_prompt: str
|
| 115 |
+
llm: "LLMConfig"
|
| 116 |
+
intents: List["IntentConfig"]
|
| 117 |
|
| 118 |
+
class Config:
|
| 119 |
extra = "allow"
|
| 120 |
populate_by_name = True
|
| 121 |
|