feat: Add dbgpt client and add api v2

This commit is contained in:
Fangyin Cheng
2024-03-18 18:24:08 +08:00
parent 4970c9f813
commit 0ed30aa44a
39 changed files with 2663 additions and 143 deletions

View File

@@ -16,7 +16,16 @@ class BaseServeConfig(BaseParameters):
config (AppConfig): Application configuration
config_prefix (str): Configuration prefix
"""
global_prefix = "dbgpt.app.global."
global_dict = config.get_all_by_prefix(global_prefix)
config_dict = config.get_all_by_prefix(config_prefix)
# remove prefix
config_dict = {k[len(config_prefix) :]: v for k, v in config_dict.items()}
config_dict = {
k[len(config_prefix) :]: v
for k, v in config_dict.items()
if k.startswith(config_prefix)
}
for k, v in global_dict.items():
if k not in config_dict and k[len(global_prefix) :] in cls().__dict__:
config_dict[k[len(global_prefix) :]] = v
return cls(**config_dict)

View File

@@ -69,11 +69,11 @@ async def validation_exception_handler(
async def http_exception_handler(request: Request, exc: HTTPException):
res = Result.failed(
msg=exc.detail,
err_code="E0002",
msg=str(exc.detail),
err_code=str(exc.status_code),
)
logger.error(f"http_exception_handler catch HTTPException: {res}")
return JSONResponse(status_code=400, content=res.dict())
return JSONResponse(status_code=exc.status_code, content=res.dict())
async def common_exception_handler(request: Request, exc: Exception) -> JSONResponse:

View File

@@ -18,7 +18,7 @@ class BaseServe(BaseComponent, ABC):
def __init__(
self,
system_app: SystemApp,
api_prefix: str,
api_prefix: str | List[str],
api_tags: List[str],
db_url_or_db: Union[str, URL, DatabaseManager] = None,
try_create_tables: Optional[bool] = False,