Skip to content

Commit

Permalink
feat: add proxy prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
boxizen committed May 12, 2023
1 parent 863a1d5 commit 7d99f7e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/components/Setting/Account/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function () {
}}
>
<Form.Item label={t('Base Path')} name="basePath">
<Input placeholder="Like https://api.openai.com/v1" />
<Input placeholder="Like https://api.openai.com" />
</Form.Item>
<Form.Item label="ApiKey" name="apikey">
<Input.Password
Expand Down
3 changes: 2 additions & 1 deletion src/electron/apis/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ export default async (req: any, res: any) => {
res.end()
})
} catch (e) {
Logger.error(e)
if (e instanceof Error) {
res.write(e.message)
res.write(String(ERR_CODES.NETWORK_CONGESTION))
res.end()
} else {
res.write(JSON.stringify(e))
Expand Down
2 changes: 2 additions & 0 deletions src/electron/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ export enum ERR_CODES {
NOT_SET_APIKEY = -998,
TOKEN_TOO_LONG = -997,
}

export const CODE_SPLIT = '&^.>'
7 changes: 7 additions & 0 deletions src/features/chat/chatSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ export const fetchChatResp = createAsyncThunk(
reject(new Error('please set your apikey first.'))
break
}

if (Number(value) === ERR_CODES.NETWORK_CONGESTION) {
reject(
new Error('Network error. Check whether you have set up a proxy')
)
break
}
str += value
dispatch(
saveResp({
Expand Down
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"Plugins": "Plugins",
"please set your apikey first.": "please set your apikey first.",
"High network latency. Check whether you have set up a proxy": "High network latency. Check whether you have set up a proxy",
"Network error. Check whether you have set up a proxy": "Network error. Check whether you have set up a proxy",
"Prompt Setting": "Prompt Setting",
"Chat mode, feel free to ask any questions you want.": "Chat mode, feel free to ask any questions you want.",
"Code Master, generate or refactor the code you want.": "Code Master, generate or refactor the code you want.",
Expand Down
1 change: 1 addition & 0 deletions src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"Plugins": "插件",
"please set your apikey first.": "请先设置你的apikey",
"High network latency. Check whether you have set up a proxy": "网络拥堵,请检查是否设置了代理。",
"Network error. Check whether you have set up a proxy": "网络错误,请检查是否设置了代理。",
"Prompt Setting": "Prompt设置",
"Chat mode, feel free to ask any questions you want.": "聊天模式,随意提出任何你想问的问题。",
"Code Master, generate or refactor the code you want.": "编程模式,生成或重构你想要的代码。",
Expand Down

0 comments on commit 7d99f7e

Please sign in to comment.