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