2020from common .core .sqlbot_cache import cache
2121from common .utils .aes_crypto import simple_aes_decrypt
2222from common .utils .utils import equals_ignore_case , string_to_numeric_hash
23+ from common .core .deps import Trans
2324
2425
2526@cache (namespace = CacheNamespace .EMBEDDED_INFO , cacheName = CacheName .ASSISTANT_INFO , keyExpression = "assistant_id" )
@@ -143,12 +144,12 @@ def get_ds_from_api(self):
143144 raise Exception (f"Failed to get datasource list from { endpoint } , error: { result_json .get ('message' )} " )
144145 else :
145146 raise Exception (f"Failed to get datasource list from { endpoint } , status code: { res .status_code } " )
146-
147+
147148 def get_first_element (self , text : str ):
148149 parts = re .split (r'[,;]' , text .strip ())
149150 first_domain = parts [0 ].strip ()
150151 return first_domain
151-
152+
152153 def get_complete_endpoint (self , endpoint : str ) -> str | None :
153154 if endpoint .startswith ("http://" ) or endpoint .startswith ("https://" ):
154155 return endpoint
@@ -158,8 +159,8 @@ def get_complete_endpoint(self, endpoint: str) -> str | None:
158159 if ',' in domain_text or ';' in domain_text :
159160 return (self .request_origin .strip ('/' ) if self .request_origin else self .get_first_element (domain_text ).strip ('/' )) + endpoint
160161 else :
161- return f"{ domain_text } { endpoint } "
162-
162+ return f"{ domain_text } { endpoint } "
163+
163164 def get_simple_ds_list (self ):
164165 if self .ds_list :
165166 return [{'id' : ds .id , 'name' : ds .name , 'description' : ds .comment } for ds in self .ds_list ]
@@ -205,14 +206,14 @@ def get_db_schema(self, ds_id: int, question: str, embedding: bool = True) -> st
205206
206207 return schema_str
207208
208- def get_ds (self , ds_id : int ):
209+ def get_ds (self , ds_id : int , trans : Trans = None ):
209210 if self .ds_list :
210211 for ds in self .ds_list :
211212 if ds .id == ds_id :
212213 return ds
213214 else :
214215 raise Exception ("Datasource list is not found." )
215- raise Exception (f"Datasource with id { ds_id } not found." )
216+ raise Exception (f"Datasource id { ds_id } is not found." if trans is None else trans ( 'i18n_data_training.datasource_id_not_found' , key = ds_id ) )
216217
217218 def convert2schema (self , ds_dict : dict , config : dict [any ]) -> AssistantOutDsSchema :
218219 id_marker : str = ''
0 commit comments