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
110bf939
authored
Aug 03, 2024
by
heheer
Committed by
GitHub
Aug 03, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: get plugin input variables from history (#2255)
parent
48f2c95b
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
7 deletions
+47
-7
packages/global/core/app/plugin/utils.ts
+16
-2
projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx
+26
-2
projects/app/src/components/core/chat/ChatContainer/PluginRunBox/context.tsx
+3
-2
projects/app/src/pages/api/v1/chat/completions.ts
+2
-1
No files found.
packages/global/core/app/plugin/utils.ts
View file @
110bf939
...
@@ -5,6 +5,20 @@ import { FlowNodeTypeEnum } from '../../workflow/node/constant';
...
@@ -5,6 +5,20 @@ import { FlowNodeTypeEnum } from '../../workflow/node/constant';
export
const
getPluginInputsFromStoreNodes
=
(
nodes
:
StoreNodeItemType
[])
=>
{
export
const
getPluginInputsFromStoreNodes
=
(
nodes
:
StoreNodeItemType
[])
=>
{
return
nodes
.
find
((
node
)
=>
node
.
flowNodeType
===
FlowNodeTypeEnum
.
pluginInput
)?.
inputs
||
[];
return
nodes
.
find
((
node
)
=>
node
.
flowNodeType
===
FlowNodeTypeEnum
.
pluginInput
)?.
inputs
||
[];
};
};
export
const
getPluginRunContent
=
(
e
:
{
pluginInputs
:
FlowNodeInputItemType
[]
})
=>
{
export
const
getPluginRunContent
=
({
return
JSON
.
stringify
(
e
);
pluginInputs
,
variables
}:
{
pluginInputs
:
FlowNodeInputItemType
[];
variables
:
Record
<
string
,
any
>
;
})
=>
{
const
pluginInputsWithValue
=
pluginInputs
.
map
((
input
)
=>
{
const
{
key
}
=
input
;
const
value
=
variables
?.
hasOwnProperty
(
key
)
?
variables
[
key
]
:
input
.
defaultValue
;
return
{
...
input
,
value
};
});
return
JSON
.
stringify
(
pluginInputsWithValue
);
};
};
projects/app/src/components/core/chat/ChatContainer/PluginRunBox/components/RenderInput.tsx
View file @
110bf939
...
@@ -31,10 +31,34 @@ const RenderInput = () => {
...
@@ -31,10 +31,34 @@ const RenderInput = () => {
);
);
},
[
pluginInputs
]);
},
[
pluginInputs
]);
const
historyFormValues
=
useMemo
(()
=>
{
if
(
histories
.
length
===
0
)
return
undefined
;
try
{
const
inputValueString
=
histories
[
0
].
value
[
0
].
text
?.
content
||
'[]'
;
return
JSON
.
parse
(
inputValueString
).
reduce
(
(
acc
:
Record
<
string
,
any
>
,
{
key
,
value
}:
{
key
:
string
;
value
:
any
;
}
)
=>
({
...
acc
,
[
key
]:
value
}),
{}
);
}
catch
(
error
)
{
console
.
error
(
'Failed to parse input value:'
,
error
);
return
undefined
;
}
},
[
histories
]);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
isEqual
(
getValues
(),
defaultFormValues
))
return
;
if
(
isEqual
(
getValues
(),
defaultFormValues
))
return
;
reset
(
defaultFormValues
);
reset
(
historyFormValues
||
defaultFormValues
);
},
[
defaultFormValues
,
histor
i
es
]);
},
[
defaultFormValues
,
histor
yFormValu
es
]);
const
isDisabledInput
=
histories
.
length
>
0
;
const
isDisabledInput
=
histories
.
length
>
0
;
...
...
projects/app/src/components/core/chat/ChatContainer/PluginRunBox/context.tsx
View file @
110bf939
...
@@ -51,7 +51,7 @@ const PluginRunContextProvider = ({
...
@@ -51,7 +51,7 @@ const PluginRunContextProvider = ({
},
[]);
},
[]);
const
generatingMessage
=
useCallback
(
const
generatingMessage
=
useCallback
(
({
event
,
text
=
''
,
status
,
name
,
tool
,
variables
}:
generatingMessageProps
)
=>
{
({
event
,
text
=
''
,
status
,
name
,
tool
}:
generatingMessageProps
)
=>
{
setHistories
((
state
)
=>
setHistories
((
state
)
=>
state
.
map
((
item
,
index
)
=>
{
state
.
map
((
item
,
index
)
=>
{
if
(
index
!==
state
.
length
-
1
||
item
.
obj
!==
ChatRoleEnum
.
AI
)
return
item
;
if
(
index
!==
state
.
length
-
1
||
item
.
obj
!==
ChatRoleEnum
.
AI
)
return
item
;
...
@@ -170,7 +170,8 @@ const PluginRunContextProvider = ({
...
@@ -170,7 +170,8 @@ const PluginRunContextProvider = ({
type
:
ChatItemValueTypeEnum
.
text
,
type
:
ChatItemValueTypeEnum
.
text
,
text
:
{
text
:
{
content
:
getPluginRunContent
({
content
:
getPluginRunContent
({
pluginInputs
pluginInputs
,
variables
:
e
})
})
}
}
}
}
...
...
projects/app/src/pages/api/v1/chat/completions.ts
View file @
110bf939
...
@@ -201,7 +201,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
...
@@ -201,7 +201,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
type
:
ChatItemValueTypeEnum
.
text
,
type
:
ChatItemValueTypeEnum
.
text
,
text
:
{
text
:
{
content
:
getPluginRunContent
({
content
:
getPluginRunContent
({
pluginInputs
:
getPluginInputsFromStoreNodes
(
app
.
modules
)
pluginInputs
:
getPluginInputsFromStoreNodes
(
app
.
modules
),
variables
})
})
}
}
}
}
...
...
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