Skip to content

Commit f6366f6

Browse files
committed
feat: support use lowercase boolean parameter in environment variables
1 parent 176de1a commit f6366f6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

backend/common/core/config.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
BeforeValidator,
77
PostgresDsn,
88
computed_field,
9+
field_validator
910
)
1011
from pydantic_core import MultiHostUrl
1112
from pydantic_settings import BaseSettings, SettingsConfigDict
@@ -113,5 +114,23 @@ def SQLALCHEMY_DATABASE_URI(self) -> PostgresDsn | str:
113114

114115
ORACLE_CLIENT_PATH: str = '/opt/sqlbot/db_client/oracle_instant_client'
115116

117+
@field_validator('SQL_DEBUG',
118+
'EMBEDDING_ENABLED',
119+
'GENERATE_SQL_QUERY_LIMIT_ENABLED',
120+
'PARSE_REASONING_BLOCK_ENABLED',
121+
'PG_POOL_PRE_PING',
122+
'TABLE_EMBEDDING_ENABLED',
123+
mode='before')
124+
@classmethod
125+
def lowercase_bool(cls, v: Any) -> Any:
126+
"""将字符串形式的布尔值转换为Python布尔值"""
127+
if isinstance(v, str):
128+
v_lower = v.lower().strip()
129+
if v_lower == 'true':
130+
return True
131+
elif v_lower == 'false':
132+
return False
133+
return v
134+
116135

117136
settings = Settings() # type: ignore

0 commit comments

Comments
 (0)