Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dify
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ai-tech
dify
Commits
0bb253ef
Unverified
Commit
0bb253ef
authored
May 24, 2023
by
zxhlyh
Committed by
GitHub
May 24, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: providererror message when token validated fail (#190)
parent
d93365d4
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
36 additions
and
36 deletions
+36
-36
index.tsx
...er/account-setting/provider-page/azure-provider/index.tsx
+8
-8
index.tsx
...r/account-setting/provider-page/openai-provider/index.tsx
+9
-9
Validate.tsx
...account-setting/provider-page/provider-input/Validate.tsx
+4
-4
useValidateToken.ts
...-setting/provider-page/provider-input/useValidateToken.ts
+13
-15
common.en.ts
web/i18n/lang/common.en.ts
+1
-0
common.zh.ts
web/i18n/lang/common.zh.ts
+1
-0
No files found.
web/app/components/header/account-setting/provider-page/azure-provider/index.tsx
View file @
0bb253ef
...
...
@@ -5,7 +5,7 @@ import Link from 'next/link'
import
{
ArrowTopRightOnSquareIcon
}
from
'@heroicons/react/24/outline'
import
{
useState
,
useEffect
}
from
'react'
import
ProviderInput
from
'../provider-input'
import
useValidateToken
,
{
ValidatedStatus
}
from
'../provider-input/useValidateToken'
import
useValidateToken
,
{
ValidatedStatus
,
ValidatedStatusState
}
from
'../provider-input/useValidateToken'
import
{
ValidatedErrorIcon
,
ValidatedSuccessIcon
,
...
...
@@ -15,7 +15,7 @@ import {
interface
IAzureProviderProps
{
provider
:
Provider
onValidatedStatus
:
(
status
?:
ValidatedStatus
)
=>
void
onValidatedStatus
:
(
status
?:
ValidatedStatus
State
)
=>
void
onTokenChange
:
(
token
:
ProviderAzureToken
)
=>
void
}
const
AzureProvider
=
({
...
...
@@ -31,7 +31,7 @@ const AzureProvider = ({
token
[
type
]
=
''
setToken
({...
token
})
onTokenChange
({...
token
})
setValidatedStatus
(
undefined
)
setValidatedStatus
(
{}
)
}
}
const
handleChange
=
(
type
:
keyof
ProviderAzureToken
,
v
:
string
,
validate
:
any
)
=>
{
...
...
@@ -41,7 +41,7 @@ const AzureProvider = ({
validate
({...
token
},
{
beforeValidating
:
()
=>
{
if
(
!
token
.
openai_api_base
||
!
token
.
openai_api_key
)
{
setValidatedStatus
(
undefined
)
setValidatedStatus
(
{}
)
return
false
}
return
true
...
...
@@ -49,10 +49,10 @@ const AzureProvider = ({
})
}
const
getValidatedIcon
=
()
=>
{
if
(
validatedStatus
===
ValidatedStatus
.
Error
||
validatedS
tatus
===
ValidatedStatus
.
Exceed
)
{
if
(
validatedStatus
.
status
===
ValidatedStatus
.
Error
||
validatedStatus
.
s
tatus
===
ValidatedStatus
.
Exceed
)
{
return
<
ValidatedErrorIcon
/>
}
if
(
validatedStatus
===
ValidatedStatus
.
Success
)
{
if
(
validatedStatus
.
status
===
ValidatedStatus
.
Success
)
{
return
<
ValidatedSuccessIcon
/>
}
}
...
...
@@ -60,8 +60,8 @@ const AzureProvider = ({
if
(
validating
)
{
return
<
ValidatingTip
/>
}
if
(
validatedStatus
===
ValidatedStatus
.
Error
)
{
return
<
ValidatedErrorOnAzureOpenaiTip
/>
if
(
validatedStatus
.
status
===
ValidatedStatus
.
Error
)
{
return
<
ValidatedErrorOnAzureOpenaiTip
errorMessage=
{
validatedStatus
.
message
??
''
}
/>
}
}
useEffect
(()
=>
{
...
...
web/app/components/header/account-setting/provider-page/openai-provider/index.tsx
View file @
0bb253ef
...
...
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next'
import
ProviderInput
from
'../provider-input'
import
Link
from
'next/link'
import
{
ArrowTopRightOnSquareIcon
}
from
'@heroicons/react/24/outline'
import
useValidateToken
,
{
ValidatedStatus
}
from
'../provider-input/useValidateToken'
import
useValidateToken
,
{
ValidatedStatus
,
ValidatedStatusState
}
from
'../provider-input/useValidateToken'
import
{
ValidatedErrorIcon
,
ValidatedSuccessIcon
,
...
...
@@ -15,7 +15,7 @@ import {
interface
IOpenaiProviderProps
{
provider
:
Provider
onValidatedStatus
:
(
status
?:
ValidatedStatus
)
=>
void
onValidatedStatus
:
(
status
?:
ValidatedStatus
State
)
=>
void
onTokenChange
:
(
token
:
string
)
=>
void
}
...
...
@@ -31,7 +31,7 @@ const OpenaiProvider = ({
if
(
token
===
provider
.
token
)
{
setToken
(
''
)
onTokenChange
(
''
)
setValidatedStatus
(
undefined
)
setValidatedStatus
(
{}
)
}
}
const
handleChange
=
(
v
:
string
)
=>
{
...
...
@@ -40,7 +40,7 @@ const OpenaiProvider = ({
validate
(
v
,
{
beforeValidating
:
()
=>
{
if
(
!
v
)
{
setValidatedStatus
(
undefined
)
setValidatedStatus
(
{}
)
return
false
}
return
true
...
...
@@ -54,10 +54,10 @@ const OpenaiProvider = ({
},
[
validatedStatus
])
const
getValidatedIcon
=
()
=>
{
if
(
validatedStatus
===
ValidatedStatus
.
Error
||
validatedS
tatus
===
ValidatedStatus
.
Exceed
)
{
if
(
validatedStatus
?.
status
===
ValidatedStatus
.
Error
||
validatedStatus
.
s
tatus
===
ValidatedStatus
.
Exceed
)
{
return
<
ValidatedErrorIcon
/>
}
if
(
validatedStatus
===
ValidatedStatus
.
Success
)
{
if
(
validatedStatus
.
status
===
ValidatedStatus
.
Success
)
{
return
<
ValidatedSuccessIcon
/>
}
}
...
...
@@ -65,11 +65,11 @@ const OpenaiProvider = ({
if
(
validating
)
{
return
<
ValidatingTip
/>
}
if
(
validatedStatus
===
ValidatedStatus
.
Exceed
)
{
if
(
validatedStatus
?.
status
===
ValidatedStatus
.
Success
)
{
return
<
ValidatedExceedOnOpenaiTip
/>
}
if
(
validatedStatus
===
ValidatedStatus
.
Error
)
{
return
<
ValidatedErrorOnOpenaiTip
/>
if
(
validatedStatus
?.
status
===
ValidatedStatus
.
Error
)
{
return
<
ValidatedErrorOnOpenaiTip
errorMessage=
{
validatedStatus
.
message
??
''
}
/>
}
}
...
...
web/app/components/header/account-setting/provider-page/provider-input/Validate.tsx
View file @
0bb253ef
...
...
@@ -38,22 +38,22 @@ export const ValidatedExceedOnOpenaiTip = () => {
)
}
export
const
ValidatedErrorOnOpenaiTip
=
()
=>
{
export
const
ValidatedErrorOnOpenaiTip
=
(
{
errorMessage
}:
{
errorMessage
:
string
}
)
=>
{
const
{
t
}
=
useTranslation
()
return
(
<
div
className=
{
`mt-2 text-[#D92D20] text-xs font-normal`
}
>
{
t
(
'common.provider.
invalidKey'
)
}
{
t
(
'common.provider.
validatedError'
)
}{
errorMessage
}
</
div
>
)
}
export
const
ValidatedErrorOnAzureOpenaiTip
=
()
=>
{
export
const
ValidatedErrorOnAzureOpenaiTip
=
(
{
errorMessage
}:
{
errorMessage
:
string
}
)
=>
{
const
{
t
}
=
useTranslation
()
return
(
<
div
className=
{
`mt-2 text-[#D92D20] text-xs font-normal`
}
>
{
t
(
'common.provider.
invalidApiKey'
)
}
{
t
(
'common.provider.
validatedError'
)
}{
errorMessage
}
</
div
>
)
}
\ No newline at end of file
web/app/components/header/account-setting/provider-page/provider-input/useValidateToken.ts
View file @
0bb253ef
...
...
@@ -8,11 +8,16 @@ export enum ValidatedStatus {
Error
=
'error'
,
Exceed
=
'exceed'
}
export
type
SetValidatedStatus
=
Dispatch
<
SetStateAction
<
ValidatedStatus
|
undefined
>>
export
type
ValidatedStatusState
=
{
status
?:
ValidatedStatus
,
message
?:
string
}
// export type ValidatedStatusState = ValidatedStatus | undefined | ValidatedError
export
type
SetValidatedStatus
=
Dispatch
<
SetStateAction
<
ValidatedStatusState
>>
export
type
ValidateFn
=
DebouncedFunc
<
(
token
:
any
,
config
:
ValidateFnConfig
)
=>
void
>
type
ValidateTokenReturn
=
[
boolean
,
ValidatedStatus
|
undefined
,
ValidatedStatus
State
,
SetValidatedStatus
,
ValidateFn
]
...
...
@@ -22,7 +27,7 @@ export type ValidateFnConfig = {
const
useValidateToken
=
(
providerName
:
string
):
ValidateTokenReturn
=>
{
const
[
validating
,
setValidating
]
=
useState
(
false
)
const
[
validatedStatus
,
setValidatedStatus
]
=
useState
<
ValidatedStatus
|
undefined
>
(
)
const
[
validatedStatus
,
setValidatedStatus
]
=
useState
<
ValidatedStatus
State
>
({}
)
const
validate
=
useCallback
(
debounce
(
async
(
token
:
string
,
config
:
ValidateFnConfig
)
=>
{
if
(
!
config
.
beforeValidating
(
token
))
{
return
false
...
...
@@ -30,19 +35,12 @@ const useValidateToken = (providerName: string): ValidateTokenReturn => {
setValidating
(
true
)
try
{
const
res
=
await
validateProviderKey
({
url
:
`/workspaces/current/providers/
${
providerName
}
/token-validate`
,
body
:
{
token
}
})
setValidatedStatus
(
res
.
result
===
'success'
?
ValidatedStatus
.
Success
:
ValidatedStatus
.
Error
)
setValidatedStatus
(
res
.
result
===
'success'
?
{
status
:
ValidatedStatus
.
Success
}
:
{
status
:
ValidatedStatus
.
Error
,
message
:
res
.
error
})
}
catch
(
e
:
any
)
{
if
(
e
.
status
===
400
)
{
e
.
json
().
then
(({
code
}:
any
)
=>
{
if
(
code
===
'provider_request_failed'
&&
providerName
===
'openai'
)
{
setValidatedStatus
(
ValidatedStatus
.
Exceed
)
}
else
{
setValidatedStatus
(
ValidatedStatus
.
Error
)
}
})
}
else
{
setValidatedStatus
(
ValidatedStatus
.
Error
)
}
setValidatedStatus
({
status
:
ValidatedStatus
.
Error
,
message
:
e
.
message
})
}
finally
{
setValidating
(
false
)
}
...
...
web/i18n/lang/common.en.ts
View file @
0bb253ef
...
...
@@ -140,6 +140,7 @@ const translation = {
apiKey
:
"API Key"
,
enterYourKey
:
"Enter your API key here"
,
invalidKey
:
"Invalid OpenAI API key"
,
validatedError
:
"Validation failed: "
,
validating
:
"Validating key..."
,
saveFailed
:
"Save api key failed"
,
apiKeyExceedBill
:
"This API KEY has no quota available, please read"
,
...
...
web/i18n/lang/common.zh.ts
View file @
0bb253ef
...
...
@@ -141,6 +141,7 @@ const translation = {
apiKey
:
"API 密钥"
,
enterYourKey
:
"输入你的 API 密钥"
,
invalidKey
:
'无效的 OpenAI API 密钥'
,
validatedError
:
"校验失败:"
,
validating
:
"验证密钥中..."
,
saveFailed
:
"API 密钥保存失败"
,
apiKeyExceedBill
:
"此 API KEY 已没有可用配额,请阅读"
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment