Skip to content

Commit b451d1f

Browse files
authored
fix: package error (#549)
1 parent 9bf2cc8 commit b451d1f

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

backend/apps/chat/curd/chat.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import datetime
2-
from idlelib.pyparse import trans
32
from typing import List
43
from sqlalchemy import desc, func
54

@@ -399,7 +398,7 @@ def create_chat(session: SessionDep, current_user: CurrentUser, create_chat_obj:
399398
ds = session.get(CoreDatasource, create_chat_obj.datasource)
400399

401400
if not ds:
402-
raise Exception(trans('i18n_data_training.datasource_id_not_found', key=create_chat_obj.datasource))
401+
raise Exception(f"Datasource with id {create_chat_obj.datasource} not found")
403402

404403
chat.engine_type = ds.type_name
405404
else:

backend/apps/system/crud/assistant.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import json
22
import re
33
import urllib
4-
from idlelib.pyparse import trans
54
from typing import Optional
65

76
import requests
@@ -117,8 +116,7 @@ def get_ds_from_api(self):
117116
endpoint: str = config['endpoint']
118117
endpoint = self.get_complete_endpoint(endpoint=endpoint)
119118
if not endpoint:
120-
raise Exception(
121-
f"Failed to get datasource list from {config['endpoint']}, error: [Assistant domain or endpoint miss]")
119+
raise Exception(f"Failed to get datasource list from {config['endpoint']}, error: [Assistant domain or endpoint miss]")
122120
certificateList: list[any] = json.loads(self.certificate)
123121
header = {}
124122
cookies = {}
@@ -145,25 +143,23 @@ def get_ds_from_api(self):
145143
raise Exception(f"Failed to get datasource list from {endpoint}, error: {result_json.get('message')}")
146144
else:
147145
raise Exception(f"Failed to get datasource list from {endpoint}, status code: {res.status_code}")
148-
146+
149147
def get_first_element(self, text: str):
150148
parts = re.split(r'[,;]', text.strip())
151149
first_domain = parts[0].strip()
152150
return first_domain
153-
151+
154152
def get_complete_endpoint(self, endpoint: str) -> str | None:
155153
if endpoint.startswith("http://") or endpoint.startswith("https://"):
156154
return endpoint
157155
domain_text = self.assistant.domain
158156
if not domain_text:
159157
return None
160158
if ',' in domain_text or ';' in domain_text:
161-
return (
162-
self.request_origin.strip('/') if self.request_origin else self.get_first_element(domain_text).strip(
163-
'/')) + endpoint
159+
return (self.request_origin.strip('/') if self.request_origin else self.get_first_element(domain_text).strip('/')) + endpoint
164160
else:
165-
return f"{domain_text}{endpoint}"
166-
161+
return f"{domain_text}{endpoint}"
162+
167163
def get_simple_ds_list(self):
168164
if self.ds_list:
169165
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):
215211
if ds.id == ds_id:
216212
return ds
217213
else:
218-
raise Exception(trans('i18n_data_training.datasource_list_is_not_found'))
219-
raise Exception(trans('i18n_data_training.datasource_id_not_found', key=ds_id))
214+
raise Exception("Datasource list is not found.")
215+
raise Exception(f"Datasource with id {ds_id} not found.")
220216

221217
def convert2schema(self, ds_dict: dict, config: dict[any]) -> AssistantOutDsSchema:
222218
id_marker: str = ''
@@ -279,17 +275,17 @@ def get_ds_engine(ds: AssistantOutDsSchema) -> Engine:
279275
return engine
280276

281277

282-
def get_out_ds_conf(ds: AssistantOutDsSchema, timeout: int = 30) -> str:
278+
def get_out_ds_conf(ds: AssistantOutDsSchema, timeout:int=30) -> str:
283279
conf = {
284-
"host": ds.host or '',
285-
"port": ds.port or 0,
286-
"username": ds.user or '',
287-
"password": ds.password or '',
288-
"database": ds.dataBase or '',
289-
"driver": '',
290-
"extraJdbc": ds.extraParams or '',
291-
"dbSchema": ds.db_schema or '',
292-
"timeout": timeout or 30
280+
"host":ds.host or '',
281+
"port":ds.port or 0,
282+
"username":ds.user or '',
283+
"password":ds.password or '',
284+
"database":ds.dataBase or '',
285+
"driver":'',
286+
"extraJdbc":ds.extraParams or '',
287+
"dbSchema":ds.db_schema or '',
288+
"timeout":timeout or 30
293289
}
294290
conf["extraJdbc"] = ''
295291
return aes_encrypt(json.dumps(conf))

0 commit comments

Comments
 (0)