@@ -169,11 +169,12 @@ function handleResponse(completion, isChatGPTModel, query, result) {
169169
170170 let targetText = ( isChatGPTModel ? choices [ 0 ] . message . content : choices [ 0 ] . text ) . trim ( ) ;
171171
172- if ( targetText . startsWith ( '"' ) || targetText . startsWith ( "「" ) ) {
173- targetText = targetText . slice ( 1 ) ;
174- }
175- if ( targetText . endsWith ( '"' ) || targetText . endsWith ( "」" ) ) {
176- targetText = targetText . slice ( 0 , - 1 ) ;
172+ // 使用正则表达式删除字符串开头和结尾的特殊字符
173+ targetText = targetText . replace ( / ^ ( 『 | 「 | " | “ ) | ( 』 | 」 | " | ” ) $ / g, "" ) ;
174+
175+ // 判断并删除字符串末尾的 `" =>`
176+ if ( targetText . endsWith ( '" =>' ) ) {
177+ targetText = targetText . slice ( 0 , - 4 ) ;
177178 }
178179
179180 completion ( {
@@ -200,10 +201,21 @@ function translate(query, completion) {
200201 }
201202
202203 const { model, apiKeys, apiUrl, deploymentName } = $option ;
203- const modifiedApiUrl = ensureHttpsAndNoTrailingSlash ( apiUrl ) ;
204204
205- const apiKeySelection = apiKeys . split ( "," ) . map ( key => key . trim ( ) ) ;
205+ if ( ! apiKeys ) {
206+ completion ( {
207+ error : {
208+ type : "secretKey" ,
209+ message : "配置错误 - 请确保您在插件配置中填入了正确的 API Keys" ,
210+ addtion : "请在插件配置中填写 API Keys" ,
211+ } ,
212+ } ) ;
213+ }
214+ const trimmedApiKeys = apiKeys . endsWith ( "," ) ? apiKeys . slice ( 0 , - 1 ) : apiKeys ;
215+ const apiKeySelection = trimmedApiKeys . split ( "," ) . map ( key => key . trim ( ) ) ;
206216 const apiKey = apiKeySelection [ Math . floor ( Math . random ( ) * apiKeySelection . length ) ] ;
217+
218+ const modifiedApiUrl = ensureHttpsAndNoTrailingSlash ( apiUrl ) ;
207219
208220 const isChatGPTModel = ChatGPTModels . includes ( model ) ;
209221 const isAzureServiceProvider = modifiedApiUrl . includes ( "openai.azure.com" ) ;
0 commit comments