mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
fix: Optimize the internationalization prompt of the assistant (#546)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from idlelib.pyparse import trans
|
||||
from typing import List
|
||||
from sqlalchemy import desc, func
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import re
|
||||
import urllib
|
||||
from idlelib.pyparse import trans
|
||||
from typing import Optional
|
||||
|
||||
import requests
|
||||
@@ -116,7 +117,8 @@ class AssistantOutDs:
|
||||
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 = {}
|
||||
@@ -143,12 +145,12 @@ class AssistantOutDs:
|
||||
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
|
||||
@@ -156,10 +158,12 @@ class AssistantOutDs:
|
||||
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]
|
||||
@@ -211,8 +215,8 @@ class AssistantOutDs:
|
||||
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 = ''
|
||||
@@ -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))
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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": "용어 이름과 동의어는 반복될 수 없습니다",
|
||||
|
||||
@@ -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": "该示例不存在",
|
||||
|
||||
Reference in New Issue
Block a user