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
75c8c425
authored
Jul 20, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: qa
parent
62ee28b1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
33 additions
and
20 deletions
+33
-20
client/data/config.json
+2
-1
client/src/hooks/useSendCode.ts
+2
-2
client/src/pages/_app.tsx
+5
-5
client/src/pages/api/user/sendAuthCode.ts
+2
-2
client/src/service/events/generateQA.ts
+12
-1
client/src/store/static.ts
+4
-5
client/src/types/index.d.ts
+2
-1
client/src/utils/plugin/google.ts
+4
-3
No files found.
client/data/config.json
View file @
75c8c425
...
...
@@ -10,8 +10,9 @@
},
"SystemParams"
:
{
"beianText"
:
""
,
"googleVerKey"
:
""
,
"baiduTongji"
:
""
,
"googleClientVerKey"
:
""
,
"googleServiceVerKey"
:
""
,
"vectorMaxProcess"
:
15
,
"qaMaxProcess"
:
15
,
"pgIvfflatProbe"
:
20
,
...
...
client/src/hooks/useSendCode.ts
View file @
75c8c425
...
...
@@ -4,7 +4,7 @@ import { UserAuthTypeEnum } from '@/constants/common';
let
timer
:
any
;
import
{
useToast
}
from
'./useToast'
;
import
{
getClientToken
}
from
'@/utils/plugin/google'
;
import
{
googleVerKey
}
from
'@/store/static'
;
import
{
google
Client
VerKey
}
from
'@/store/static'
;
export
const
useSendCode
=
()
=>
{
const
{
toast
}
=
useToast
();
...
...
@@ -27,7 +27,7 @@ export const useSendCode = () => {
await
sendAuthCode
({
username
,
type
,
googleToken
:
await
getClientToken
(
googleVerKey
)
googleToken
:
await
getClientToken
(
google
Client
VerKey
)
});
setCodeCountDown
(
60
);
timer
=
setInterval
(()
=>
{
...
...
client/src/pages/_app.tsx
View file @
75c8c425
...
...
@@ -31,7 +31,7 @@ const queryClient = new QueryClient({
});
function
App
({
Component
,
pageProps
,
isPc
}:
AppProps
&
{
isPc
?:
boolean
;
response
:
any
})
{
const
[
googleVerKey
,
setGoogleVerKey
]
=
useState
<
string
>
();
const
[
google
Client
VerKey
,
setGoogleVerKey
]
=
useState
<
string
>
();
const
[
baiduTongji
,
setBaiduTongji
]
=
useState
<
string
>
();
const
{
initIsPc
}
=
useGlobalStore
();
...
...
@@ -42,9 +42,9 @@ function App({ Component, pageProps, isPc }: AppProps & { isPc?: boolean; respon
useEffect
(()
=>
{
(
async
()
=>
{
const
{
systemEnv
:
{
googleVerKey
,
baiduTongji
}
systemEnv
:
{
google
Client
VerKey
,
baiduTongji
}
}
=
await
clientInitData
();
setGoogleVerKey
(
googleVerKey
);
setGoogleVerKey
(
google
Client
VerKey
);
setBaiduTongji
(
baiduTongji
);
})();
},
[]);
...
...
@@ -65,10 +65,10 @@ function App({ Component, pageProps, isPc }: AppProps & { isPc?: boolean; respon
<
Script
src=
"/js/pdf.js"
strategy=
"lazyOnload"
></
Script
>
<
Script
src=
"/js/html2pdf.bundle.min.js"
strategy=
"lazyOnload"
></
Script
>
{
baiduTongji
&&
<
Script
src=
{
baiduTongji
}
strategy=
"lazyOnload"
></
Script
>
}
{
googleVerKey
&&
(
{
google
Client
VerKey
&&
(
<>
<
Script
src=
{
`https://www.recaptcha.net/recaptcha/api.js?render=${googleVerKey}`
}
src=
{
`https://www.recaptcha.net/recaptcha/api.js?render=${google
Client
VerKey}`
}
strategy=
"afterInteractive"
></
Script
>
</>
...
...
client/src/pages/api/user/sendAuthCode.ts
View file @
75c8c425
...
...
@@ -23,9 +23,9 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
// google auth
process
.
env
.
SERVICE_GOOGLE_VER_TOKEN
&&
global
.
systemEnv
.
googleServiceVerKey
&&
(
await
authGoogleToken
({
secret
:
process
.
env
.
SERVICE_GOOGLE_VER_TOKEN
,
secret
:
global
.
systemEnv
.
googleServiceVerKey
,
response
:
googleToken
,
remoteip
:
requestIp
.
getClientIp
(
req
)
||
undefined
}));
...
...
client/src/service/events/generateQA.ts
View file @
75c8c425
...
...
@@ -7,6 +7,8 @@ import { sendInform } from '@/pages/api/user/inform/send';
import
{
authBalanceByUid
}
from
'../utils/auth'
;
import
{
axiosConfig
,
getOpenAIApi
}
from
'../ai/openai'
;
import
{
ChatCompletionRequestMessage
}
from
'openai'
;
import
{
modelToolMap
}
from
'@/utils/plugin'
;
import
{
gptMessage2ChatType
}
from
'@/utils/adapt'
;
const
reduceQueue
=
()
=>
{
global
.
qaQueueLen
=
global
.
qaQueueLen
>
0
?
global
.
qaQueueLen
-
1
:
0
;
...
...
@@ -58,6 +60,8 @@ export async function generateQA(): Promise<any> {
// 请求 chatgpt 获取回答
const
response
=
await
Promise
.
all
(
[
data
.
q
].
map
((
text
)
=>
{
const
modelTokenLimit
=
chatModels
.
find
((
item
)
=>
item
.
model
===
data
.
model
)?.
contextMaxToken
||
16000
;
const
messages
:
ChatCompletionRequestMessage
[]
=
[
{
role
:
'system'
,
...
...
@@ -74,13 +78,20 @@ A2:
content
:
text
}
];
const
promptsToken
=
modelToolMap
.
countTokens
({
messages
:
gptMessage2ChatType
(
messages
)
});
const
maxToken
=
modelTokenLimit
-
promptsToken
;
return
chatAPI
.
createChatCompletion
(
{
model
:
data
.
model
,
temperature
:
0.8
,
messages
,
stream
:
false
stream
:
false
,
max_tokens
:
maxToken
},
{
timeout
:
480000
,
...
...
client/src/store/static.ts
View file @
75c8c425
...
...
@@ -9,7 +9,7 @@ import { delay } from '@/utils/tools';
import
{
FeConfigsType
}
from
'@/types'
;
export
let
beianText
:
string
|
undefined
;
export
let
googleVerKey
:
string
|
undefined
;
export
let
google
Client
VerKey
:
string
|
undefined
;
export
let
baiduTongji
:
string
|
undefined
;
export
let
chatModelList
:
ChatModelItemType
[]
=
[];
export
let
qaModelList
:
QAModelItemType
[]
=
[];
...
...
@@ -26,10 +26,9 @@ export const clientInitData = async (): Promise<InitDateResponse> => {
qaModelList
=
res
.
qaModels
;
vectorModelList
=
res
.
vectorModels
;
feConfigs
=
res
.
feConfigs
;
beianText
=
res
.
systemEnv
.
beianText
;
googleVerKey
=
res
.
systemEnv
.
googleVerKey
;
baiduTongji
=
res
.
systemEnv
.
baiduTongji
;
console
.
log
(
res
);
beianText
=
res
.
systemEnv
?.
beianText
;
googleClientVerKey
=
res
.
systemEnv
?.
googleClientVerKey
;
baiduTongji
=
res
.
systemEnv
?.
baiduTongji
;
return
res
;
}
catch
(
error
)
{
...
...
client/src/types/index.d.ts
View file @
75c8c425
...
...
@@ -24,7 +24,8 @@ export type FeConfigsType = {
};
export
type
SystemEnvType
=
{
beianText
?:
string
;
googleVerKey
?:
string
;
googleClientVerKey
?:
string
;
googleServiceVerKey
?:
string
;
baiduTongji
?:
string
;
vectorMaxProcess
:
number
;
qaMaxProcess
:
number
;
...
...
client/src/utils/plugin/google.ts
View file @
75c8c425
import
axios
from
'axios'
;
import
{
Obj2Query
}
from
'../tools'
;
export
const
getClientToken
=
(
googleVerKey
:
string
)
=>
{
if
(
typeof
window
.
grecaptcha
===
'undefined'
||
!
window
.
grecaptcha
?.
ready
)
return
''
;
export
const
getClientToken
=
(
googleClientVerKey
?:
string
)
=>
{
if
(
!
googleClientVerKey
||
typeof
window
.
grecaptcha
===
'undefined'
||
!
window
.
grecaptcha
?.
ready
)
return
''
;
return
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
window
.
grecaptcha
.
ready
(
async
()
=>
{
try
{
const
token
=
await
window
.
grecaptcha
.
execute
(
googleVerKey
,
{
const
token
=
await
window
.
grecaptcha
.
execute
(
google
Client
VerKey
,
{
action
:
'submit'
});
resolve
(
token
);
...
...
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