Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
426176db
authored
Jun 25, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: apikey
parent
cfb31afb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
16 deletions
+22
-16
client/src/pages/api/openapi/plugin/openaiEmbedding.ts
+7
-2
client/src/pages/number/index.tsx
+13
-7
client/src/utils/plugin/openai.ts
+2
-7
No files found.
client/src/pages/api/openapi/plugin/openaiEmbedding.ts
View file @
426176db
...
...
@@ -39,7 +39,12 @@ export async function openaiEmbedding({
input
,
mustPay
=
false
}:
{
userId
:
string
;
mustPay
?:
boolean
}
&
Props
)
{
const
apiKey
=
getSystemOpenAiKey
();
const
{
userOpenAiKey
,
systemAuthKey
}
=
await
getApiKey
({
model
:
'gpt-3.5-turbo'
,
userId
,
mustPay
});
const
apiKey
=
userOpenAiKey
||
systemAuthKey
;
// 获取 chatAPI
const
chatAPI
=
getOpenAIApi
(
apiKey
);
...
...
@@ -68,7 +73,7 @@ export async function openaiEmbedding({
});
pushGenerateVectorBill
({
isPay
:
mustPa
y
,
isPay
:
!
userOpenAiKe
y
,
userId
,
text
:
input
.
join
(
''
),
tokenLen
:
result
.
tokenLen
...
...
client/src/pages/number/index.tsx
View file @
426176db
...
...
@@ -54,7 +54,6 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
{
label
:
'佣金'
,
id
:
TableEnum
.
promotion
,
Component
:
<
PromotionTable
/>
},
{
label
:
'通知'
,
id
:
TableEnum
.
inform
,
Component
:
<
InformTable
/>
}
]);
const
[
currentTab
,
setCurrentTab
]
=
useState
(
tableType
);
const
router
=
useRouter
();
const
{
copyData
}
=
useCopyData
();
...
...
@@ -84,7 +83,14 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
async
(
data
:
UserUpdateParams
)
=>
{
setLoading
(
true
);
try
{
data
.
openaiKey
&&
(
await
authOpenAiKey
(
data
.
openaiKey
));
if
(
data
.
openaiKey
)
{
const
text
=
await
authOpenAiKey
(
data
.
openaiKey
);
text
&&
toast
({
title
:
text
,
status
:
'warning'
});
}
await
putUserInfo
({
openaiKey
:
data
.
openaiKey
,
avatar
:
data
.
avatar
...
...
@@ -95,7 +101,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
});
reset
(
data
);
toast
({
title
:
'更新成功'
,
title
:
'更新
数据
成功'
,
status
:
'success'
});
}
catch
(
error
)
{
...
...
@@ -195,7 +201,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
<
Box
flex=
{
'0 0 85px'
}
>
openaiKey:
</
Box
>
<
Input
{
...
register
(`
openaiKey
`)}
maxW=
{
'3
0
0px'
}
maxW=
{
'3
5
0px'
}
placeholder=
{
'openai账号。回车或失去焦点保存'
}
size=
{
'sm'
}
onBlur=
{
handleSubmit
(
onclickSave
)
}
...
...
@@ -251,13 +257,13 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
m=
{
'auto'
}
w=
{
'200px'
}
list=
{
tableList
.
current
}
activeId=
{
currentTab
}
activeId=
{
tableType
}
size=
{
'sm'
}
onChange=
{
(
id
:
any
)
=>
setCurrentTab
(
id
)
}
onChange=
{
(
id
:
any
)
=>
router
.
replace
(
`/number?type=${id}`
)
}
/>
<
Box
minH=
{
'300px'
}
>
{
(()
=>
{
const
item
=
tableList
.
current
.
find
((
item
)
=>
item
.
id
===
currentTab
);
const
item
=
tableList
.
current
.
find
((
item
)
=>
item
.
id
===
tableType
);
return
item
?
item
.
Component
:
null
;
})()
}
...
...
client/src/utils/plugin/openai.ts
View file @
426176db
...
...
@@ -111,16 +111,11 @@ export const authOpenAiKey = async (key: string) => {
})
.
then
((
res
)
=>
{
if
(
!
res
.
data
.
access_until
)
{
return
Promise
.
reject
(
'OpenAI Key 无效,请重试或更换 key'
);
}
const
keyExpiredTime
=
dayjs
(
res
.
data
.
access_until
*
1000
);
const
currentTime
=
dayjs
();
if
(
keyExpiredTime
.
isBefore
(
currentTime
))
{
return
Promise
.
reject
(
'OpenAI Key 已过期'
);
return
Promise
.
resolve
(
'OpenAI Key 可能无效'
);
}
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
return
Promise
.
reject
(
err
?.
response
?.
data
?.
error
||
'OpenAI 账号无效,请重试或更换 key
'
);
return
Promise
.
reject
(
err
?.
response
?.
data
?.
error
?.
message
||
'OpenAI 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