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
b7934ecc
authored
Aug 02, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: extract modules
parent
8862e353
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
67 additions
and
16 deletions
+67
-16
client/src/components/ChatBox/index.tsx
+6
-3
client/src/constants/chat.ts
+6
-0
client/src/constants/flow/ModuleTemplate.ts
+4
-3
client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeExtract.tsx
+6
-1
client/src/pages/app/detail/components/AdEdit/index.tsx
+29
-5
client/src/service/moduleDispatch/agent/extract.ts
+2
-2
client/src/types/flow.d.ts
+9
-0
client/src/utils/adapt.ts
+5
-2
No files found.
client/src/components/ChatBox/index.tsx
View file @
b7934ecc
...
@@ -38,7 +38,7 @@ import { fileDownload } from '@/utils/file';
...
@@ -38,7 +38,7 @@ import { fileDownload } from '@/utils/file';
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
htmlTemplate
}
from
'@/constants/common'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useGlobalStore
}
from
'@/store/global'
;
import
{
useGlobalStore
}
from
'@/store/global'
;
import
{
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
TaskResponseKeyEnum
,
getDefaultChatVariables
}
from
'@/constants/chat'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
import
Avatar
from
'@/components/Avatar'
;
import
Avatar
from
'@/components/Avatar'
;
...
@@ -251,7 +251,7 @@ const ChatBox = (
...
@@ -251,7 +251,7 @@ const ChatBox = (
* user confirm send prompt
* user confirm send prompt
*/
*/
const
sendPrompt
=
useCallback
(
const
sendPrompt
=
useCallback
(
async
(
data
:
Record
<
string
,
any
>
=
{},
inputVal
=
''
)
=>
{
async
(
variables
:
Record
<
string
,
any
>
=
{},
inputVal
=
''
)
=>
{
if
(
isChatting
)
{
if
(
isChatting
)
{
toast
({
toast
({
title
:
'正在聊天中...请等待结束'
,
title
:
'正在聊天中...请等待结束'
,
...
@@ -306,7 +306,10 @@ const ChatBox = (
...
@@ -306,7 +306,10 @@ const ChatBox = (
messages
,
messages
,
controller
:
abortSignal
,
controller
:
abortSignal
,
generatingMessage
,
generatingMessage
,
variables
:
data
variables
:
{
...
getDefaultChatVariables
(),
...
variables
}
});
});
// set finish status
// set finish status
...
...
client/src/constants/chat.ts
View file @
b7934ecc
import
dayjs
from
'dayjs'
;
export
enum
sseResponseEventEnum
{
export
enum
sseResponseEventEnum
{
error
=
'error'
,
error
=
'error'
,
answer
=
'answer'
,
answer
=
'answer'
,
...
@@ -65,3 +67,7 @@ export enum OutLinkTypeEnum {
...
@@ -65,3 +67,7 @@ export enum OutLinkTypeEnum {
export
const
HUMAN_ICON
=
`https://fastgpt.run/icon/human.png`
;
export
const
HUMAN_ICON
=
`https://fastgpt.run/icon/human.png`
;
export
const
LOGO_ICON
=
`https://fastgpt.run/icon/logo.png`
;
export
const
LOGO_ICON
=
`https://fastgpt.run/icon/logo.png`
;
export
const
getDefaultChatVariables
=
()
=>
({
cTime
:
dayjs
().
format
(
'YYYY/MM/DD HH:mm:ss'
)
});
client/src/constants/flow/ModuleTemplate.ts
View file @
b7934ecc
...
@@ -30,7 +30,7 @@ export const VariableModule: FlowModuleTemplateType = {
...
@@ -30,7 +30,7 @@ export const VariableModule: FlowModuleTemplateType = {
name
:
'全局变量'
,
name
:
'全局变量'
,
intro
:
'可以在对话开始前,要求用户填写一些内容作为本轮对话的变量。该模块位于开场引导之后。'
,
intro
:
'可以在对话开始前,要求用户填写一些内容作为本轮对话的变量。该模块位于开场引导之后。'
,
description
:
description
:
'全局变量可以通过 {{变量key}} 的形式注入到其他模块
的文本中。目前支持:提示词、限定词。
'
,
'全局变量可以通过 {{变量key}} 的形式注入到其他模块
string 类型的输入中,例如:提示词、限定词等
'
,
flowType
:
FlowModuleTypeEnum
.
variable
,
flowType
:
FlowModuleTypeEnum
.
variable
,
inputs
:
[
inputs
:
[
{
{
...
@@ -389,6 +389,7 @@ export const ContextExtractModule: FlowModuleTemplateType = {
...
@@ -389,6 +389,7 @@ export const ContextExtractModule: FlowModuleTemplateType = {
valueType: FlowValueTypeEnum.string,
valueType: FlowValueTypeEnum.string,
label: '提取要求描述',
label: '提取要求描述',
description: '写一段提取要求,告诉 AI 需要提取哪些内容',
description: '写一段提取要求,告诉 AI 需要提取哪些内容',
required: true,
placeholder:
placeholder:
'例如: \n1. 你是一个实验室预约助手。根据用户问题,提取出姓名、实验室号和预约时间',
'例如: \n1. 你是一个实验室预约助手。根据用户问题,提取出姓名、实验室号和预约时间',
value: ''
value: ''
...
@@ -433,8 +434,8 @@ export const ContextExtractModule: FlowModuleTemplateType = {
...
@@ -433,8 +434,8 @@ export const ContextExtractModule: FlowModuleTemplateType = {
{
{
key: ContextExtractEnum.fields,
key: ContextExtractEnum.fields,
label: '完整提取结果',
label: '完整提取结果',
description: '一个 JSON
对象,例如
{"name:":"YY","Time":"2023/7/2 18:00"}',
description: '一个 JSON
字符串,例如:
{"name:":"YY","Time":"2023/7/2 18:00"}',
valueType: FlowValueTypeEnum.
any
,
valueType: FlowValueTypeEnum.
string
,
type: FlowOutputItemTypeEnum.source,
type: FlowOutputItemTypeEnum.source,
targets: []
targets: []
},
},
...
...
client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeExtract.tsx
View file @
b7934ecc
...
@@ -16,7 +16,7 @@ import { ContextExtractEnum } from '@/constants/flow/flowField';
...
@@ -16,7 +16,7 @@ import { ContextExtractEnum } from '@/constants/flow/flowField';
import
{
FlowOutputItemTypeEnum
,
FlowValueTypeEnum
}
from
'@/constants/flow'
;
import
{
FlowOutputItemTypeEnum
,
FlowValueTypeEnum
}
from
'@/constants/flow'
;
const
NodeExtract
=
({
const
NodeExtract
=
({
data
:
{
inputs
,
outputs
,
moduleId
,
onChangeNode
,
...
props
}
data
:
{
inputs
,
outputs
,
moduleId
,
onChangeNode
,
onDelEdge
,
...
props
}
}:
NodeProps
<
FlowModuleItemType
>
)
=>
{
}:
NodeProps
<
FlowModuleItemType
>
)
=>
{
const
{
t
}
=
useTranslation
();
const
{
t
}
=
useTranslation
();
const
[
editExtractFiled
,
setEditExtractField
]
=
useState
<
ContextExtractAgentItemType
>
();
const
[
editExtractFiled
,
setEditExtractField
]
=
useState
<
ContextExtractAgentItemType
>
();
...
@@ -105,6 +105,7 @@ const NodeExtract = ({
...
@@ -105,6 +105,7 @@ const NodeExtract = ({
key
:
''
,
key
:
''
,
value
:
newOutputVal
value
:
newOutputVal
});
});
onDelEdge
({
moduleId
,
sourceHandle
:
item
.
key
});
}
}
}
}
/>
/>
</
Td
>
</
Td
>
...
@@ -168,6 +169,10 @@ const NodeExtract = ({
...
@@ -168,6 +169,10 @@ const NodeExtract = ({
value
:
newOutputs
value
:
newOutputs
});
});
if
(
editExtractFiled
.
key
&&
editExtractFiled
.
key
!==
data
.
key
)
{
onDelEdge
({
moduleId
,
sourceHandle
:
editExtractFiled
.
key
});
}
setEditExtractField
(
undefined
);
setEditExtractField
(
undefined
);
}
}
}
}
/>
/>
...
...
client/src/pages/app/detail/components/AdEdit/index.tsx
View file @
b7934ecc
...
@@ -162,7 +162,6 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -162,7 +162,6 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
});
});
return
modules
;
return
modules
;
},
[
edges
,
nodes
]);
},
[
edges
,
nodes
]);
const
onChangeNode
=
useCallback
(
const
onChangeNode
=
useCallback
(
({
moduleId
,
key
,
type
=
'inputs'
,
value
,
valueKey
=
'value'
}:
FlowModuleItemChangeProps
)
=>
{
({
moduleId
,
key
,
type
=
'inputs'
,
value
,
valueKey
=
'value'
}:
FlowModuleItemChangeProps
)
=>
{
setNodes
((
nodes
)
=>
setNodes
((
nodes
)
=>
...
@@ -205,6 +204,29 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -205,6 +204,29 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
},
},
[
setEdges
,
setNodes
]
[
setEdges
,
setNodes
]
);
);
const
onDelEdge
=
useCallback
(
({
moduleId
,
sourceHandle
,
targetHandle
}:
{
moduleId
:
string
;
sourceHandle
?:
string
;
targetHandle
?:
string
;
})
=>
{
if
(
!
sourceHandle
&&
!
targetHandle
)
return
;
setEdges
((
state
)
=>
state
.
filter
((
edge
)
=>
{
if
(
edge
.
source
===
moduleId
&&
edge
.
sourceHandle
===
sourceHandle
)
return
false
;
if
(
edge
.
target
===
moduleId
&&
edge
.
targetHandle
===
targetHandle
)
return
false
;
return
true
;
})
);
},
[
setEdges
]
);
const
onAddNode
=
useCallback
(
const
onAddNode
=
useCallback
(
({
template
,
position
}:
{
template
:
FlowModuleTemplateType
;
position
:
XYPosition
})
=>
{
({
template
,
position
}:
{
template
:
FlowModuleTemplateType
;
position
:
XYPosition
})
=>
{
if
(
!
reactFlowWrapper
.
current
)
return
;
if
(
!
reactFlowWrapper
.
current
)
return
;
...
@@ -221,12 +243,13 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -221,12 +243,13 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
position
:
{
x
:
mouseX
,
y
:
mouseY
}
position
:
{
x
:
mouseX
,
y
:
mouseY
}
},
},
onChangeNode
,
onChangeNode
,
onDelNode
onDelNode
,
onDelEdge
})
})
)
)
);
);
},
},
[
onChangeNode
,
onDelNode
,
setNodes
,
x
,
y
,
zoom
]
[
on
DelEdge
,
on
ChangeNode
,
onDelNode
,
setNodes
,
x
,
y
,
zoom
]
);
);
const
onDelConnect
=
useCallback
(
const
onDelConnect
=
useCallback
(
(
id
:
string
)
=>
{
(
id
:
string
)
=>
{
...
@@ -309,14 +332,15 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -309,14 +332,15 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
appModule2FlowNode
({
appModule2FlowNode
({
item
,
item
,
onChangeNode
,
onChangeNode
,
onDelNode
onDelNode
,
onDelEdge
})
})
)
)
);
);
onFixView
();
onFixView
();
},
},
[
onDelConnect
,
setEdges
,
setNodes
,
onFixView
,
onChangeNode
,
onDelNode
]
[
onDelConnect
,
setEdges
,
setNodes
,
onFixView
,
onChangeNode
,
onDelNode
,
onDelEdge
]
);
);
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
client/src/service/moduleDispatch/agent/extract.ts
View file @
b7934ecc
...
@@ -19,7 +19,7 @@ export type Props = {
...
@@ -19,7 +19,7 @@ export type Props = {
export
type
Response
=
{
export
type
Response
=
{
[
ContextExtractEnum
.
success
]?:
boolean
;
[
ContextExtractEnum
.
success
]?:
boolean
;
[
ContextExtractEnum
.
failed
]?:
boolean
;
[
ContextExtractEnum
.
failed
]?:
boolean
;
[
ContextExtractEnum
.
fields
]:
Record
<
string
,
any
>
;
[
ContextExtractEnum
.
fields
]:
string
;
[
TaskResponseKeyEnum
.
responseData
]:
ChatHistoryItemResType
;
[
TaskResponseKeyEnum
.
responseData
]:
ChatHistoryItemResType
;
};
};
...
@@ -115,7 +115,7 @@ export async function dispatchContentExtract({
...
@@ -115,7 +115,7 @@ export async function dispatchContentExtract({
return
{
return
{
[
ContextExtractEnum
.
success
]:
success
?
true
:
undefined
,
[
ContextExtractEnum
.
success
]:
success
?
true
:
undefined
,
[
ContextExtractEnum
.
failed
]:
success
?
undefined
:
true
,
[
ContextExtractEnum
.
failed
]:
success
?
undefined
:
true
,
[
ContextExtractEnum
.
fields
]:
arg
,
[
ContextExtractEnum
.
fields
]:
JSON
.
stringify
(
arg
)
,
...
arg
,
...
arg
,
[
TaskResponseKeyEnum
.
responseData
]:
{
[
TaskResponseKeyEnum
.
responseData
]:
{
moduleName
:
ChatModuleEnum
.
Extract
,
moduleName
:
ChatModuleEnum
.
Extract
,
...
...
client/src/types/flow.d.ts
View file @
b7934ecc
...
@@ -59,4 +59,13 @@ export type FlowModuleItemType = FlowModuleTemplateType & {
...
@@ -59,4 +59,13 @@ export type FlowModuleItemType = FlowModuleTemplateType & {
moduleId
:
string
;
moduleId
:
string
;
onChangeNode
:
(
e
:
FlowModuleItemChangeProps
)
=>
void
;
onChangeNode
:
(
e
:
FlowModuleItemChangeProps
)
=>
void
;
onDelNode
:
(
id
:
string
)
=>
void
;
onDelNode
:
(
id
:
string
)
=>
void
;
onDelEdge
:
({
moduleId
,
sourceHandle
,
targetHandle
}:
{
moduleId
:
string
;
sourceHandle
?:
string
|
undefined
;
targetHandle
?:
string
|
undefined
;
})
=>
void
;
};
};
client/src/utils/adapt.ts
View file @
b7934ecc
...
@@ -63,11 +63,13 @@ export const textAdaptGptResponse = ({
...
@@ -63,11 +63,13 @@ export const textAdaptGptResponse = ({
export
const
appModule2FlowNode
=
({
export
const
appModule2FlowNode
=
({
item
,
item
,
onChangeNode
,
onChangeNode
,
onDelNode
onDelNode
,
onDelEdge
}:
{
}:
{
item
:
AppModuleItemType
;
item
:
AppModuleItemType
;
onChangeNode
:
FlowModuleItemType
[
'onChangeNode'
];
onChangeNode
:
FlowModuleItemType
[
'onChangeNode'
];
onDelNode
:
FlowModuleItemType
[
'onDelNode'
];
onDelNode
:
FlowModuleItemType
[
'onDelNode'
];
onDelEdge
:
FlowModuleItemType
[
'onDelEdge'
];
}):
Node
<
FlowModuleItemType
>
=>
{
}):
Node
<
FlowModuleItemType
>
=>
{
// init some static data
// init some static data
const
template
=
const
template
=
...
@@ -96,7 +98,8 @@ export const appModule2FlowNode = ({
...
@@ -96,7 +98,8 @@ export const appModule2FlowNode = ({
};
};
}),
}),
onChangeNode
,
onChangeNode
,
onDelNode
onDelNode
,
onDelEdge
};
};
return
{
return
{
...
...
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