From d6286c5d43fa9b5197899156836ce7fdb08ec3b3 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Tue, 2 Dec 2025 17:49:55 +0800 Subject: [PATCH] fix: package error --- backend/apps/chat/curd/chat.py | 3 +- backend/apps/system/crud/assistant.py | 40 ++++++++++++--------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/backend/apps/chat/curd/chat.py b/backend/apps/chat/curd/chat.py index b003204f..f6dafb44 100644 --- a/backend/apps/chat/curd/chat.py +++ b/backend/apps/chat/curd/chat.py @@ -1,5 +1,4 @@ import datetime -from idlelib.pyparse import trans from typing import List from sqlalchemy import desc, func @@ -399,7 +398,7 @@ def create_chat(session: SessionDep, current_user: CurrentUser, create_chat_obj: ds = session.get(CoreDatasource, create_chat_obj.datasource) if not ds: - raise Exception(trans('i18n_data_training.datasource_id_not_found', key=create_chat_obj.datasource)) + raise Exception(f"Datasource with id {create_chat_obj.datasource} not found") chat.engine_type = ds.type_name else: diff --git a/backend/apps/system/crud/assistant.py b/backend/apps/system/crud/assistant.py index ff9a1d48..1f1e5ec6 100644 --- a/backend/apps/system/crud/assistant.py +++ b/backend/apps/system/crud/assistant.py @@ -1,7 +1,6 @@ import json import re import urllib -from idlelib.pyparse import trans from typing import Optional import requests @@ -117,8 +116,7 @@ def get_ds_from_api(self): endpoint: str = config['endpoint'] endpoint = self.get_complete_endpoint(endpoint=endpoint) if not endpoint: - raise Exception( - f"Failed to get datasource list from {config['endpoint']}, error: [Assistant domain or endpoint miss]") + raise Exception(f"Failed to get datasource list from {config['endpoint']}, error: [Assistant domain or endpoint miss]") certificateList: list[any] = json.loads(self.certificate) header = {} cookies = {} @@ -145,12 +143,12 @@ def get_ds_from_api(self): raise Exception(f"Failed to get datasource list from {endpoint}, error: {result_json.get('message')}") else: raise Exception(f"Failed to get datasource list from {endpoint}, status code: {res.status_code}") - + def get_first_element(self, text: str): parts = re.split(r'[,;]', text.strip()) first_domain = parts[0].strip() return first_domain - + def get_complete_endpoint(self, endpoint: str) -> str | None: if endpoint.startswith("http://") or endpoint.startswith("https://"): return endpoint @@ -158,12 +156,10 @@ def get_complete_endpoint(self, endpoint: str) -> str | None: if not domain_text: return None if ',' in domain_text or ';' in domain_text: - return ( - self.request_origin.strip('/') if self.request_origin else self.get_first_element(domain_text).strip( - '/')) + endpoint + return (self.request_origin.strip('/') if self.request_origin else self.get_first_element(domain_text).strip('/')) + endpoint else: - return f"{domain_text}{endpoint}" - + return f"{domain_text}{endpoint}" + def get_simple_ds_list(self): if self.ds_list: return [{'id': ds.id, 'name': ds.name, 'description': ds.comment} for ds in self.ds_list] @@ -215,8 +211,8 @@ def get_ds(self, ds_id: int): if ds.id == ds_id: return ds else: - raise Exception(trans('i18n_data_training.datasource_list_is_not_found')) - raise Exception(trans('i18n_data_training.datasource_id_not_found', key=ds_id)) + raise Exception("Datasource list is not found.") + raise Exception(f"Datasource with id {ds_id} not found.") def convert2schema(self, ds_dict: dict, config: dict[any]) -> AssistantOutDsSchema: id_marker: str = '' @@ -279,17 +275,17 @@ def get_ds_engine(ds: AssistantOutDsSchema) -> Engine: return engine -def get_out_ds_conf(ds: AssistantOutDsSchema, timeout: int = 30) -> str: +def get_out_ds_conf(ds: AssistantOutDsSchema, timeout:int=30) -> str: conf = { - "host": ds.host or '', - "port": ds.port or 0, - "username": ds.user or '', - "password": ds.password or '', - "database": ds.dataBase or '', - "driver": '', - "extraJdbc": ds.extraParams or '', - "dbSchema": ds.db_schema or '', - "timeout": timeout or 30 + "host":ds.host or '', + "port":ds.port or 0, + "username":ds.user or '', + "password":ds.password or '', + "database":ds.dataBase or '', + "driver":'', + "extraJdbc":ds.extraParams or '', + "dbSchema":ds.db_schema or '', + "timeout":timeout or 30 } conf["extraJdbc"] = '' return aes_encrypt(json.dumps(conf))