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
38d49ea0
authored
Mar 10, 2023
by
Archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 错误提示
parent
453f3be8
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
38 additions
and
33 deletions
+38
-33
src/pages/api/chat/chatGpt.ts
+3
-3
src/pages/login/components/ForgetPasswordForm.tsx
+3
-5
src/pages/login/components/LoginForm.tsx
+3
-5
src/pages/login/components/RegisterForm.tsx
+3
-6
src/pages/login/index.tsx
+6
-2
src/pages/model/detail.tsx
+6
-2
src/pages/model/list.tsx
+8
-2
src/service/mongo.ts
+2
-5
src/types/index.d.ts
+3
-3
tsconfig.json
+1
-0
No files found.
src/pages/api/chat/chatGpt.ts
View file @
38d49ea0
...
...
@@ -50,13 +50,13 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const
formatPrompts
:
ChatCompletionRequestMessage
[]
=
filterPrompts
.
map
(
(
item
:
ChatItemType
)
=>
({
role
:
map
[
item
.
obj
],
content
:
item
.
value
.
replace
(
/
\n
/g
,
' '
)
content
:
item
.
value
})
);
// 第一句话,强调代码类型
formatPrompts
.
unshift
({
role
:
ChatCompletionRequestMessageRoleEnum
.
System
,
content
:
'如果你想返回代码,请务必声明代码的类型!'
content
:
'如果你想返回代码,请务必声明代码的类型!
并且在代码块前加一个换行符。
'
});
// 获取 chatAPI
const
chatAPI
=
getOpenAIApi
(
userApiKey
);
...
...
@@ -100,7 +100,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
try
{
const
json
=
JSON
.
parse
(
data
);
const
content
:
string
=
json
.
choices
[
0
].
delta
.
content
||
''
;
const
content
:
string
=
json
.
choices
[
0
].
delta
.
content
||
'
\n
'
;
// console.log('content:', content)
res
.
write
(
`event: responseData\ndata:
${
content
.
replace
(
/
\n
/g
,
'<br/>'
)}
\n\n`
);
AIResponse
+=
content
;
...
...
src/pages/login/components/ForgetPasswordForm.tsx
View file @
38d49ea0
...
...
@@ -61,12 +61,10 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
title
:
`密码已找回`
,
status
:
'success'
});
}
catch
(
error
)
{
typeof
error
===
'string'
&&
}
catch
(
error
:
any
)
{
toast
({
title
:
error
,
status
:
'error'
,
position
:
'top'
title
:
error
.
message
||
'修改密码异常'
,
status
:
'error'
});
}
setRequesting
(
false
);
...
...
src/pages/login/components/LoginForm.tsx
View file @
38d49ea0
...
...
@@ -42,12 +42,10 @@ const LoginForm = ({ setPageType, loginSuccess }: Props) => {
title
:
'登录成功'
,
status
:
'success'
});
}
catch
(
error
)
{
typeof
error
===
'string'
&&
}
catch
(
error
:
any
)
{
toast
({
title
:
error
,
status
:
'error'
,
position
:
'top'
title
:
error
.
message
||
'登录异常'
,
status
:
'error'
});
}
setRequesting
(
false
);
...
...
src/pages/login/components/RegisterForm.tsx
View file @
38d49ea0
...
...
@@ -61,13 +61,10 @@ const RegisterForm = ({ setPageType, loginSuccess }: Props) => {
title
:
`注册成功`
,
status
:
'success'
});
}
catch
(
error
)
{
typeof
error
===
'string'
&&
}
catch
(
error
:
any
)
{
toast
({
title
:
error
,
status
:
'error'
,
duration
:
4000
,
isClosable
:
true
title
:
error
.
message
||
'注册异常'
,
status
:
'error'
});
}
setRequesting
(
false
);
...
...
src/pages/login/index.tsx
View file @
38d49ea0
import
React
,
{
useState
,
useCallback
,
use
Memo
}
from
'react'
;
import
React
,
{
useState
,
useCallback
,
use
Effect
}
from
'react'
;
import
styles
from
'./index.module.scss'
;
import
{
Box
,
Flex
,
Image
}
from
'@chakra-ui/react'
;
import
{
PageTypeEnum
}
from
'@/constants/user'
;
...
...
@@ -21,7 +21,7 @@ const Login = () => {
const
loginSuccess
=
useCallback
(
(
res
:
ResLogin
)
=>
{
setUserInfo
(
res
.
user
,
res
.
token
);
router
.
push
(
'/'
);
router
.
push
(
'/
model/list
'
);
},
[
router
,
setUserInfo
]
);
...
...
@@ -38,6 +38,10 @@ const Login = () => {
return
<
Component
setPageType=
{
setPageType
}
loginSuccess=
{
loginSuccess
}
/>;
}
useEffect
(()
=>
{
router
.
prefetch
(
'/model/list'
);
},
[
router
]);
return
(
<
Box
className=
{
styles
.
loginPage
}
h=
{
'100%'
}
p=
{
isPc
?
'10vh 10vw'
:
0
}
>
<
Flex
...
...
src/pages/model/detail.tsx
View file @
38d49ea0
...
...
@@ -120,11 +120,15 @@ const ModelDetail = () => {
try
{
await
putModelTrainingStatus
(
model
.
_id
);
loadModel
();
}
catch
(
error
)
{
}
catch
(
error
:
any
)
{
console
.
error
(
error
);
toast
({
title
:
error
.
message
||
'更新失败'
,
status
:
'error'
});
}
setLoading
(
false
);
},
[
setLoading
,
loadModel
,
model
]);
},
[
model
,
setLoading
,
loadModel
,
toast
]);
return
(
<>
...
...
src/pages/model/list.tsx
View file @
38d49ea0
...
...
@@ -10,10 +10,12 @@ import { useScreen } from '@/hooks/useScreen';
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useLoading
}
from
'@/hooks/useLoading'
;
import
dynamic
from
'next/dynamic'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
const
CreateModel
=
dynamic
(()
=>
import
(
'./components/CreateModel'
));
const
ModelList
=
()
=>
{
const
{
toast
}
=
useToast
();
const
{
isPc
}
=
useScreen
();
const
router
=
useRouter
();
const
[
models
,
setModels
]
=
useState
<
ModelType
[]
>
([]);
...
...
@@ -43,12 +45,16 @@ const ModelList = () => {
router
.
push
(
`/chat?chatId=
${
chatId
}
`
,
undefined
,
{
shallow
:
true
});
}
catch
(
err
)
{
}
catch
(
err
:
any
)
{
console
.
error
(
err
);
toast
({
title
:
err
.
message
||
'出现一些异常'
,
status
:
'error'
});
}
setIsLoading
(
false
);
},
[
router
,
setIsLoading
]
[
router
,
setIsLoading
,
toast
]
);
return
(
...
...
src/service/mongo.ts
View file @
38d49ea0
import
mongoose
from
'mongoose'
;
import
mongoose
,
{
Mongoose
}
from
'mongoose'
;
/**
* 连接 MongoDB 数据库
*/
export
async
function
connectToDatabase
():
Promise
<
void
>
{
// @ts-ignore
if
(
global
.
mongodb
)
{
return
;
}
// @ts-ignore
global
.
mongodb
=
'connecting'
;
console
.
log
(
'connect mongo'
);
try
{
// @ts-ignore
global
.
mongodb
=
await
mongoose
.
connect
(
process
.
env
.
MONGODB_URI
as
string
,
{
dbName
:
'doc_gpt'
,
maxPoolSize
:
10
,
...
...
@@ -20,7 +18,6 @@ export async function connectToDatabase(): Promise<void> {
});
}
catch
(
error
)
{
console
.
error
(
'mongo connect error'
);
// @ts-ignore
global
.
mongodb
=
null
;
}
}
...
...
src/types/index.d.ts
View file @
38d49ea0
import
type
{
Mongoose
}
from
'mongoose'
;
declare
global
{
namespace
NodeJS
{
interface
Global
{
mongodb
:
Mongoose
;
mongodb
:
Mongoose
|
string
;
}
}
}
export
type
a
=
string
;
tsconfig.json
View file @
38d49ea0
...
...
@@ -3,6 +3,7 @@
"target"
:
"es5"
,
"lib"
:
[
"dom"
,
"dom.iterable"
,
"esnext"
],
"allowJs"
:
true
,
"noImplicitAny"
:
true
,
"skipLibCheck"
:
true
,
"strict"
:
true
,
"forceConsistentCasingInFileNames"
:
true
,
...
...
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