Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion backend/apps/chat/curd/chat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from idlelib.pyparse import trans
from typing import List
from sqlalchemy import desc, func

Expand Down Expand Up @@ -398,7 +399,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(f"Datasource with id {create_chat_obj.datasource} not found")
raise Exception(trans('i18n_data_training.datasource_id_not_found', key=create_chat_obj.datasource))

chat.engine_type = ds.type_name
else:
Expand Down
40 changes: 22 additions & 18 deletions backend/apps/system/crud/assistant.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import re
import urllib
from idlelib.pyparse import trans
from typing import Optional

import requests
Expand Down Expand Up @@ -116,7 +117,8 @@ 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 = {}
Expand All @@ -143,23 +145,25 @@ 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
domain_text = self.assistant.domain
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]
Expand Down Expand Up @@ -211,8 +215,8 @@ def get_ds(self, ds_id: int):
if ds.id == ds_id:
return ds
else:
raise Exception("Datasource list is not found.")
raise Exception(f"Datasource with id {ds_id} not found.")
raise Exception(trans('i18n_data_training.datasource_list_is_not_found'))
raise Exception(trans('i18n_data_training.datasource_id_not_found', key=ds_id))

def convert2schema(self, ds_dict: dict, config: dict[any]) -> AssistantOutDsSchema:
id_marker: str = ''
Expand Down Expand Up @@ -275,17 +279,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))
2 changes: 2 additions & 0 deletions backend/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"datasource_not_found": "Datasource not found"
},
"i18n_data_training": {
"datasource_list_is_not_found": "Data source list not found",
"datasource_id_not_found": "Data source ID: {key} not found",
"datasource_cannot_be_none": "Datasource cannot be empty",
"datasource_assistant_cannot_be_none": "Datasource or advanced application cannot both be empty",
"data_training_not_exists": "This example does not exist",
Expand Down
2 changes: 2 additions & 0 deletions backend/locales/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
"invalid_origin": "도메인 이름 검증 실패 【{origin}】"
},
"i18n_terminology": {
"datasource_list_is_not_found": "데이터 소스 목록을 찾을 수 없습니다",
"datasource_id_not_found": "데이터 소스 ID: {key}를 찾을 수 없습니다",
"terminology_not_exists": "이 용어가 존재하지 않습니다",
"datasource_cannot_be_none": "데이터 소스는 비울 수 없습니다",
"cannot_be_repeated": "용어 이름과 동의어는 반복될 수 없습니다",
Expand Down
2 changes: 2 additions & 0 deletions backend/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
"datasource_not_found": "找不到数据源"
},
"i18n_data_training": {
"datasource_list_is_not_found": "数据源列表未找到",
"datasource_id_not_found": "数据源ID: {key} 未找到",
"datasource_cannot_be_none": "数据源不能为空",
"datasource_assistant_cannot_be_none": "数据源或高级应用不能都为空",
"data_training_not_exists": "该示例不存在",
Expand Down