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
2fc31a70
authored
May 29, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update model use time
parent
2fce7620
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
62 additions
and
44 deletions
+62
-44
src/api/chat.ts
+1
-1
src/pages/api/chat/history/getHistoryQuote.ts
+0
-0
src/pages/api/chat/saveChat.ts
+32
-23
src/pages/api/model/list.ts
+1
-1
src/pages/chat/index.tsx
+28
-19
No files found.
src/api/chat.ts
View file @
2fc31a70
...
@@ -62,7 +62,7 @@ export const createShareChat = (
...
@@ -62,7 +62,7 @@ export const createShareChat = (
)
=>
POST
<
string
>
(
`/chat/shareChat/create`
,
data
);
)
=>
POST
<
string
>
(
`/chat/shareChat/create`
,
data
);
/**
/**
* get
shareChat
* get shareChat
*/
*/
export
const
getShareChatList
=
(
modelId
:
string
)
=>
export
const
getShareChatList
=
(
modelId
:
string
)
=>
GET
<
ShareChatSchema
[]
>
(
`/chat/shareChat/list?modelId=
${
modelId
}
`
);
GET
<
ShareChatSchema
[]
>
(
`/chat/shareChat/list?modelId=
${
modelId
}
`
);
...
...
src/pages/api/chat/getHistoryQuote.ts
→
src/pages/api/chat/
history/
getHistoryQuote.ts
View file @
2fc31a70
File moved
src/pages/api/chat/saveChat.ts
View file @
2fc31a70
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
ChatItemType
}
from
'@/types/chat'
;
import
{
connectToDatabase
,
Chat
}
from
'@/service/mongo'
;
import
{
connectToDatabase
,
Chat
,
Model
}
from
'@/service/mongo'
;
import
{
authModel
}
from
'@/service/utils/auth'
;
import
{
authModel
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
{
authUser
}
from
'@/service/utils/auth'
;
import
mongoose
from
'mongoose'
;
import
mongoose
from
'mongoose'
;
...
@@ -65,27 +65,36 @@ export async function saveChat({
...
@@ -65,27 +65,36 @@ export async function saveChat({
}))
||
[]
}))
||
[]
}));
}));
// 没有 chatId, 创建一个对话
const
[
id
]
=
await
Promise
.
all
([
if
(
!
chatId
)
{
...(
chatId
// update chat
const
{
_id
}
=
await
Chat
.
create
({
?
[
_id
:
newChatId
?
new
mongoose
.
Types
.
ObjectId
(
newChatId
)
:
undefined
,
Chat
.
findByIdAndUpdate
(
chatId
,
{
userId
,
$push
:
{
modelId
,
content
:
{
content
,
$each
:
content
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
}
latestChat
:
content
[
1
].
value
},
});
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
return
_id
;
latestChat
:
content
[
1
].
value
,
}
else
{
updateTime
:
new
Date
()
await
Chat
.
findByIdAndUpdate
(
chatId
,
{
}).
then
(()
=>
''
)
$push
:
{
]
content
:
{
:
[
$each
:
content
Chat
.
create
({
}
_id
:
newChatId
?
new
mongoose
.
Types
.
ObjectId
(
newChatId
)
:
undefined
,
},
userId
,
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
modelId
,
latestChat
:
content
[
1
].
value
,
content
,
title
:
content
[
0
].
value
.
slice
(
0
,
20
),
latestChat
:
content
[
1
].
value
}).
then
((
res
)
=>
res
.
_id
)
]),
Model
.
findByIdAndUpdate
(
modelId
,
{
updateTime
:
new
Date
()
updateTime
:
new
Date
()
});
})
// update model
}
]);
return
{
id
};
}
}
src/pages/api/model/list.ts
View file @
2fc31a70
...
@@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
...
@@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
},
},
'_id avatar name chat.systemPrompt'
'_id avatar name chat.systemPrompt'
).
sort
({
).
sort
({
_id
:
-
1
updateTime
:
-
1
}),
}),
Collection
.
find
({
userId
})
Collection
.
find
({
userId
})
.
populate
({
.
populate
({
...
...
src/pages/chat/index.tsx
View file @
2fc31a70
...
@@ -105,7 +105,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -105,7 +105,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
const
{
copyData
}
=
useCopyData
();
const
{
copyData
}
=
useCopyData
();
const
{
isPc
}
=
useGlobalStore
();
const
{
isPc
}
=
useGlobalStore
();
const
{
Loading
,
setIsLoading
}
=
useLoading
();
const
{
Loading
,
setIsLoading
}
=
useLoading
();
const
{
userInfo
}
=
useUserStore
();
const
{
userInfo
,
loadMyModels
}
=
useUserStore
();
const
{
isOpen
:
isOpenSlider
,
onClose
:
onCloseSlider
,
onOpen
:
onOpenSlider
}
=
useDisclosure
();
const
{
isOpen
:
isOpenSlider
,
onClose
:
onCloseSlider
,
onOpen
:
onOpenSlider
}
=
useDisclosure
();
// close contextMenu
// close contextMenu
...
@@ -228,13 +228,21 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -228,13 +228,21 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
})
})
}));
}));
// refresh history
// refresh data
setTimeout
(()
=>
{
loadHistory
({
pageNum
:
1
,
init
:
true
});
loadHistory
({
pageNum
:
1
,
init
:
true
});
loadMyModels
(
true
);
generatingMessage
();
generatingMessage
();
},
100
);
},
},
[
chatId
,
setForbidLoadChatData
,
generatingMessage
,
loadHistory
,
modelId
,
router
,
setChatData
]
[
chatId
,
modelId
,
setChatData
,
loadHistory
,
loadMyModels
,
generatingMessage
,
setForbidLoadChatData
,
router
]
);
);
/**
/**
...
@@ -458,14 +466,14 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -458,14 +466,14 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
async ({
async ({
modelId,
modelId,
chatId,
chatId,
isL
oading = false
l
oading = false
}: {
}: {
modelId: string;
modelId: string;
chatId: string;
chatId: string;
isL
oading?: boolean;
l
oading?: boolean;
}) => {
}) => {
isLoading && setIsLoading(true);
try {
try {
loading && setIsLoading(true);
const res = await getInitChatSiteInfo(modelId, chatId);
const res = await getInitChatSiteInfo(modelId, chatId);
setChatData({
setChatData({
...
@@ -500,18 +508,18 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -500,18 +508,18 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
return null;
return null;
},
},
[
[
router,
loadHistory,
setForbidLoadChatData,
scrollToBottom,
setChatData,
setIsLoading,
setIsLoading,
setChatData,
scrollToBottom,
setForbidLoadChatData,
router,
setLastChatModelId,
setLastChatId,
setLastChatId,
setLastChatModelId
loadHistory
]
]
);
);
// 初始化聊天框
// 初始化聊天框
const { isLoading } =
useQuery(['init', modelId, chatId], () => {
useQuery(['init', modelId, chatId], () => {
// pc: redirect to latest model chat
// pc: redirect to latest model chat
if (!modelId && lastChatModelId) {
if (!modelId && lastChatModelId) {
router.replace(`/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`);
router.replace(`/chat?modelId=${lastChatModelId}&chatId=${lastChatId}`);
...
@@ -529,7 +537,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -529,7 +537,8 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
return loadChatInfo({
return loadChatInfo({
modelId,
modelId,
chatId
chatId,
loading: true
});
});
});
});
...
@@ -874,7 +883,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
...
@@ -874,7 +883,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
</Box>
</Box>
)}
)}
<Loading
loading={isLoading}
fixed={false} />
<Loading fixed={false} />
</Flex>
</Flex>
)}
)}
...
...
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