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
ffd4e194
authored
Aug 03, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: http request
parent
952da2a0
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
138 additions
and
139 deletions
+138
-139
client/src/constants/flow/flowField.ts
+2
-3
client/src/pages/api/openapi/v1/chat/completions.ts
+5
-3
client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeExtract.tsx
+1
-1
client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeHttp.tsx
+0
-1
client/src/pages/app/detail/components/AdEdit/components/modules/SetInputFieldModal.tsx
+1
-2
client/src/pages/app/detail/components/AdEdit/components/render/RenderInput.tsx
+8
-11
client/src/pages/app/detail/components/AdEdit/components/render/RenderOutput.tsx
+26
-54
client/src/pages/app/detail/components/AdEdit/components/render/TargetHandle.tsx
+2
-2
client/src/pages/app/detail/components/AdEdit/index.tsx
+39
-30
client/src/service/moduleDispatch/agent/extract.ts
+1
-1
client/src/service/moduleDispatch/index.ts
+2
-0
client/src/service/moduleDispatch/tools/http.ts
+51
-0
client/src/service/moduleDispatch/tools/httpRequest.ts
+0
-31
No files found.
client/src/constants/flow/flowField.ts
View file @
ffd4e194
...
@@ -9,7 +9,6 @@ export enum ContextExtractEnum {
...
@@ -9,7 +9,6 @@ export enum ContextExtractEnum {
export
enum
HttpPropsEnum
{
export
enum
HttpPropsEnum
{
url
=
'url'
,
url
=
'url'
,
finish
=
'finish'
,
failed
=
'failed'
,
body
=
'body'
,
finish
=
'finish'
response
=
'response'
}
}
client/src/pages/api/openapi/v1/chat/completions.ts
View file @
ffd4e194
...
@@ -10,7 +10,9 @@ import {
...
@@ -10,7 +10,9 @@ import {
dispatchChatCompletion
,
dispatchChatCompletion
,
dispatchKBSearch
,
dispatchKBSearch
,
dispatchAnswer
,
dispatchAnswer
,
dispatchClassifyQuestion
dispatchClassifyQuestion
,
dispatchContentExtract
,
dispatchHttpRequest
}
from
'@/service/moduleDispatch'
;
}
from
'@/service/moduleDispatch'
;
import
type
{
CreateChatCompletionRequest
}
from
'openai'
;
import
type
{
CreateChatCompletionRequest
}
from
'openai'
;
import
{
gptMessage2ChatType
,
textAdaptGptResponse
}
from
'@/utils/adapt'
;
import
{
gptMessage2ChatType
,
textAdaptGptResponse
}
from
'@/utils/adapt'
;
...
@@ -25,7 +27,6 @@ import { pushTaskBill } from '@/service/events/pushBill';
...
@@ -25,7 +27,6 @@ import { pushTaskBill } from '@/service/events/pushBill';
import
{
BillSourceEnum
}
from
'@/constants/user'
;
import
{
BillSourceEnum
}
from
'@/constants/user'
;
import
{
ChatHistoryItemResType
}
from
'@/types/chat'
;
import
{
ChatHistoryItemResType
}
from
'@/types/chat'
;
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
UserModelSchema
}
from
'@/types/mongoSchema'
;
import
{
dispatchContentExtract
}
from
'@/service/moduleDispatch/agent/extract'
;
export
type
MessageItemType
=
ChatCompletionRequestMessage
&
{
_id
?:
string
};
export
type
MessageItemType
=
ChatCompletionRequestMessage
&
{
_id
?:
string
};
type
FastGptWebChatProps
=
{
type
FastGptWebChatProps
=
{
...
@@ -339,7 +340,8 @@ export async function dispatchModules({
...
@@ -339,7 +340,8 @@ export async function dispatchModules({
[
FlowModuleTypeEnum
.
chatNode
]:
dispatchChatCompletion
,
[
FlowModuleTypeEnum
.
chatNode
]:
dispatchChatCompletion
,
[
FlowModuleTypeEnum
.
kbSearchNode
]:
dispatchKBSearch
,
[
FlowModuleTypeEnum
.
kbSearchNode
]:
dispatchKBSearch
,
[
FlowModuleTypeEnum
.
classifyQuestion
]:
dispatchClassifyQuestion
,
[
FlowModuleTypeEnum
.
classifyQuestion
]:
dispatchClassifyQuestion
,
[
FlowModuleTypeEnum
.
contentExtract
]:
dispatchContentExtract
[
FlowModuleTypeEnum
.
contentExtract
]:
dispatchContentExtract
,
[
FlowModuleTypeEnum
.
httpRequest
]:
dispatchHttpRequest
};
};
if
(
callbackMap
[
module
.
flowType
])
{
if
(
callbackMap
[
module
.
flowType
])
{
return
callbackMap
[
module
.
flowType
](
props
);
return
callbackMap
[
module
.
flowType
](
props
);
...
...
client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeExtract.tsx
View file @
ffd4e194
...
@@ -66,7 +66,7 @@ const NodeExtract = ({
...
@@ -66,7 +66,7 @@ const NodeExtract = ({
{
extractKeys
.
map
((
item
,
index
)
=>
(
{
extractKeys
.
map
((
item
,
index
)
=>
(
<
Tr
key=
{
index
}
position=
{
'relative'
}
>
<
Tr
key=
{
index
}
position=
{
'relative'
}
>
<
Td
>
{
item
.
key
}
</
Td
>
<
Td
>
{
item
.
key
}
</
Td
>
<
Td
whiteSpace=
{
'pre-
line
'
}
wordBreak=
{
'break-all'
}
>
<
Td
whiteSpace=
{
'pre-
wrap
'
}
wordBreak=
{
'break-all'
}
>
{
item
.
desc
}
{
item
.
desc
}
</
Td
>
</
Td
>
<
Td
>
{
item
.
required
?
'✔'
:
''
}
</
Td
>
<
Td
>
{
item
.
required
?
'✔'
:
''
}
</
Td
>
...
...
client/src/pages/app/detail/components/AdEdit/components/Nodes/NodeHttp.tsx
View file @
ffd4e194
...
@@ -32,7 +32,6 @@ const NodeHttp = ({
...
@@ -32,7 +32,6 @@ const NodeHttp = ({
key
,
key
,
value
:
{
value
:
{
key
,
key
,
value
:
''
,
valueType
:
FlowValueTypeEnum
.
string
,
valueType
:
FlowValueTypeEnum
.
string
,
type
:
FlowInputItemTypeEnum
.
target
,
type
:
FlowInputItemTypeEnum
.
target
,
label
:
'New Param'
,
label
:
'New Param'
,
...
...
client/src/pages/app/detail/components/AdEdit/components/modules/SetInputFieldModal.tsx
View file @
ffd4e194
...
@@ -10,14 +10,13 @@ import {
...
@@ -10,14 +10,13 @@ import {
Input
,
Input
,
FormControl
FormControl
}
from
'@chakra-ui/react'
;
}
from
'@chakra-ui/react'
;
import
type
{
ContextExtractAgentItemType
,
HttpFieldItemType
}
from
'@/types/app'
;
import
{
useForm
}
from
'react-hook-form'
;
import
{
useForm
}
from
'react-hook-form'
;
import
{
customAlphabet
}
from
'nanoid'
;
import
{
customAlphabet
}
from
'nanoid'
;
const
nanoid
=
customAlphabet
(
'abcdefghijklmnopqrstuvwxyz1234567890'
,
6
);
const
nanoid
=
customAlphabet
(
'abcdefghijklmnopqrstuvwxyz1234567890'
,
6
);
import
MyModal
from
'@/components/MyModal'
;
import
MyModal
from
'@/components/MyModal'
;
import
Avatar
from
'@/components/Avatar'
;
import
Avatar
from
'@/components/Avatar'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
{
FlowInputItemTypeEnum
,
FlowValueTypeEnum
,
FlowValueTypeStyle
}
from
'@/constants/flow'
;
import
{
FlowInputItemTypeEnum
,
FlowValueTypeEnum
}
from
'@/constants/flow'
;
import
{
useTranslation
}
from
'react-i18next'
;
import
{
useTranslation
}
from
'react-i18next'
;
import
MySelect
from
'@/components/Select'
;
import
MySelect
from
'@/components/Select'
;
import
{
FlowInputItemType
}
from
'@/types/flow'
;
import
{
FlowInputItemType
}
from
'@/types/flow'
;
...
...
client/src/pages/app/detail/components/AdEdit/components/render/RenderInput.tsx
View file @
ffd4e194
...
@@ -35,7 +35,7 @@ export const Label = ({
...
@@ -35,7 +35,7 @@ export const Label = ({
const
[
editField
,
setEditField
]
=
useState
<
FlowInputItemType
>
();
const
[
editField
,
setEditField
]
=
useState
<
FlowInputItemType
>
();
return
(
return
(
<
Flex
alignItems=
{
'center'
}
position=
{
'relative'
}
>
<
Flex
className=
"nodrag"
cursor=
{
'default'
}
alignItems=
{
'center'
}
position=
{
'relative'
}
>
<
Box
position=
{
'relative'
}
>
<
Box
position=
{
'relative'
}
>
{
label
}
{
label
}
{
description
&&
(
{
description
&&
(
...
@@ -83,9 +83,6 @@ export const Label = ({
...
@@ -83,9 +83,6 @@ export const Label = ({
ml=
{
2
}
ml=
{
2
}
_hover=
{
{
color
:
'red.500'
}
}
_hover=
{
{
color
:
'red.500'
}
}
onClick=
{
()
=>
{
onClick=
{
()
=>
{
{
console
.
log
(
moduleId
,
inputKey
,
valueType
);
}
onChangeNode
({
onChangeNode
({
moduleId
,
moduleId
,
type
:
'delInput'
,
type
:
'delInput'
,
...
@@ -113,15 +110,15 @@ export const Label = ({
...
@@ -113,15 +110,15 @@ export const Label = ({
// diff key. del and add
// diff key. del and add
onChangeNode
({
onChangeNode
({
moduleId
,
moduleId
,
type
:
'
del
Input'
,
type
:
'
add
Input'
,
key
:
editField
.
key
,
key
:
data
.
key
,
value
:
''
value
:
data
});
});
onChangeNode
({
onChangeNode
({
moduleId
,
moduleId
,
type
:
'
add
Input'
,
type
:
'
del
Input'
,
key
:
editField
.
key
,
key
:
editField
.
key
,
value
:
data
value
:
''
});
});
}
}
setEditField
(
undefined
);
setEditField
(
undefined
);
...
@@ -132,7 +129,7 @@ export const Label = ({
...
@@ -132,7 +129,7 @@ export const Label = ({
);
);
};
};
const
Render
Body
=
({
const
Render
Input
=
({
flowInputList
,
flowInputList
,
moduleId
,
moduleId
,
CustomComponent
=
{},
CustomComponent
=
{},
...
@@ -270,4 +267,4 @@ const RenderBody = ({
...
@@ -270,4 +267,4 @@ const RenderBody = ({
);
);
};
};
export
default
React
.
memo
(
Render
Body
);
export
default
React
.
memo
(
Render
Input
);
client/src/pages/app/detail/components/AdEdit/components/render/RenderOutput.tsx
View file @
ffd4e194
import
React
,
{
use
Callback
,
use
State
}
from
'react'
;
import
React
,
{
useState
}
from
'react'
;
import
type
{
FlowModuleItemType
,
FlowOutputItemType
}
from
'@/types/flow'
;
import
type
{
FlowModuleItemType
,
FlowOutputItemType
}
from
'@/types/flow'
;
import
{
Box
,
Flex
}
from
'@chakra-ui/react'
;
import
{
Box
,
Flex
}
from
'@chakra-ui/react'
;
import
{
FlowOutputItemTypeEnum
}
from
'@/constants/flow'
;
import
{
FlowOutputItemTypeEnum
}
from
'@/constants/flow'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
import
{
QuestionOutlineIcon
}
from
'@chakra-ui/icons'
;
import
{
Handle
,
Position
}
from
'reactflow'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
MyTooltip
from
'@/components/MyTooltip'
;
import
SourceHandle
from
'./SourceHandle'
;
import
SourceHandle
from
'./SourceHandle'
;
import
MyIcon
from
'@/components/Icon'
;
import
MyIcon
from
'@/components/Icon'
;
...
@@ -13,24 +12,26 @@ const SetOutputFieldModal = dynamic(() => import('../modules/SetOutputFieldModal
...
@@ -13,24 +12,26 @@ const SetOutputFieldModal = dynamic(() => import('../modules/SetOutputFieldModal
const
Label
=
({
const
Label
=
({
moduleId
,
moduleId
,
outputKey
,
outputKey
,
delOutputByKey
,
outputs
,
updateOutput
,
onChangeNode
,
onChangeNode
,
addUpdateOutput
,
...
item
...
item
}:
FlowOutputItemType
&
{
}:
FlowOutputItemType
&
{
outputKey
:
string
;
outputKey
:
string
;
moduleId
:
string
;
moduleId
:
string
;
delOutputByKey
:
(
key
:
string
)
=>
void
;
outputs
:
FlowOutputItemType
[];
updateOutput
:
(
key
:
string
,
val
:
FlowOutputItemType
)
=>
void
;
addUpdateOutput
:
(
val
:
FlowOutputItemType
)
=>
void
;
onChangeNode
:
FlowModuleItemType
[
'onChangeNode'
];
onChangeNode
:
FlowModuleItemType
[
'onChangeNode'
];
})
=>
{
})
=>
{
const
{
label
,
description
,
edit
}
=
item
;
const
{
label
,
description
,
edit
}
=
item
;
const
[
editField
,
setEditField
]
=
useState
<
FlowOutputItemType
>
();
const
[
editField
,
setEditField
]
=
useState
<
FlowOutputItemType
>
();
return
(
return
(
<
Flex
as=
{
'label'
}
justifyContent=
{
'right'
}
alignItems=
{
'center'
}
position=
{
'relative'
}
>
<
Flex
className=
"nodrag"
cursor=
{
'default'
}
justifyContent=
{
'right'
}
alignItems=
{
'center'
}
position=
{
'relative'
}
>
{
edit
&&
(
{
edit
&&
(
<>
<>
<
MyIcon
<
MyIcon
...
@@ -53,7 +54,14 @@ const Label = ({
...
@@ -53,7 +54,14 @@ const Label = ({
cursor=
{
'pointer'
}
cursor=
{
'pointer'
}
mr=
{
3
}
mr=
{
3
}
_hover=
{
{
color
:
'red.500'
}
}
_hover=
{
{
color
:
'red.500'
}
}
onClick=
{
()
=>
delOutputByKey
(
outputKey
)
}
onClick=
{
()
=>
{
onChangeNode
({
moduleId
,
type
:
'outputs'
,
key
:
''
,
value
:
outputs
.
filter
((
output
)
=>
output
.
key
!==
outputKey
)
});
}
}
/>
/>
</>
</>
)
}
)
}
...
@@ -69,13 +77,13 @@ const Label = ({
...
@@ -69,13 +77,13 @@ const Label = ({
defaultField=
{
editField
}
defaultField=
{
editField
}
onClose=
{
()
=>
setEditField
(
undefined
)
}
onClose=
{
()
=>
setEditField
(
undefined
)
}
onSubmit=
{
(
data
)
=>
{
onSubmit=
{
(
data
)
=>
{
console
.
log
(
data
);
// same key
onChangeNode
({
if
(
editField
.
key
===
data
.
key
)
{
moduleId
,
updateOutput
(
data
.
key
,
data
);
type
:
'outputs'
,
}
else
{
key
:
''
,
delOutputByKey
(
editField
.
key
);
value
:
outputs
.
map
((
output
)
=>
(
output
.
key
===
outputKey
?
data
:
output
))
addUpdateOutput
(
data
);
}
);
}
setEditField
(
undefined
);
setEditField
(
undefined
);
}
}
}
}
/>
/>
...
@@ -93,40 +101,6 @@ const RenderOutput = ({
...
@@ -93,40 +101,6 @@ const RenderOutput = ({
flowOutputList
:
FlowOutputItemType
[];
flowOutputList
:
FlowOutputItemType
[];
onChangeNode
:
FlowModuleItemType
[
'onChangeNode'
];
onChangeNode
:
FlowModuleItemType
[
'onChangeNode'
];
})
=>
{
})
=>
{
const
delOutputByKey
=
useCallback
(
(
key
:
string
)
=>
{
onChangeNode
({
moduleId
,
type
:
'outputs'
,
key
:
''
,
value
:
flowOutputList
.
filter
((
output
)
=>
output
.
key
!==
key
)
});
},
[
moduleId
,
flowOutputList
,
onChangeNode
]
);
const
updateOutput
=
useCallback
(
(
key
:
string
,
val
:
FlowOutputItemType
)
=>
{
onChangeNode
({
moduleId
,
type
:
'outputs'
,
key
:
''
,
value
:
flowOutputList
.
map
((
output
)
=>
(
output
.
key
===
key
?
val
:
output
))
});
},
[
flowOutputList
,
moduleId
,
onChangeNode
]
);
const
addUpdateOutput
=
useCallback
(
(
val
:
FlowOutputItemType
)
=>
{
onChangeNode
({
moduleId
,
type
:
'outputs'
,
key
:
''
,
value
:
flowOutputList
.
concat
(
val
)
});
},
[
flowOutputList
,
moduleId
,
onChangeNode
]
);
return
(
return
(
<>
<>
{
flowOutputList
.
map
(
{
flowOutputList
.
map
(
...
@@ -137,9 +111,7 @@ const RenderOutput = ({
...
@@ -137,9 +111,7 @@ const RenderOutput = ({
moduleId=
{
moduleId
}
moduleId=
{
moduleId
}
onChangeNode=
{
onChangeNode
}
onChangeNode=
{
onChangeNode
}
outputKey=
{
item
.
key
}
outputKey=
{
item
.
key
}
delOutputByKey=
{
delOutputByKey
}
outputs=
{
flowOutputList
}
addUpdateOutput=
{
addUpdateOutput
}
updateOutput=
{
updateOutput
}
{
...
item
}
{
...
item
}
/>
/>
<
Box
mt=
{
FlowOutputItemTypeEnum
.
answer
?
0
:
2
}
className=
{
'nodrag'
}
>
<
Box
mt=
{
FlowOutputItemTypeEnum
.
answer
?
0
:
2
}
className=
{
'nodrag'
}
>
...
...
client/src/pages/app/detail/components/AdEdit/components/render/TargetHandle.tsx
View file @
ffd4e194
...
@@ -21,6 +21,7 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
...
@@ -21,6 +21,7 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
return
(
return
(
<
Box
<
Box
key=
{
handleKey
}
position=
{
'absolute'
}
position=
{
'absolute'
}
top=
{
'50%'
}
top=
{
'50%'
}
left=
{
'-16px'
}
left=
{
'-16px'
}
...
@@ -36,7 +37,6 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
...
@@ -36,7 +37,6 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
}
}
}
}
type=
"target"
type=
"target"
id=
{
handleKey
}
id=
{
handleKey
}
datatype=
{
valueStyle
}
position=
{
Position
.
Left
}
position=
{
Position
.
Left
}
/>
/>
</
MyTooltip
>
</
MyTooltip
>
...
@@ -44,4 +44,4 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
...
@@ -44,4 +44,4 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
);
);
};
};
export
default
TargetHandle
;
export
default
React
.
memo
(
TargetHandle
)
;
client/src/pages/app/detail/components/AdEdit/index.tsx
View file @
ffd4e194
...
@@ -125,6 +125,36 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -125,6 +125,36 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
},
100
);
},
100
);
},
[]);
},
[]);
const
onDelNode
=
useCallback
(
(
nodeId
:
string
)
=>
{
setNodes
((
state
)
=>
state
.
filter
((
item
)
=>
item
.
id
!==
nodeId
));
setEdges
((
state
)
=>
state
.
filter
((
edge
)
=>
edge
.
source
!==
nodeId
&&
edge
.
target
!==
nodeId
));
},
[
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
flow2AppModules
=
useCallback
(()
=>
{
const
flow2AppModules
=
useCallback
(()
=>
{
const
modules
:
AppModuleItemType
[]
=
nodes
.
map
((
item
)
=>
({
const
modules
:
AppModuleItemType
[]
=
nodes
.
map
((
item
)
=>
({
moduleId
:
item
.
data
.
moduleId
,
moduleId
:
item
.
data
.
moduleId
,
...
@@ -203,6 +233,7 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -203,6 +233,7 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
};
};
}
}
if
(
type
===
'delInput'
)
{
if
(
type
===
'delInput'
)
{
onDelEdge
({
moduleId
,
targetHandle
:
key
});
return
{
return
{
...
node
,
...
node
,
data
:
{
data
:
{
...
@@ -211,7 +242,14 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -211,7 +242,14 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
}
}
};
};
}
}
console
.
log
(
value
);
// del output connect
const
delOutputs
=
node
.
data
.
outputs
.
filter
(
(
item
)
=>
!
value
.
find
((
output
:
FlowOutputTargetItemType
)
=>
output
.
key
===
item
.
key
)
);
delOutputs
.
forEach
((
output
)
=>
{
onDelEdge
({
moduleId
,
sourceHandle
:
output
.
key
});
});
return
{
return
{
...
node
,
...
node
,
...
@@ -225,35 +263,6 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -225,35 +263,6 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
},
},
[
setNodes
]
[
setNodes
]
);
);
const
onDelNode
=
useCallback
(
(
nodeId
:
string
)
=>
{
setNodes
((
state
)
=>
state
.
filter
((
item
)
=>
item
.
id
!==
nodeId
));
setEdges
((
state
)
=>
state
.
filter
((
edge
)
=>
edge
.
source
!==
nodeId
&&
edge
.
target
!==
nodeId
));
},
[
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
})
=>
{
...
...
client/src/service/moduleDispatch/agent/extract.ts
View file @
ffd4e194
...
@@ -66,7 +66,7 @@ export async function dispatchContentExtract({
...
@@ -66,7 +66,7 @@ export async function dispatchContentExtract({
// function body
// function body
const
agentFunction
=
{
const
agentFunction
=
{
name
:
agentFunName
,
name
:
agentFunName
,
description
:
`
${
description
}
\n如果内容不存在,返回空字符串。
当前时间是2023/7/31 18:00
`
,
description
:
`
${
description
}
\n如果内容不存在,返回空字符串。`
,
parameters
:
{
parameters
:
{
type
:
'object'
,
type
:
'object'
,
properties
,
properties
,
...
...
client/src/service/moduleDispatch/index.ts
View file @
ffd4e194
...
@@ -3,4 +3,6 @@ export * from './init/userChatInput';
...
@@ -3,4 +3,6 @@ export * from './init/userChatInput';
export
*
from
'./chat/oneapi'
;
export
*
from
'./chat/oneapi'
;
export
*
from
'./kb/search'
;
export
*
from
'./kb/search'
;
export
*
from
'./tools/answer'
;
export
*
from
'./tools/answer'
;
export
*
from
'./tools/http'
;
export
*
from
'./agent/classifyQuestion'
;
export
*
from
'./agent/classifyQuestion'
;
export
*
from
'./agent/extract'
;
client/src/service/moduleDispatch/tools/http.ts
0 → 100644
View file @
ffd4e194
import
{
HttpPropsEnum
}
from
'@/constants/flow/flowField'
;
import
type
{
NextApiResponse
}
from
'next'
;
export
type
HttpRequestProps
=
{
res
:
NextApiResponse
;
stream
:
boolean
;
userOpenaiAccount
:
any
;
[
HttpPropsEnum
.
url
]:
string
;
[
key
:
string
]:
any
;
};
export
type
HttpResponse
=
{
[
HttpPropsEnum
.
finish
]:
boolean
;
[
HttpPropsEnum
.
failed
]?:
boolean
;
[
key
:
string
]:
any
;
};
export
const
dispatchHttpRequest
=
async
(
props
:
Record
<
string
,
any
>
):
Promise
<
HttpResponse
>
=>
{
const
{
res
,
stream
,
userOpenaiAccount
,
url
,
...
body
}
=
props
as
HttpRequestProps
;
try
{
const
response
=
await
fetchData
({
url
,
body
});
return
{
[
HttpPropsEnum
.
finish
]:
true
,
...
response
};
}
catch
(
error
)
{
return
{
[
HttpPropsEnum
.
finish
]:
true
,
[
HttpPropsEnum
.
failed
]:
true
};
}
};
async
function
fetchData
({
url
,
body
}:
{
url
:
string
;
body
:
Record
<
string
,
any
>
;
}):
Promise
<
Record
<
string
,
any
>>
{
const
response
=
await
fetch
(
url
,
{
method
:
'POST'
,
headers
:
{
'Content-Type'
:
'application/json'
},
body
:
JSON
.
stringify
(
body
)
}).
then
((
res
)
=>
res
.
json
());
return
response
;
}
client/src/service/moduleDispatch/tools/httpRequest.ts
deleted
100644 → 0
View file @
952da2a0
import
{
sseResponseEventEnum
,
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
{
sseResponse
}
from
'@/service/utils/tools'
;
import
{
textAdaptGptResponse
}
from
'@/utils/adapt'
;
import
type
{
NextApiResponse
}
from
'next'
;
export
type
AnswerProps
=
{
res
:
NextApiResponse
;
text
:
string
;
stream
:
boolean
;
};
export
type
AnswerResponse
=
{
[
TaskResponseKeyEnum
.
answerText
]:
string
;
};
export
const
dispatchAnswer
=
(
props
:
Record
<
string
,
any
>
):
AnswerResponse
=>
{
const
{
res
,
text
=
''
,
stream
}
=
props
as
AnswerProps
;
if
(
stream
)
{
sseResponse
({
res
,
event
:
sseResponseEventEnum
.
answer
,
data
:
textAdaptGptResponse
({
text
:
text
.
replace
(
/
\\
n/g
,
'\n'
)
})
});
}
return
{
[
TaskResponseKeyEnum
.
answerText
]:
text
};
};
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