mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 11:42:29 +08:00
feat: Add program_name attribute to TiDB connection (#5499)
Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
This commit is contained in:
parent
756d9a4bc2
commit
13fcd7a901
|
@ -33,6 +33,7 @@ class Config:
|
|||
dotenv.load_dotenv()
|
||||
|
||||
self.TESTING = False
|
||||
self.APPLICATION_NAME = "langgenius/dify"
|
||||
|
||||
# cors settings
|
||||
self.CONSOLE_CORS_ALLOW_ORIGINS = get_cors_allow_origins(
|
||||
|
|
|
@ -26,6 +26,7 @@ class TiDBVectorConfig(BaseModel):
|
|||
user: str
|
||||
password: str
|
||||
database: str
|
||||
program_name: str
|
||||
|
||||
@model_validator(mode='before')
|
||||
def validate_config(cls, values: dict) -> dict:
|
||||
|
@ -39,6 +40,8 @@ class TiDBVectorConfig(BaseModel):
|
|||
raise ValueError("config TIDB_VECTOR_PASSWORD is required")
|
||||
if not values['database']:
|
||||
raise ValueError("config TIDB_VECTOR_DATABASE is required")
|
||||
if not values['program_name']:
|
||||
raise ValueError("config APPLICATION_NAME is required")
|
||||
return values
|
||||
|
||||
|
||||
|
@ -65,7 +68,7 @@ class TiDBVector(BaseVector):
|
|||
super().__init__(collection_name)
|
||||
self._client_config = config
|
||||
self._url = (f"mysql+pymysql://{config.user}:{config.password}@{config.host}:{config.port}/{config.database}?"
|
||||
f"ssl_verify_cert=true&ssl_verify_identity=true")
|
||||
f"ssl_verify_cert=true&ssl_verify_identity=true&program_name={config.program_name}")
|
||||
self._distance_func = distance_func.lower()
|
||||
self._engine = create_engine(self._url)
|
||||
self._orm_base = declarative_base()
|
||||
|
@ -245,5 +248,6 @@ class TiDBVectorFactory(AbstractVectorFactory):
|
|||
user=config.get('TIDB_VECTOR_USER'),
|
||||
password=config.get('TIDB_VECTOR_PASSWORD'),
|
||||
database=config.get('TIDB_VECTOR_DATABASE'),
|
||||
program_name=config.get('APPLICATION_NAME'),
|
||||
),
|
||||
)
|
|
@ -16,7 +16,8 @@ def tidb_vector():
|
|||
port="4000",
|
||||
user="xxx.root",
|
||||
password="xxxxxx",
|
||||
database="dify"
|
||||
database="dify",
|
||||
program_name="langgenius/dify"
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user