CatPtain commited on
Commit
7254052
·
verified ·
1 Parent(s): 57af3f6

Update app/config/config.py

Browse files
Files changed (1) hide show
  1. app/config/config.py +7 -57
app/config/config.py CHANGED
@@ -4,49 +4,12 @@
4
 
5
  import datetime
6
  import json
7
- from typing import Annotated, Any, Dict, List, Type
8
 
9
- from pydantic import BeforeValidator, ValidationError, ValidationInfo, field_validator
10
  from pydantic_settings import BaseSettings
11
  from sqlalchemy import insert, select, update
12
 
13
-
14
- def parse_comma_separated_string(v: Any) -> List[str]:
15
- # Handle None or empty values
16
- if v is None or v == "":
17
- return []
18
-
19
- if isinstance(v, list):
20
- return [str(item).strip() for item in v if str(item).strip()]
21
-
22
- if isinstance(v, str):
23
- # Handle empty string or whitespace-only string
24
- if not v.strip():
25
- return []
26
-
27
- try:
28
- # Attempt to parse as JSON list first, in case it's provided as such
29
- parsed = json.loads(v)
30
- if isinstance(parsed, list):
31
- return [str(item).strip() for item in parsed if str(item).strip()]
32
- except json.JSONDecodeError:
33
- pass # Not a JSON string, proceed to comma split
34
-
35
- # Split by comma and filter out empty strings
36
- return [token.strip() for token in v.split(',') if token.strip()]
37
-
38
- # For any other type, try to convert to string and process
39
- try:
40
- str_val = str(v)
41
- if not str_val or str_val.strip() == "":
42
- return []
43
- return [token.strip() for token in str_val.split(',') if token.strip()]
44
- except Exception:
45
- return []
46
-
47
-
48
- CommaSeparatedList = Annotated[List[str], BeforeValidator(parse_comma_separated_string)]
49
-
50
  from app.core.constants import (
51
  API_VERSION,
52
  DEFAULT_CREATE_IMAGE_MODEL,
@@ -66,7 +29,7 @@ from app.log.logger import Logger
66
 
67
  class Settings(BaseSettings):
68
  # 数据库配置
69
- DATABASE_TYPE: str = "sqlite" # sqlite 或 mysql
70
  SQLITE_DATABASE: str = "default_db"
71
  MYSQL_HOST: str = ""
72
  MYSQL_PORT: int = 3306
@@ -88,15 +51,8 @@ class Settings(BaseSettings):
88
  return v
89
 
90
  # API相关配置
91
- API_KEYS: CommaSeparatedList
92
- ALLOWED_TOKENS: CommaSeparatedList = []
93
-
94
- @field_validator("API_KEYS")
95
- @classmethod
96
- def validate_api_keys(cls, v: List[str]) -> List[str]:
97
- if not v or len(v) == 0:
98
- raise ValueError("API_KEYS cannot be empty. Please provide at least one API key.")
99
- return v
100
  BASE_URL: str = f"https://generativelanguage.googleapis.com/{API_VERSION}"
101
  AUTH_TOKEN: str = ""
102
  MAX_FAILURES: int = 3
@@ -116,13 +72,6 @@ class Settings(BaseSettings):
116
  IMAGE_MODELS: List[str] = ["gemini-2.0-flash-exp"]
117
  FILTERED_MODELS: List[str] = DEFAULT_FILTER_MODELS
118
  TOOLS_CODE_EXECUTION_ENABLED: bool = False
119
-
120
- @field_validator("TOOLS_CODE_EXECUTION_ENABLED", mode="before")
121
- @classmethod
122
- def parse_boolean(cls, v: Any) -> bool:
123
- if isinstance(v, str):
124
- return v.lower() == "true"
125
- return v
126
  SHOW_SEARCH_LINK: bool = True
127
  SHOW_THINKING_PROCESS: bool = True
128
  THINKING_MODELS: List[str] = []
@@ -141,6 +90,7 @@ class Settings(BaseSettings):
141
  PICGO_API_KEY: str = ""
142
  CLOUDFLARE_IMGBED_URL: str = ""
143
  CLOUDFLARE_IMGBED_AUTH_CODE: str = ""
 
144
 
145
  # 流式输出优化器配置
146
  STREAM_OPTIMIZER_ENABLED: bool = False
@@ -527,4 +477,4 @@ async def sync_initial_settings():
527
  except Exception as e:
528
  logger.error(f"Error disconnecting database after initial sync: {e}")
529
 
530
- logger.info("Initial settings synchronization finished.")
 
4
 
5
  import datetime
6
  import json
7
+ from typing import Any, Dict, List, Type
8
 
9
+ from pydantic import ValidationError, ValidationInfo, field_validator
10
  from pydantic_settings import BaseSettings
11
  from sqlalchemy import insert, select, update
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  from app.core.constants import (
14
  API_VERSION,
15
  DEFAULT_CREATE_IMAGE_MODEL,
 
29
 
30
  class Settings(BaseSettings):
31
  # 数据库配置
32
+ DATABASE_TYPE: str = "mysql" # sqlite 或 mysql
33
  SQLITE_DATABASE: str = "default_db"
34
  MYSQL_HOST: str = ""
35
  MYSQL_PORT: int = 3306
 
51
  return v
52
 
53
  # API相关配置
54
+ API_KEYS: List[str]
55
+ ALLOWED_TOKENS: List[str]
 
 
 
 
 
 
 
56
  BASE_URL: str = f"https://generativelanguage.googleapis.com/{API_VERSION}"
57
  AUTH_TOKEN: str = ""
58
  MAX_FAILURES: int = 3
 
72
  IMAGE_MODELS: List[str] = ["gemini-2.0-flash-exp"]
73
  FILTERED_MODELS: List[str] = DEFAULT_FILTER_MODELS
74
  TOOLS_CODE_EXECUTION_ENABLED: bool = False
 
 
 
 
 
 
 
75
  SHOW_SEARCH_LINK: bool = True
76
  SHOW_THINKING_PROCESS: bool = True
77
  THINKING_MODELS: List[str] = []
 
90
  PICGO_API_KEY: str = ""
91
  CLOUDFLARE_IMGBED_URL: str = ""
92
  CLOUDFLARE_IMGBED_AUTH_CODE: str = ""
93
+ CLOUDFLARE_IMGBED_UPLOAD_FOLDER: str = ""
94
 
95
  # 流式输出优化器配置
96
  STREAM_OPTIMIZER_ENABLED: bool = False
 
477
  except Exception as e:
478
  logger.error(f"Error disconnecting database after initial sync: {e}")
479
 
480
+ logger.info("Initial settings synchronization finished.")