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
48fbc741
authored
Jun 05, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: embedding
parent
92b592dd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
11 additions
and
17 deletions
+11
-17
src/pages/api/openapi/plugin/openaiEmbedding.ts
+6
-13
src/pages/api/user/getPayCode.ts
+0
-1
src/pages/chat/index.tsx
+2
-0
src/pages/number/components/PayModal.tsx
+3
-3
No files found.
src/pages/api/openapi/plugin/openaiEmbedding.ts
View file @
48fbc741
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
,
getSystemOpenAiKey
}
from
'@/service/utils/auth'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
withNextCors
}
from
'@/service/utils/tools'
;
import
{
getApiKey
}
from
'@/service/utils/auth'
;
import
{
getOpenAIApi
}
from
'@/service/utils/chat/openai'
;
import
{
getOpenAIApi
}
from
'@/service/utils/chat/openai'
;
import
{
embeddingModel
}
from
'@/constants/model'
;
import
{
embeddingModel
}
from
'@/constants/model'
;
import
{
axiosConfig
}
from
'@/service/utils/tools'
;
import
{
axiosConfig
}
from
'@/service/utils/tools'
;
...
@@ -25,7 +24,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -25,7 +24,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
}
}
jsonRes
<
Response
>
(
res
,
{
jsonRes
<
Response
>
(
res
,
{
data
:
await
openaiEmbedding
({
userId
,
input
,
mustPay
:
true
,
type
})
data
:
await
openaiEmbedding
({
userId
,
input
,
type
})
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
);
console
.
log
(
err
);
...
@@ -39,15 +38,9 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -39,15 +38,9 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
export
async
function
openaiEmbedding
({
export
async
function
openaiEmbedding
({
userId
,
userId
,
input
,
input
,
mustPay
=
false
,
type
=
'chat'
type
=
'chat'
}:
{
userId
:
string
;
mustPay
?:
boolean
}
&
Props
)
{
}:
{
userId
:
string
}
&
Props
)
{
const
{
userOpenAiKey
,
systemAuthKey
}
=
await
getApiKey
({
const
apiKey
=
getSystemOpenAiKey
(
type
);
model
:
'gpt-3.5-turbo'
,
userId
,
mustPay
,
type
});
// 获取 chatAPI
// 获取 chatAPI
const
chatAPI
=
getOpenAIApi
();
const
chatAPI
=
getOpenAIApi
();
...
@@ -61,7 +54,7 @@ export async function openaiEmbedding({
...
@@ -61,7 +54,7 @@ export async function openaiEmbedding({
},
},
{
{
timeout
:
60000
,
timeout
:
60000
,
...
axiosConfig
(
userOpenAiKey
||
systemAuth
Key
)
...
axiosConfig
(
api
Key
)
}
}
)
)
.
then
((
res
)
=>
({
.
then
((
res
)
=>
({
...
@@ -70,7 +63,7 @@ export async function openaiEmbedding({
...
@@ -70,7 +63,7 @@ export async function openaiEmbedding({
}));
}));
pushGenerateVectorBill
({
pushGenerateVectorBill
({
isPay
:
!
userOpenAiKey
,
isPay
:
false
,
userId
,
userId
,
text
:
input
.
join
(
''
),
text
:
input
.
join
(
''
),
tokenLen
:
result
.
tokenLen
tokenLen
:
result
.
tokenLen
...
...
src/pages/api/user/getPayCode.ts
View file @
48fbc741
...
@@ -35,7 +35,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -35,7 +35,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
}
});
});
}
catch
(
err
)
{
}
catch
(
err
)
{
console
.
log
(
err
,
'=='
);
jsonRes
(
res
,
{
jsonRes
(
res
,
{
code
:
500
,
code
:
500
,
error
:
err
error
:
err
...
...
src/pages/chat/index.tsx
View file @
48fbc741
...
@@ -211,6 +211,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -211,6 +211,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
router
.
replace
(
`/chat?modelId=
${
modelId
}
&chatId=
${
newChatId
}
`
);
router
.
replace
(
`/chat?modelId=
${
modelId
}
&chatId=
${
newChatId
}
`
);
}
}
abortSignal
.
signal
.
aborted
&&
(
await
delay
(
500
));
// 设置聊天内容为完成状态
// 设置聊天内容为完成状态
setChatData
((
state
)
=>
({
setChatData
((
state
)
=>
({
...
state
,
...
state
,
...
...
src/pages/number/components/PayModal.tsx
View file @
48fbc741
...
@@ -16,6 +16,7 @@ import { getPayCode, checkPayResult } from '@/api/user';
...
@@ -16,6 +16,7 @@ import { getPayCode, checkPayResult } from '@/api/user';
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
getErrText
}
from
'@/utils/tools'
;
const
PayModal
=
({
onClose
}:
{
onClose
:
()
=>
void
})
=>
{
const
PayModal
=
({
onClose
}:
{
onClose
:
()
=>
void
})
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
...
@@ -39,12 +40,11 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
...
@@ -39,12 +40,11 @@ const PayModal = ({ onClose }: { onClose: () => void }) => {
correctLevel
:
QRCode
.
CorrectLevel
.
H
correctLevel
:
QRCode
.
CorrectLevel
.
H
});
});
setPayId
(
res
.
payId
);
setPayId
(
res
.
payId
);
}
catch
(
err
or
)
{
}
catch
(
err
)
{
toast
({
toast
({
title
:
'出现了一些意外...'
,
title
:
getErrText
(
err
)
,
status
:
'error'
status
:
'error'
});
});
console
.
log
(
error
);
}
}
setLoading
(
false
);
setLoading
(
false
);
},
[
inputVal
,
toast
]);
},
[
inputVal
,
toast
]);
...
...
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