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({
...
@@ -39,7 +39,12 @@ export async function openaiEmbedding({
input
,
input
,
mustPay
=
false
mustPay
=
false
}:
{
userId
:
string
;
mustPay
?:
boolean
}
&
Props
)
{
}:
{
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
// 获取 chatAPI
const
chatAPI
=
getOpenAIApi
(
apiKey
);
const
chatAPI
=
getOpenAIApi
(
apiKey
);
...
@@ -68,7 +73,7 @@ export async function openaiEmbedding({
...
@@ -68,7 +73,7 @@ export async function openaiEmbedding({
});
});
pushGenerateVectorBill
({
pushGenerateVectorBill
({
isPay
:
mustPa
y
,
isPay
:
!
userOpenAiKe
y
,
userId
,
userId
,
text
:
input
.
join
(
''
),
text
:
input
.
join
(
''
),
tokenLen
:
result
.
tokenLen
tokenLen
:
result
.
tokenLen
...
...
client/src/pages/number/index.tsx
View file @
426176db
...
@@ -54,7 +54,6 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
...
@@ -54,7 +54,6 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
{
label
:
'佣金'
,
id
:
TableEnum
.
promotion
,
Component
:
<
PromotionTable
/>
},
{
label
:
'佣金'
,
id
:
TableEnum
.
promotion
,
Component
:
<
PromotionTable
/>
},
{
label
:
'通知'
,
id
:
TableEnum
.
inform
,
Component
:
<
InformTable
/>
}
{
label
:
'通知'
,
id
:
TableEnum
.
inform
,
Component
:
<
InformTable
/>
}
]);
]);
const
[
currentTab
,
setCurrentTab
]
=
useState
(
tableType
);
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
copyData
}
=
useCopyData
();
const
{
copyData
}
=
useCopyData
();
...
@@ -84,7 +83,14 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
...
@@ -84,7 +83,14 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
async
(
data
:
UserUpdateParams
)
=>
{
async
(
data
:
UserUpdateParams
)
=>
{
setLoading
(
true
);
setLoading
(
true
);
try
{
try
{
data
.
openaiKey
&&
(
await
authOpenAiKey
(
data
.
openaiKey
));
if
(
data
.
openaiKey
)
{
const
text
=
await
authOpenAiKey
(
data
.
openaiKey
);
text
&&
toast
({
title
:
text
,
status
:
'warning'
});
}
await
putUserInfo
({
await
putUserInfo
({
openaiKey
:
data
.
openaiKey
,
openaiKey
:
data
.
openaiKey
,
avatar
:
data
.
avatar
avatar
:
data
.
avatar
...
@@ -95,7 +101,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
...
@@ -95,7 +101,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
});
});
reset
(
data
);
reset
(
data
);
toast
({
toast
({
title
:
'更新成功'
,
title
:
'更新
数据
成功'
,
status
:
'success'
status
:
'success'
});
});
}
catch
(
error
)
{
}
catch
(
error
)
{
...
@@ -195,7 +201,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
...
@@ -195,7 +201,7 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
<
Box
flex=
{
'0 0 85px'
}
>
openaiKey:
</
Box
>
<
Box
flex=
{
'0 0 85px'
}
>
openaiKey:
</
Box
>
<
Input
<
Input
{
...
register
(`
openaiKey
`)}
{
...
register
(`
openaiKey
`)}
maxW=
{
'3
0
0px'
}
maxW=
{
'3
5
0px'
}
placeholder=
{
'openai账号。回车或失去焦点保存'
}
placeholder=
{
'openai账号。回车或失去焦点保存'
}
size=
{
'sm'
}
size=
{
'sm'
}
onBlur=
{
handleSubmit
(
onclickSave
)
}
onBlur=
{
handleSubmit
(
onclickSave
)
}
...
@@ -251,13 +257,13 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
...
@@ -251,13 +257,13 @@ const NumberSetting = ({ tableType }: { tableType: `${TableEnum}` }) => {
m=
{
'auto'
}
m=
{
'auto'
}
w=
{
'200px'
}
w=
{
'200px'
}
list=
{
tableList
.
current
}
list=
{
tableList
.
current
}
activeId=
{
currentTab
}
activeId=
{
tableType
}
size=
{
'sm'
}
size=
{
'sm'
}
onChange=
{
(
id
:
any
)
=>
setCurrentTab
(
id
)
}
onChange=
{
(
id
:
any
)
=>
router
.
replace
(
`/number?type=${id}`
)
}
/>
/>
<
Box
minH=
{
'300px'
}
>
<
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
;
return
item
?
item
.
Component
:
null
;
})()
}
})()
}
...
...
client/src/utils/plugin/openai.ts
View file @
426176db
...
@@ -111,16 +111,11 @@ export const authOpenAiKey = async (key: string) => {
...
@@ -111,16 +111,11 @@ export const authOpenAiKey = async (key: string) => {
})
})
.
then
((
res
)
=>
{
.
then
((
res
)
=>
{
if
(
!
res
.
data
.
access_until
)
{
if
(
!
res
.
data
.
access_until
)
{
return
Promise
.
reject
(
'OpenAI Key 无效,请重试或更换 key'
);
return
Promise
.
resolve
(
'OpenAI Key 可能无效'
);
}
const
keyExpiredTime
=
dayjs
(
res
.
data
.
access_until
*
1000
);
const
currentTime
=
dayjs
();
if
(
keyExpiredTime
.
isBefore
(
currentTime
))
{
return
Promise
.
reject
(
'OpenAI Key 已过期'
);
}
}
})
})
.
catch
((
err
)
=>
{
.
catch
((
err
)
=>
{
console
.
log
(
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