Skip to content

Commit 839f653

Browse files
committed
chore: update bing client and improve error messages (#337)
1 parent a00a40a commit 839f653

File tree

5 files changed

+27
-15
lines changed

5 files changed

+27
-15
lines changed

src/_locales/en/main.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,8 @@
118118
"Close All Chats In This Page": "Close All Chats In This Page",
119119
"When Icon Clicked": "When Icon Clicked",
120120
"Open Settings": "Open Settings",
121-
"Focus to input box after answering": "Focus to input box after answering"
121+
"Focus to input box after answering": "Focus to input box after answering",
122+
"Bing CaptchaChallenge": "You must pass Bing's verification. Please go to https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx and send a message",
123+
"Exceeded quota": "You exceeded your current quota, check https://platform.openai.com/account/usage",
124+
"Rate limit": "Rate limit exceeded"
122125
}

src/_locales/zh-hans/main.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,8 @@
118118
"Close All Chats In This Page": "关闭本页所有聊天",
119119
"When Icon Clicked": "当图标被点击时",
120120
"Open Settings": "打开设置",
121-
"Focus to input box after answering": "回答结束后自动聚焦到输入框"
121+
"Focus to input box after answering": "回答结束后自动聚焦到输入框",
122+
"Bing CaptchaChallenge": "你必须通过必应的验证, 打开 https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx 并发送一条消息",
123+
"Exceeded quota": "余额不足或过期, 检查此链接: https://platform.openai.com/account/usage",
124+
"Rate limit": "请求频率过高"
122125
}

src/_locales/zh-hant/main.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,5 +118,8 @@
118118
"Close All Chats In This Page": "關閉本頁所有對話",
119119
"When Icon Clicked": "當圖示被點擊時",
120120
"Open Settings": "開啟設定",
121-
"Focus to input box after answering": "回答結束後自動聚焦到輸入框"
121+
"Focus to input box after answering": "回答結束後自動聚焦到輸入框",
122+
"Bing CaptchaChallenge": "妳必須通過必應的驗證, 打開 https://www.bing.com/search?q=Bing+AI&showconv=1&FORM=hpcodx 並發送壹條消息",
123+
"Exceeded quota": "余額不足或過期, 檢查此網址: https://platform.openai.com/account/usage",
124+
"Rate limit": "請求頻率過高"
122125
}

src/services/clients/bing/index.mjs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -234,20 +234,14 @@ export default class BingAIClient {
234234
author: 'system',
235235
},
236236
...previousCachedMessages,
237+
// We still need this to avoid repeating introduction in some cases
237238
{
238239
text: message,
239240
author: 'user',
240241
},
241242
]
242243
: undefined
243244

244-
if (context) {
245-
previousMessages.push({
246-
text: context,
247-
author: 'context', // not a real/valid author, we're just piggybacking on the existing logic
248-
})
249-
}
250-
251245
// prepare messages for prompt injection
252246
previousMessagesFormatted = previousMessages
253247
?.map((previousMessage) => {
@@ -257,14 +251,16 @@ export default class BingAIClient {
257251
case 'bot':
258252
return `[assistant](#message)\n${previousMessage.text}`
259253
case 'system':
260-
return `N/A\n\n[system](#additional_instructions)\n- ${previousMessage.text}`
261-
case 'context':
262-
return `[user](#context)\n${previousMessage.text}`
254+
return `[system](#additional_instructions)\n${previousMessage.text}`
263255
default:
264256
throw new Error(`Unknown message author: ${previousMessage.author}`)
265257
}
266258
})
267259
.join('\n\n')
260+
261+
if (context) {
262+
previousMessagesFormatted = `${context}\n\n${previousMessagesFormatted}`
263+
}
268264
}
269265

270266
const userMessage = {
@@ -313,13 +309,14 @@ export default class BingAIClient {
313309
'cricinfo',
314310
'cricinfov2',
315311
'dv3sugg',
312+
'nojbfedge',
316313
],
317314
sliceIds: ['222dtappid', '225cricinfo', '224locals0'],
318315
traceId: genRanHex(32),
319316
isStartOfSession: invocationId === 0,
320317
message: {
321318
author: 'user',
322-
text: jailbreakConversationId ? '' : message,
319+
text: message,
323320
messageType: jailbreakConversationId ? 'SearchQuery' : 'Chat',
324321
},
325322
conversationSignature,

src/services/wrappers.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ export function registerPortListener(executor) {
5555
err.message.includes(m),
5656
)
5757
)
58-
port.postMessage({ error: t('Exceeded maximum context length') + '\n' + err.message })
58+
port.postMessage({ error: t('Exceeded maximum context length') + '\n\n' + err.message })
59+
else if (['CaptchaChallenge', 'CAPTCHA'].some((m) => err.message.includes(m)))
60+
port.postMessage({ error: t('Bing CaptchaChallenge') + '\n\n' + err.message })
61+
else if (['exceeded your current quota'].some((m) => err.message.includes(m)))
62+
port.postMessage({ error: t('Exceeded quota') + '\n\n' + err.message })
63+
else if (['Rate limit reached'].some((m) => err.message.includes(m)))
64+
port.postMessage({ error: t('Rate limit') + '\n\n' + err.message })
5965
else port.postMessage({ error: err.message })
6066
}
6167
}

0 commit comments

Comments
 (0)