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
d0e8f720
authored
Sep 14, 2024
by
Archer
Committed by
GitHub
Sep 14, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: plugin support files (#2708)
parent
092bb9ab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
19 deletions
+30
-19
packages/service/core/workflow/dispatch/plugin/run.ts
+9
-1
packages/service/core/workflow/utils.ts
+19
-17
projects/app/src/pages/api/v1/chat/completions.ts
+2
-1
No files found.
packages/service/core/workflow/dispatch/plugin/run.ts
View file @
d0e8f720
...
@@ -14,6 +14,7 @@ import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
...
@@ -14,6 +14,7 @@ import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
import
{
computedPluginUsage
}
from
'../../../app/plugin/utils'
;
import
{
computedPluginUsage
}
from
'../../../app/plugin/utils'
;
import
{
filterSystemVariables
}
from
'../utils'
;
import
{
filterSystemVariables
}
from
'../utils'
;
import
{
getPluginRunUserQuery
}
from
'../../utils'
;
import
{
getPluginRunUserQuery
}
from
'../../utils'
;
import
{
chatValue2RuntimePrompt
}
from
'@fastgpt/global/core/chat/adapt'
;
type
RunPluginProps
=
ModuleDispatchProps
<
{
type
RunPluginProps
=
ModuleDispatchProps
<
{
[
key
:
string
]:
any
;
[
key
:
string
]:
any
;
...
@@ -25,6 +26,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
...
@@ -25,6 +26,7 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
node
:
{
pluginId
},
node
:
{
pluginId
},
runningAppInfo
,
runningAppInfo
,
mode
,
mode
,
query
,
params
:
data
// Plugin input
params
:
data
// Plugin input
}
=
props
;
}
=
props
;
...
@@ -32,6 +34,8 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
...
@@ -32,6 +34,8 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
return
Promise
.
reject
(
'pluginId can not find'
);
return
Promise
.
reject
(
'pluginId can not find'
);
}
}
const
{
files
}
=
chatValue2RuntimePrompt
(
query
);
// auth plugin
// auth plugin
const
pluginData
=
await
authPluginByTmbId
({
const
pluginData
=
await
authPluginByTmbId
({
appId
:
pluginId
,
appId
:
pluginId
,
...
@@ -74,7 +78,11 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
...
@@ -74,7 +78,11 @@ export const dispatchRunPlugin = async (props: RunPluginProps): Promise<RunPlugi
tmbId
:
pluginData
?.
tmbId
||
''
tmbId
:
pluginData
?.
tmbId
||
''
},
},
variables
:
runtimeVariables
,
variables
:
runtimeVariables
,
query
:
getPluginRunUserQuery
(
plugin
.
nodes
,
runtimeVariables
).
value
,
query
:
getPluginRunUserQuery
({
nodes
:
plugin
.
nodes
,
variables
:
runtimeVariables
,
files
}).
value
,
chatConfig
:
{},
chatConfig
:
{},
runtimeNodes
,
runtimeNodes
,
runtimeEdges
:
initWorkflowEdgeStatus
(
plugin
.
edges
)
runtimeEdges
:
initWorkflowEdgeStatus
(
plugin
.
edges
)
...
...
packages/service/core/workflow/utils.ts
View file @
d0e8f720
import
{
SearchDataResponseItemType
}
from
'@fastgpt/global/core/dataset/type'
;
import
{
SearchDataResponseItemType
}
from
'@fastgpt/global/core/dataset/type'
;
import
{
countPromptTokens
}
from
'../../common/string/tiktoken/index'
;
import
{
countPromptTokens
}
from
'../../common/string/tiktoken/index'
;
import
{
getNanoid
}
from
'@fastgpt/global/common/string/tools'
;
import
{
getNanoid
}
from
'@fastgpt/global/common/string/tools'
;
import
{
Chat
ItemValueTypeEnum
,
Chat
RoleEnum
}
from
'@fastgpt/global/core/chat/constants'
;
import
{
ChatRoleEnum
}
from
'@fastgpt/global/core/chat/constants'
;
import
{
import
{
getPluginInputsFromStoreNodes
,
getPluginInputsFromStoreNodes
,
getPluginRunContent
getPluginRunContent
}
from
'@fastgpt/global/core/app/plugin/utils'
;
}
from
'@fastgpt/global/core/app/plugin/utils'
;
import
{
StoreNodeItemType
}
from
'@fastgpt/global/core/workflow/type/node'
;
import
{
StoreNodeItemType
}
from
'@fastgpt/global/core/workflow/type/node'
;
import
{
UserChatItemType
}
from
'@fastgpt/global/core/chat/type'
;
import
{
RuntimeUserPromptType
,
UserChatItemType
}
from
'@fastgpt/global/core/chat/type'
;
import
{
runtimePrompt2ChatsValue
}
from
'@fastgpt/global/core/chat/adapt'
;
/* filter search result */
/* filter search result */
export
const
filterSearchResultsByMaxChars
=
async
(
export
const
filterSearchResultsByMaxChars
=
async
(
...
@@ -33,23 +34,24 @@ export const filterSearchResultsByMaxChars = async (
...
@@ -33,23 +34,24 @@ export const filterSearchResultsByMaxChars = async (
};
};
/* Get plugin runtime input user query */
/* Get plugin runtime input user query */
export
const
getPluginRunUserQuery
=
(
export
const
getPluginRunUserQuery
=
({
nodes
:
StoreNodeItemType
[],
nodes
,
variables
:
Record
<
string
,
any
>
variables
,
):
UserChatItemType
&
{
dataId
:
string
}
=>
{
files
=
[]
}:
{
nodes
:
StoreNodeItemType
[];
variables
:
Record
<
string
,
any
>
;
files
?:
RuntimeUserPromptType
[
'files'
];
}):
UserChatItemType
&
{
dataId
:
string
}
=>
{
return
{
return
{
dataId
:
getNanoid
(
24
),
dataId
:
getNanoid
(
24
),
obj
:
ChatRoleEnum
.
Human
,
obj
:
ChatRoleEnum
.
Human
,
value
:
[
value
:
runtimePrompt2ChatsValue
({
{
text
:
getPluginRunContent
({
type
:
ChatItemValueTypeEnum
.
text
,
pluginInputs
:
getPluginInputsFromStoreNodes
(
nodes
),
text
:
{
variables
content
:
getPluginRunContent
({
}),
pluginInputs
:
getPluginInputsFromStoreNodes
(
nodes
),
files
variables
})
})
}
}
]
};
};
};
};
projects/app/src/pages/api/v1/chat/completions.ts
View file @
d0e8f720
...
@@ -189,7 +189,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
...
@@ -189,7 +189,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
// Get obj=Human history
// Get obj=Human history
const
userQuestion
:
UserChatItemType
=
(()
=>
{
const
userQuestion
:
UserChatItemType
=
(()
=>
{
if
(
isPlugin
)
{
if
(
isPlugin
)
{
return
getPluginRunUserQuery
(
app
.
modules
,
variables
);
// TODO:get plugin files from variables
return
getPluginRunUserQuery
({
nodes
:
app
.
modules
,
variables
});
}
}
const
latestHumanChat
=
chatMessages
.
pop
()
as
UserChatItemType
|
undefined
;
const
latestHumanChat
=
chatMessages
.
pop
()
as
UserChatItemType
|
undefined
;
...
...
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