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
aef42cef
authored
Jul 08, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: attribute
parent
23642af6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
81 additions
and
80 deletions
+81
-80
client/src/components/Icon/icons/light/chat.svg
+2
-0
client/src/components/Icon/index.tsx
+2
-1
client/src/components/Layout/navbar.tsx
+1
-1
client/src/components/Layout/navbarPhone.tsx
+1
-1
client/src/constants/app.ts
+0
-0
client/src/pages/api/openapi/modules/kb/search.ts
+6
-0
client/src/pages/app/detail/components/Settings.tsx
+1
-1
client/src/pages/app/detail/components/edit/components/TemplateList.tsx
+2
-2
client/src/pages/app/detail/components/edit/index.tsx
+1
-0
client/src/pages/app/detail/index.tsx
+3
-3
client/src/pages/app/list/component/CreateModal.tsx
+6
-37
client/src/pages/app/list/index.tsx
+26
-2
client/src/pages/appStore/components/list.tsx
+1
-1
client/src/pages/chat/components/History.tsx
+4
-4
client/src/pages/chat/components/ModelList.tsx
+1
-1
client/src/pages/chat/components/PhoneSliderBar.tsx
+4
-4
client/src/pages/chat/index.tsx
+20
-22
No files found.
client/src/components/Icon/icons/light/chat.svg
0 → 100644
View file @
aef42cef
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg
t=
"1688783528309"
class=
"icon"
viewBox=
"0 0 1024 1024"
version=
"1.1"
xmlns=
"http://www.w3.org/2000/svg"
p-id=
"5845"
xmlns:xlink=
"http://www.w3.org/1999/xlink"
><path
d=
"M931.53 960H512C264.97 960 64 759.03 64 512S264.97 64 512 64s448 200.97 448 448v419.53c0 15.69-12.77 28.47-28.47 28.47zM512 116.71c-217.96 0-395.29 177.33-395.29 395.29 0 217.97 177.33 395.3 395.29 395.3h395.29V512c0-217.97-177.33-395.29-395.29-395.29z"
fill=
"#333333"
p-id=
"5846"
></path><path
d=
"M730.13 439.04H293.87c-14.55 0-26.35-11.8-26.35-26.35s11.8-26.35 26.35-26.35h436.26c14.55 0 26.35 11.8 26.35 26.35s-11.8 26.35-26.35 26.35zM730.13 637.67H293.87c-14.55 0-26.35-11.8-26.35-26.35s11.8-26.35 26.35-26.35h436.26c14.55 0 26.35 11.8 26.35 26.35s-11.8 26.35-26.35 26.35z"
p-id=
"5847"
></path></svg>
\ No newline at end of file
client/src/components/Icon/index.tsx
View file @
aef42cef
...
@@ -36,7 +36,8 @@ const map = {
...
@@ -36,7 +36,8 @@ const map = {
date
:
require
(
'./icons/date.svg'
).
default
,
date
:
require
(
'./icons/date.svg'
).
default
,
apikey
:
require
(
'./icons/apikey.svg'
).
default
,
apikey
:
require
(
'./icons/apikey.svg'
).
default
,
save
:
require
(
'./icons/save.svg'
).
default
,
save
:
require
(
'./icons/save.svg'
).
default
,
minus
:
require
(
'./icons/minus.svg'
).
default
minus
:
require
(
'./icons/minus.svg'
).
default
,
chatLight
:
require
(
'./icons/light/chat.svg'
).
default
};
};
export
type
IconName
=
keyof
typeof
map
;
export
type
IconName
=
keyof
typeof
map
;
...
...
client/src/components/Layout/navbar.tsx
View file @
aef42cef
...
@@ -23,7 +23,7 @@ const Navbar = ({ unread }: { unread: number }) => {
...
@@ -23,7 +23,7 @@ const Navbar = ({ unread }: { unread: number }) => {
{
{
label
:
'聊天'
,
label
:
'聊天'
,
icon
:
'chat'
,
icon
:
'chat'
,
link
:
`/chat?
model
Id=
${
lastChatModelId
}
&chatId=
${
lastChatId
}
`
,
link
:
`/chat?
app
Id=
${
lastChatModelId
}
&chatId=
${
lastChatId
}
`
,
activeLink
:
[
'/chat'
]
activeLink
:
[
'/chat'
]
},
},
{
{
...
...
client/src/components/Layout/navbarPhone.tsx
View file @
aef42cef
...
@@ -13,7 +13,7 @@ const NavbarPhone = ({ unread }: { unread: number }) => {
...
@@ -13,7 +13,7 @@ const NavbarPhone = ({ unread }: { unread: number }) => {
{
{
label
:
'聊天'
,
label
:
'聊天'
,
icon
:
'tabbarChat'
,
icon
:
'tabbarChat'
,
link
:
`/chat?
model
Id=
${
lastChatModelId
}
&chatId=
${
lastChatId
}
`
,
link
:
`/chat?
app
Id=
${
lastChatModelId
}
&chatId=
${
lastChatId
}
`
,
activeLink
:
[
'/chat'
],
activeLink
:
[
'/chat'
],
unread
:
0
unread
:
0
},
},
...
...
client/src/constants/app.ts
View file @
aef42cef
This diff is collapsed.
Click to expand it.
client/src/pages/api/openapi/modules/kb/search.ts
View file @
aef42cef
...
@@ -72,6 +72,12 @@ export async function kbSearch({
...
@@ -72,6 +72,12 @@ export async function kbSearch({
maxToken
=
2500
,
maxToken
=
2500
,
userChatInput
userChatInput
}:
Props
):
Promise
<
Response
>
{
}:
Props
):
Promise
<
Response
>
{
if
(
kb_ids
.
length
===
0
)
return
{
isEmpty
:
true
,
rawSearch
:
[],
quotePrompt
:
undefined
};
// get vector
// get vector
const
promptVector
=
await
openaiEmbedding_system
({
const
promptVector
=
await
openaiEmbedding_system
({
input
:
[
userChatInput
]
input
:
[
userChatInput
]
...
...
client/src/pages/app/detail/components/Settings.tsx
View file @
aef42cef
...
@@ -238,7 +238,7 @@ const Settings = ({ modelId }: { modelId: string }) => {
...
@@ -238,7 +238,7 @@ const Settings = ({ modelId }: { modelId: string }) => {
router
.
prefetch
(
'/chat'
);
router
.
prefetch
(
'/chat'
);
await
saveUpdateModel
();
await
saveUpdateModel
();
}
catch
(
error
)
{}
}
catch
(
error
)
{}
router
.
push
(
`/chat?
model
Id=${modelId}`
);
router
.
push
(
`/chat?
app
Id=${modelId}`
);
}
}
}
}
>
>
对话
对话
...
...
client/src/pages/app/detail/components/edit/components/TemplateList.tsx
View file @
aef42cef
...
@@ -31,8 +31,8 @@ const ModuleStoreList = ({
...
@@ -31,8 +31,8 @@ const ModuleStoreList = ({
position=
{
'fixed'
}
position=
{
'fixed'
}
top=
{
0
}
top=
{
0
}
left=
{
0
}
left=
{
0
}
right=
{
0
}
bottom=
{
0
}
bottom=
{
0
}
w=
{
'360px'
}
></
Box
>
></
Box
>
<
Flex
<
Flex
zIndex=
{
3
}
zIndex=
{
3
}
...
@@ -66,7 +66,7 @@ const ModuleStoreList = ({
...
@@ -66,7 +66,7 @@ const ModuleStoreList = ({
borderRadius=
{
'md'
}
borderRadius=
{
'md'
}
draggable
draggable
onDragEnd=
{
(
e
)
=>
{
onDragEnd=
{
(
e
)
=>
{
// if (e.clientX < 40
0) return;
if
(
e
.
clientX
<
36
0
)
return
;
onAddNode
({
onAddNode
({
template
:
item
,
template
:
item
,
position
:
{
x
:
e
.
clientX
,
y
:
e
.
clientY
}
position
:
{
x
:
e
.
clientX
,
y
:
e
.
clientY
}
...
...
client/src/pages/app/detail/components/edit/index.tsx
View file @
aef42cef
...
@@ -187,6 +187,7 @@ const AppEdit = ({ app, onBack }: Props) => {
...
@@ -187,6 +187,7 @@ const AppEdit = ({ app, onBack }: Props) => {
targets
:
[]
as
FlowOutputTargetItemType
[]
targets
:
[]
as
FlowOutputTargetItemType
[]
}))
}))
}));
}));
console
.
log
(
modules
);
// update inputs and outputs
// update inputs and outputs
modules
.
forEach
((
module
)
=>
{
modules
.
forEach
((
module
)
=>
{
...
...
client/src/pages/app/detail/index.tsx
View file @
aef42cef
...
@@ -83,7 +83,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
...
@@ -83,7 +83,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
<
Box
display=
{
[
'block'
,
'flex'
]
}
h=
{
'100%'
}
>
<
Box
display=
{
[
'block'
,
'flex'
]
}
h=
{
'100%'
}
>
{
/* pc tab */
}
{
/* pc tab */
}
<
Box
display=
{
[
'none'
,
'block'
]
}
p=
{
4
}
w=
{
'200px'
}
borderRight=
{
theme
.
borders
.
base
}
>
<
Box
display=
{
[
'none'
,
'block'
]
}
p=
{
4
}
w=
{
'200px'
}
borderRight=
{
theme
.
borders
.
base
}
>
<
Flex
mb=
{
4
}
>
<
Flex
mb=
{
4
}
alignItems=
{
'center'
}
>
<
Avatar
src=
{
appDetail
.
avatar
}
w=
{
'34px'
}
borderRadius=
{
'lg'
}
/>
<
Avatar
src=
{
appDetail
.
avatar
}
w=
{
'34px'
}
borderRadius=
{
'lg'
}
/>
<
Box
ml=
{
2
}
fontWeight=
{
'bold'
}
>
<
Box
ml=
{
2
}
fontWeight=
{
'bold'
}
>
{
appDetail
.
name
}
{
appDetail
.
name
}
...
@@ -97,7 +97,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
...
@@ -97,7 +97,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
activeId=
{
currentTab
}
activeId=
{
currentTab
}
onChange=
{
(
e
:
any
)
=>
{
onChange=
{
(
e
:
any
)
=>
{
if
(
e
===
'startChat'
)
{
if
(
e
===
'startChat'
)
{
router
.
push
(
`/chat?
model
Id=${appId}`
);
router
.
push
(
`/chat?
app
Id=${appId}`
);
}
else
{
}
else
{
setCurrentTab
(
e
);
setCurrentTab
(
e
);
}
}
...
@@ -118,7 +118,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
...
@@ -118,7 +118,7 @@ const AppDetail = ({ currentTab }: { currentTab: `${TabEnum}` }) => {
activeId=
{
currentTab
}
activeId=
{
currentTab
}
onChange=
{
(
e
:
any
)
=>
{
onChange=
{
(
e
:
any
)
=>
{
if
(
e
===
'startChat'
)
{
if
(
e
===
'startChat'
)
{
router
.
push
(
`/chat?
model
Id=${appId}`
);
router
.
push
(
`/chat?
app
Id=${appId}`
);
}
else
{
}
else
{
setCurrentTab
(
e
);
setCurrentTab
(
e
);
}
}
...
...
client/src/pages/app/list/component/CreateModal.tsx
View file @
aef42cef
...
@@ -21,47 +21,16 @@ import { getErrText } from '@/utils/tools';
...
@@ -21,47 +21,16 @@ import { getErrText } from '@/utils/tools';
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
useToast
}
from
'@/hooks/useToast'
;
import
{
postCreateApp
}
from
'@/api/app'
;
import
{
postCreateApp
}
from
'@/api/app'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
chatAppDemo
}
from
'@/constants/app'
;
import
{
appTemplates
}
from
'@/constants/app'
;
import
Avatar
from
'@/components/Avatar'
;
import
Avatar
from
'@/components/Avatar'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
type
FormType
=
{
type
FormType
=
{
avatar
:
string
;
avatar
:
string
;
name
:
string
;
name
:
string
;
templateId
:
number
;
templateId
:
string
;
};
};
const
templates
=
[
{
id
:
0
,
icon
:
'settings'
,
name
:
'简单的对话'
,
intro
:
'一个极其简单的 AI 对话应用'
,
modules
:
chatAppDemo
.
modules
},
{
id
:
1
,
icon
:
'settings'
,
name
:
'基础知识库'
,
intro
:
'每次提问时进行一次知识库搜索,将搜索结果注入 LLM 模型进行参考回答'
,
modules
:
chatAppDemo
.
modules
},
{
id
:
2
,
icon
:
'settings'
,
name
:
'问答前引导'
,
intro
:
'可以在每次对话开始前提示用户填写一些内容,作为本次对话的永久内容'
,
modules
:
chatAppDemo
.
modules
},
{
id
:
3
,
icon
:
'settings'
,
name
:
'意图识别 + 知识库'
,
intro
:
'先对用户的问题进行分类,再根据不同类型问题,执行不同的操作'
,
modules
:
chatAppDemo
.
modules
}
];
const
CreateModal
=
({
onClose
,
onSuccess
}:
{
onClose
:
()
=>
void
;
onSuccess
:
()
=>
void
})
=>
{
const
CreateModal
=
({
onClose
,
onSuccess
}:
{
onClose
:
()
=>
void
;
onSuccess
:
()
=>
void
})
=>
{
const
[
refresh
,
setRefresh
]
=
useState
(
false
);
const
[
refresh
,
setRefresh
]
=
useState
(
false
);
const
[
creating
,
setCreating
]
=
useState
(
false
);
const
[
creating
,
setCreating
]
=
useState
(
false
);
...
@@ -72,7 +41,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
...
@@ -72,7 +41,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
defaultValues
:
{
defaultValues
:
{
avatar
:
'/icon/logo.png'
,
avatar
:
'/icon/logo.png'
,
name
:
''
,
name
:
''
,
templateId
:
0
templateId
:
appTemplates
[
0
].
id
}
}
});
});
...
@@ -110,7 +79,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
...
@@ -110,7 +79,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
const
id
=
await
postCreateApp
({
const
id
=
await
postCreateApp
({
avatar
:
data
.
avatar
,
avatar
:
data
.
avatar
,
name
:
data
.
name
,
name
:
data
.
name
,
modules
:
t
emplates
.
find
((
item
)
=>
item
.
id
===
data
.
templateId
)?.
modules
||
[]
modules
:
appT
emplates
.
find
((
item
)
=>
item
.
id
===
data
.
templateId
)?.
modules
||
[]
});
});
toast
({
toast
({
title
:
'创建成功'
,
title
:
'创建成功'
,
...
@@ -163,7 +132,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
...
@@ -163,7 +132,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
gridTemplateColumns=
{
[
'repeat(1,1fr)'
,
'repeat(2,1fr)'
]
}
gridTemplateColumns=
{
[
'repeat(1,1fr)'
,
'repeat(2,1fr)'
]
}
gridGap=
{
4
}
gridGap=
{
4
}
>
>
{
t
emplates
.
map
((
item
)
=>
(
{
appT
emplates
.
map
((
item
)
=>
(
<
Card
<
Card
key=
{
item
.
id
}
key=
{
item
.
id
}
border=
{
theme
.
borders
.
base
}
border=
{
theme
.
borders
.
base
}
...
@@ -186,7 +155,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
...
@@ -186,7 +155,7 @@ const CreateModal = ({ onClose, onSuccess }: { onClose: () => void; onSuccess: (
}
}
}
}
>
>
<
Flex
alignItems=
{
'center'
}
>
<
Flex
alignItems=
{
'center'
}
>
<
MyIcon
name=
{
'apikey'
}
w=
{
'16
px'
}
/>
<
Avatar
src=
{
item
.
avatar
}
borderRadius=
{
'md'
}
w=
{
'20
px'
}
/>
<
Box
ml=
{
3
}
fontWeight=
{
'bold'
}
>
<
Box
ml=
{
3
}
fontWeight=
{
'bold'
}
>
{
item
.
name
}
{
item
.
name
}
</
Box
>
</
Box
>
...
...
client/src/pages/app/list/index.tsx
View file @
aef42cef
...
@@ -89,22 +89,27 @@ const MyApps = () => {
...
@@ -89,22 +89,27 @@ const MyApps = () => {
border=
{
theme
.
borders
.
md
}
border=
{
theme
.
borders
.
md
}
boxShadow=
{
'none'
}
boxShadow=
{
'none'
}
userSelect=
{
'none'
}
userSelect=
{
'none'
}
position=
{
'relative'
}
_hover=
{
{
_hover=
{
{
boxShadow
:
'1px 1px 10px rgba(0,0,0,0.2)'
,
boxShadow
:
'1px 1px 10px rgba(0,0,0,0.2)'
,
borderColor
:
'transparent'
,
borderColor
:
'transparent'
,
'& .delete'
:
{
'& .delete'
:
{
display
:
'block'
display
:
'block'
},
'& .chat'
:
{
display
:
'block'
}
}
}
}
}
}
onClick=
{
()
=>
router
.
push
(
`/app/detail?appId=${app._id}`
)
}
onClick=
{
()
=>
router
.
push
(
`/app/detail?appId=${app._id}`
)
}
>
>
<
Flex
alignItems=
{
'center'
}
h=
{
'38px'
}
position=
{
'relative'
}
>
<
Flex
alignItems=
{
'center'
}
h=
{
'38px'
}
>
<
Avatar
src=
{
app
.
avatar
}
borderRadius=
{
'md'
}
w=
{
'28px'
}
/>
<
Avatar
src=
{
app
.
avatar
}
borderRadius=
{
'md'
}
w=
{
'28px'
}
/>
<
Box
ml=
{
3
}
>
{
app
.
name
}
</
Box
>
<
Box
ml=
{
3
}
>
{
app
.
name
}
</
Box
>
<
IconButton
<
IconButton
className=
"delete"
className=
"delete"
position=
{
'absolute'
}
position=
{
'absolute'
}
right=
{
0
}
top=
{
4
}
right=
{
4
}
size=
{
'sm'
}
size=
{
'sm'
}
icon=
{
<
MyIcon
name=
{
'delete'
}
w=
{
'14px'
}
/>
}
icon=
{
<
MyIcon
name=
{
'delete'
}
w=
{
'14px'
}
/>
}
variant=
{
'base'
}
variant=
{
'base'
}
...
@@ -129,6 +134,25 @@ const MyApps = () => {
...
@@ -129,6 +134,25 @@ const MyApps = () => {
>
>
{
app
.
intro
||
'这个应用还没写介绍~'
}
{
app
.
intro
||
'这个应用还没写介绍~'
}
</
Box
>
</
Box
>
<
IconButton
className=
"chat"
position=
{
'absolute'
}
right=
{
4
}
bottom=
{
4
}
size=
{
'sm'
}
icon=
{
<
MyIcon
name=
{
'chatLight'
}
w=
{
'14px'
}
/>
}
variant=
{
'base'
}
borderRadius=
{
'md'
}
aria
-
label=
{
'delete'
}
display=
{
[
''
,
'none'
]
}
_hover=
{
{
bg
:
'myGray.100'
}
}
onClick=
{
(
e
)
=>
{
e
.
stopPropagation
();
router
.
push
(
`/chat?appId=${app._id}`
);
}
}
/>
</
Card
>
</
Card
>
))
}
))
}
</
Grid
>
</
Grid
>
...
...
client/src/pages/appStore/components/list.tsx
View file @
aef42cef
...
@@ -77,7 +77,7 @@ const ShareModelList = ({
...
@@ -77,7 +77,7 @@ const ShareModelList = ({
size=
{
'sm'
}
size=
{
'sm'
}
variant=
{
'base'
}
variant=
{
'base'
}
w=
{
[
'60px'
,
'70px'
]
}
w=
{
[
'60px'
,
'70px'
]
}
onClick=
{
()
=>
router
.
push
(
`/chat?
model
Id=${model._id}`
)
}
onClick=
{
()
=>
router
.
push
(
`/chat?
app
Id=${model._id}`
)
}
>
>
体验
体验
</
Button
>
</
Button
>
...
...
client/src/pages/chat/components/History.tsx
View file @
aef42cef
...
@@ -125,7 +125,7 @@ const PcSliderBar = ({
...
@@ -125,7 +125,7 @@ const PcSliderBar = ({
w=
{
'100%'
}
w=
{
'100%'
}
h=
{
'100%'
}
h=
{
'100%'
}
leftIcon=
{
<
AddIcon
/>
}
leftIcon=
{
<
AddIcon
/>
}
onClick=
{
()
=>
router
.
replace
(
`/chat?
model
Id=${modelId}`
)
}
onClick=
{
()
=>
router
.
replace
(
`/chat?
app
Id=${modelId}`
)
}
>
>
新对话
新对话
</
Button
>
</
Button
>
...
@@ -176,9 +176,9 @@ const PcSliderBar = ({
...
@@ -176,9 +176,9 @@ const PcSliderBar = ({
onClick=
{
()
=>
{
onClick=
{
()
=>
{
if
(
item
.
_id
===
chatId
)
return
;
if
(
item
.
_id
===
chatId
)
return
;
if
(
isPc
)
{
if
(
isPc
)
{
router
.
replace
(
`/chat?
model
Id=${item.modelId}&chatId=${item._id}`
);
router
.
replace
(
`/chat?
app
Id=${item.modelId}&chatId=${item._id}`
);
}
else
{
}
else
{
router
.
push
(
`/chat?
model
Id=${item.modelId}&chatId=${item._id}`
);
router
.
push
(
`/chat?
app
Id=${item.modelId}&chatId=${item._id}`
);
}
}
}
}
}
}
onContextMenu=
{
(
e
)
=>
onclickContextMenu
(
e
,
item
)
}
onContextMenu=
{
(
e
)
=>
onclickContextMenu
(
e
,
item
)
}
...
@@ -251,7 +251,7 @@ const PcSliderBar = ({
...
@@ -251,7 +251,7 @@ const PcSliderBar = ({
try
{
try
{
await
onclickDelHistory
(
contextMenuData
.
history
.
_id
);
await
onclickDelHistory
(
contextMenuData
.
history
.
_id
);
if
(
contextMenuData
.
history
.
_id
===
chatId
)
{
if
(
contextMenuData
.
history
.
_id
===
chatId
)
{
router
.
replace
(
`/chat?
model
Id=${modelId}`
);
router
.
replace
(
`/chat?
app
Id=${modelId}`
);
}
}
}
catch
(
error
)
{
}
catch
(
error
)
{
console
.
log
(
error
);
console
.
log
(
error
);
...
...
client/src/pages/chat/components/ModelList.tsx
View file @
aef42cef
...
@@ -30,7 +30,7 @@ const ModelList = ({ models, modelId }: { models: AppListItemType[]; modelId: st
...
@@ -30,7 +30,7 @@ const ModelList = ({ models, modelId }: { models: AppListItemType[]; modelId: st
}
}
:
{})}
:
{})}
onClick=
{
()
=>
{
onClick=
{
()
=>
{
router
.
replace
(
`/chat?
model
Id=${item._id}`
);
router
.
replace
(
`/chat?
app
Id=${item._id}`
);
}
}
}
}
>
>
<
Avatar
src=
{
item
.
avatar
}
w=
{
'34px'
}
h=
{
'34px'
}
/>
<
Avatar
src=
{
item
.
avatar
}
w=
{
'34px'
}
h=
{
'34px'
}
/>
...
...
client/src/pages/chat/components/PhoneSliderBar.tsx
View file @
aef42cef
...
@@ -95,7 +95,7 @@ const PhoneSliderBar = ({
...
@@ -95,7 +95,7 @@ const PhoneSliderBar = ({
color=
{
'white'
}
color=
{
'white'
}
leftIcon=
{
<
AddIcon
/>
}
leftIcon=
{
<
AddIcon
/>
}
onClick=
{
()
=>
{
onClick=
{
()
=>
{
router
.
replace
(
`/chat?
model
Id=${modelId}`
);
router
.
replace
(
`/chat?
app
Id=${modelId}`
);
onClose
();
onClose
();
}
}
}
}
>
>
...
@@ -128,7 +128,7 @@ const PhoneSliderBar = ({
...
@@ -128,7 +128,7 @@ const PhoneSliderBar = ({
:
{})}
:
{})}
onClick=
{
async
()
=>
{
onClick=
{
async
()
=>
{
if
(
item
.
_id
===
modelId
)
return
;
if
(
item
.
_id
===
modelId
)
return
;
router
.
replace
(
`/chat?
model
Id=${item._id}`
);
router
.
replace
(
`/chat?
app
Id=${item._id}`
);
onClose
();
onClose
();
}
}
}
}
>
>
...
@@ -159,7 +159,7 @@ const PhoneSliderBar = ({
...
@@ -159,7 +159,7 @@ const PhoneSliderBar = ({
:
{})}
:
{})}
onClick=
{
()
=>
{
onClick=
{
()
=>
{
if
(
item
.
_id
===
chatId
)
return
;
if
(
item
.
_id
===
chatId
)
return
;
router
.
replace
(
`/chat?
model
Id=${item.modelId}&chatId=${item._id}`
);
router
.
replace
(
`/chat?
app
Id=${item.modelId}&chatId=${item._id}`
);
onClose
();
onClose
();
}
}
}
}
>
>
...
@@ -177,7 +177,7 @@ const PhoneSliderBar = ({
...
@@ -177,7 +177,7 @@ const PhoneSliderBar = ({
await
delChatHistoryById
(
item
.
_id
);
await
delChatHistoryById
(
item
.
_id
);
loadHistory
({
pageNum
:
1
,
init
:
true
});
loadHistory
({
pageNum
:
1
,
init
:
true
});
if
(
item
.
_id
===
chatId
)
{
if
(
item
.
_id
===
chatId
)
{
router
.
replace
(
`/chat?
model
Id=${modelId}`
);
router
.
replace
(
`/chat?
app
Id=${modelId}`
);
}
}
}
}
}
}
/>
/>
...
...
client/src/pages/chat/index.tsx
View file @
aef42cef
...
@@ -65,7 +65,7 @@ const textareaMinH = '22px';
...
@@ -65,7 +65,7 @@ const textareaMinH = '22px';
const
Chat
=
()
=>
{
const
Chat
=
()
=>
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
{
modelId
=
''
,
chatId
=
''
}
=
router
.
query
as
{
model
Id
:
string
;
chatId
:
string
};
const
{
appId
=
''
,
chatId
=
''
}
=
router
.
query
as
{
app
Id
:
string
;
chatId
:
string
};
const
theme
=
useTheme
();
const
theme
=
useTheme
();
const
ChatBox
=
useRef
<
HTMLDivElement
>
(
null
);
const
ChatBox
=
useRef
<
HTMLDivElement
>
(
null
);
...
@@ -179,7 +179,7 @@ const Chat = () => {
...
@@ -179,7 +179,7 @@ const Chat = () => {
data
:
{
data
:
{
messages
,
messages
,
chatId
,
chatId
,
appId
:
modelId
,
appId
,
model
:
''
model
:
''
},
},
onMessage
:
(
text
:
string
)
=>
{
onMessage
:
(
text
:
string
)
=>
{
...
@@ -206,7 +206,7 @@ const Chat = () => {
...
@@ -206,7 +206,7 @@ const Chat = () => {
// save chat
// save chat
if
(
newChatId
)
{
if
(
newChatId
)
{
setForbidLoadChatData
(
true
);
setForbidLoadChatData
(
true
);
router
.
replace
(
`/chat?
modelId=
${
model
Id
}
&chatId=
${
newChatId
}
`
);
router
.
replace
(
`/chat?
appId=
${
app
Id
}
&chatId=
${
newChatId
}
`
);
}
}
abortSignal
.
signal
.
aborted
&&
(
await
delay
(
500
));
abortSignal
.
signal
.
aborted
&&
(
await
delay
(
500
));
...
@@ -243,7 +243,7 @@ const Chat = () => {
...
@@ -243,7 +243,7 @@ const Chat = () => {
},
},
[
[
chatId
,
chatId
,
model
Id
,
app
Id
,
setChatData
,
setChatData
,
generatingMessage
,
generatingMessage
,
setForbidLoadChatData
,
setForbidLoadChatData
,
...
@@ -474,17 +474,17 @@ const Chat = () => {
...
@@ -474,17 +474,17 @@ const Chat = () => {
// 获取对话信息
// 获取对话信息
const loadChatInfo = useCallback(
const loadChatInfo = useCallback(
async ({
async ({
model
Id,
app
Id,
chatId,
chatId,
loading = false
loading = false
}: {
}: {
model
Id: string;
app
Id: string;
chatId: string;
chatId: string;
loading?: boolean;
loading?: boolean;
}) => {
}) => {
try {
try {
loading && setIsLoading(true);
loading && setIsLoading(true);
const res = await getInitChatSiteInfo(
model
Id, chatId);
const res = await getInitChatSiteInfo(
app
Id, chatId);
setChatData({
setChatData({
...res,
...res,
...
@@ -502,9 +502,9 @@ const Chat = () => {
...
@@ -502,9 +502,9 @@ const Chat = () => {
}
}
// 空 modelId 请求, 重定向到新的 model 聊天
// 空 modelId 请求, 重定向到新的 model 聊天
if (res.modelId !==
model
Id) {
if (res.modelId !==
app
Id) {
setForbidLoadChatData(true);
setForbidLoadChatData(true);
router.replace(`/chat?
model
Id=${res.modelId}`);
router.replace(`/chat?
app
Id=${res.modelId}`);
}
}
} catch (e: any) {
} catch (e: any) {
// reset all chat tore
// reset all chat tore
...
@@ -529,15 +529,15 @@ const Chat = () => {
...
@@ -529,15 +529,15 @@ const Chat = () => {
]
]
);
);
// 初始化聊天框
// 初始化聊天框
useQuery(['init',
model
Id, chatId], () => {
useQuery(['init',
app
Id, chatId], () => {
// pc: redirect to latest model chat
// pc: redirect to latest model chat
if (!
model
Id && lastChatModelId) {
if (!
app
Id && lastChatModelId) {
router.replace(`/chat?
model
Id=${lastChatModelId}&chatId=${lastChatId}`);
router.replace(`/chat?
app
Id=${lastChatModelId}&chatId=${lastChatId}`);
return null;
return null;
}
}
// store id
// store id
modelId && setLastChatModelId(model
Id);
appId && setLastChatModelId(app
Id);
setLastChatId(chatId);
setLastChatId(chatId);
if (forbidLoadChatData) {
if (forbidLoadChatData) {
...
@@ -546,7 +546,7 @@ const Chat = () => {
...
@@ -546,7 +546,7 @@ const Chat = () => {
}
}
return loadChatInfo({
return loadChatInfo({
model
Id,
app
Id,
chatId,
chatId,
loading: true
loading: true
});
});
...
@@ -559,7 +559,7 @@ const Chat = () => {
...
@@ -559,7 +559,7 @@ const Chat = () => {
isLeavePage.current = true;
isLeavePage.current = true;
controller.current?.abort();
controller.current?.abort();
};
};
}, [
model
Id, chatId]);
}, [
app
Id, chatId]);
// context menu component
// context menu component
const RenderContextMenu = useCallback(
const RenderContextMenu = useCallback(
...
@@ -611,14 +611,14 @@ const Chat = () => {
...
@@ -611,14 +611,14 @@ const Chat = () => {
backgroundColor={useColorModeValue('#fdfdfd', '')}
backgroundColor={useColorModeValue('#fdfdfd', '')}
>
>
{/* pc always show history. */}
{/* pc always show history. */}
{(isPc || !
model
Id) && (
{(isPc || !
app
Id) && (
<SideBar>
<SideBar>
<History onclickDelHistory={onclickDelHistory} onclickExportChat={onclickExportChat} />
<History onclickDelHistory={onclickDelHistory} onclickExportChat={onclickExportChat} />
</SideBar>
</SideBar>
)}
)}
{/* 聊天内容 */}
{/* 聊天内容 */}
{
model
Id && (
{
app
Id && (
<Flex
<Flex
position={'relative'}
position={'relative'}
h={[0, '100%']}
h={[0, '100%']}
...
@@ -667,15 +667,13 @@ const Chat = () => {
...
@@ -667,15 +667,13 @@ const Chat = () => {
/>
/>
</MenuButton>
</MenuButton>
<MenuList minW={`90px !important`}>
<MenuList minW={`90px !important`}>
<MenuItem onClick={() => router.replace(`/chat?modelId=${modelId}`)}>
<MenuItem onClick={() => router.replace(`/chat?appId=${appId}`)}>新对话</MenuItem>
新对话
</MenuItem>
<MenuItem
<MenuItem
onClick={async () => {
onClick={async () => {
try {
try {
setIsLoading(true);
setIsLoading(true);
await onclickDelHistory(chatData.chatId);
await onclickDelHistory(chatData.chatId);
router.replace(`/chat?
modelId=${model
Id}`);
router.replace(`/chat?
appId=${app
Id}`);
} catch (err) {
} catch (err) {
console.log(err);
console.log(err);
}
}
...
@@ -901,7 +899,7 @@ const Chat = () => {
...
@@ -901,7 +899,7 @@ const Chat = () => {
<Drawer isOpen={isOpenSlider} placement="
left
"
size
=
{
'xs'
}
onClose
=
{
onCloseSlider
}
>
<Drawer isOpen={isOpenSlider} placement="
left
"
size
=
{
'xs'
}
onClose
=
{
onCloseSlider
}
>
<
DrawerOverlay
backgroundColor=
{
'rgba(255,255,255,0.5)'
}
/>
<
DrawerOverlay
backgroundColor=
{
'rgba(255,255,255,0.5)'
}
/>
<
DrawerContent
maxW=
{
'70%'
}
>
<
DrawerContent
maxW=
{
'70%'
}
>
<
PhoneSliderBar
chatId=
{
chatId
}
modelId=
{
model
Id
}
onClose=
{
onCloseSlider
}
/>
<
PhoneSliderBar
chatId=
{
chatId
}
modelId=
{
app
Id
}
onClose=
{
onCloseSlider
}
/>
</
DrawerContent
>
</
DrawerContent
>
<
/
Drawer
>
<
/
Drawer
>
)}
)}
...
...
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