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
b7d18e38
authored
Jul 23, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: template
parent
5e0b1470
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
43 deletions
+37
-43
client/src/constants/flow/ModuleTemplate.ts
+0
-0
client/src/constants/flow/index.ts
+6
-2
client/src/pages/app/detail/components/Edit/components/modules/NodeCard.tsx
+9
-5
client/src/pages/app/detail/components/Edit/index.tsx
+0
-1
client/src/service/moduleDispatch/agent/classifyQuestion.ts
+2
-6
client/src/service/utils/chat/index.ts
+10
-24
client/src/utils/app.ts
+10
-5
No files found.
client/src/constants/flow/ModuleTemplate.ts
View file @
b7d18e38
This diff is collapsed.
Click to expand it.
client/src/constants/flow/index.ts
View file @
b7d18e38
...
@@ -31,6 +31,10 @@ export enum FlowModuleTypeEnum {
...
@@ -31,6 +31,10 @@ export enum FlowModuleTypeEnum {
classifyQuestion
=
'classifyQuestion'
classifyQuestion
=
'classifyQuestion'
}
}
export
enum
SpecialInputKeyEnum
{
'answerText'
=
'text'
}
export
const
initModuleType
:
Record
<
string
,
boolean
>
=
{
export
const
initModuleType
:
Record
<
string
,
boolean
>
=
{
[
FlowModuleTypeEnum
.
historyNode
]:
true
,
[
FlowModuleTypeEnum
.
historyNode
]:
true
,
[
FlowModuleTypeEnum
.
questionInput
]:
true
[
FlowModuleTypeEnum
.
questionInput
]:
true
...
@@ -38,8 +42,8 @@ export const initModuleType: Record<string, boolean> = {
...
@@ -38,8 +42,8 @@ export const initModuleType: Record<string, boolean> = {
export
const
edgeOptions
=
{
export
const
edgeOptions
=
{
style
:
{
style
:
{
strokeWidth
:
1
,
strokeWidth
:
1
.5
,
stroke
:
'#5A646Es'
stroke
:
'#5A646Es'
}
}
};
};
export
const
connectionLineStyle
=
{
strokeWidth
:
1
,
stroke
:
'#5A646Es'
};
export
const
connectionLineStyle
=
{
strokeWidth
:
1
.5
,
stroke
:
'#5A646Es'
};
client/src/pages/app/detail/components/Edit/components/modules/NodeCard.tsx
View file @
b7d18e38
...
@@ -41,15 +41,19 @@ const NodeCard = ({
...
@@ -41,15 +41,19 @@ const NodeCard = ({
</
MyTooltip
>
</
MyTooltip
>
)
}
)
}
<
Box
flex=
{
1
}
/>
<
Box
flex=
{
1
}
/>
<
MyIcon
<
Flex
className=
{
'nodrag'
}
className=
{
'nodrag'
}
name=
"delete"
w=
{
'22px'
}
cursor=
{
'pointer'
}
h=
{
'22px'
}
alignItems=
{
'center'
}
justifyContent=
{
'center'
}
color=
{
'myGray.600'
}
color=
{
'myGray.600'
}
w=
{
'16px'
}
_hover=
{
{
color
:
'red.600'
}
}
_hover=
{
{
color
:
'red.600'
}
}
cursor=
{
'pointer'
}
onClick=
{
()
=>
onDelNode
(
moduleId
)
}
onClick=
{
()
=>
onDelNode
(
moduleId
)
}
/>
>
<
MyIcon
name=
"delete"
w=
{
'16px'
}
/>
</
Flex
>
</
Flex
>
</
Flex
>
{
children
}
{
children
}
</
Box
>
</
Box
>
...
...
client/src/pages/app/detail/components/Edit/index.tsx
View file @
b7d18e38
...
@@ -283,7 +283,6 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
...
@@ -283,7 +283,6 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
useEffect
(()
=>
{
useEffect
(()
=>
{
initData
(
JSON
.
parse
(
JSON
.
stringify
(
app
)));
initData
(
JSON
.
parse
(
JSON
.
stringify
(
app
)));
},
[
app
,
initData
]);
},
[
app
,
initData
]);
console
.
log
(
flow2AppModules
());
return
(
return
(
<>
<>
...
...
client/src/service/moduleDispatch/agent/classifyQuestion.ts
View file @
b7d18e38
...
@@ -51,7 +51,7 @@ export const dispatchClassifyQuestion = async (props: Record<string, any>): Prom
...
@@ -51,7 +51,7 @@ export const dispatchClassifyQuestion = async (props: Record<string, any>): Prom
// function body
// function body
const
agentFunction
=
{
const
agentFunction
=
{
name
:
agentFunName
,
name
:
agentFunName
,
description
:
'判断用户问题的类型
,并返回指定值
'
,
description
:
'判断用户问题的类型
属于哪方面,返回对应的枚举字段
'
,
parameters
:
{
parameters
:
{
type
:
'object'
,
type
:
'object'
,
properties
:
{
properties
:
{
...
@@ -81,13 +81,9 @@ export const dispatchClassifyQuestion = async (props: Record<string, any>): Prom
...
@@ -81,13 +81,9 @@ export const dispatchClassifyQuestion = async (props: Record<string, any>): Prom
const
arg
=
JSON
.
parse
(
response
.
data
.
choices
?.[
0
]?.
message
?.
function_call
?.
arguments
||
''
);
const
arg
=
JSON
.
parse
(
response
.
data
.
choices
?.[
0
]?.
message
?.
function_call
?.
arguments
||
''
);
if
(
!
arg
.
type
)
{
throw
new
Error
(
''
);
}
const
tokens
=
response
.
data
.
usage
?.
total_tokens
||
0
;
const
tokens
=
response
.
data
.
usage
?.
total_tokens
||
0
;
const
result
=
agents
.
find
((
item
)
=>
item
.
key
===
arg
.
type
)
||
agents
[
0
];
const
result
=
agents
.
find
((
item
)
=>
item
.
key
===
arg
?
.
type
)
||
agents
[
0
];
return
{
return
{
[
result
.
key
]:
1
,
[
result
.
key
]:
1
,
...
...
client/src/service/utils/chat/index.ts
View file @
b7d18e38
...
@@ -31,7 +31,7 @@ const simplifyStr = (str = '') =>
...
@@ -31,7 +31,7 @@ const simplifyStr = (str = '') =>
.
replace
(
/
[^\S\r\n]
+/g
,
' '
)
// 连续空白内容
.
replace
(
/
[^\S\r\n]
+/g
,
' '
)
// 连续空白内容
.
trim
();
.
trim
();
/*
聊天上下文 tokens 截断
*/
/*
slice chat context by tokens
*/
export
const
ChatContextFilter
=
({
export
const
ChatContextFilter
=
({
model
,
model
,
prompts
,
prompts
,
...
@@ -41,33 +41,19 @@ export const ChatContextFilter = ({
...
@@ -41,33 +41,19 @@ export const ChatContextFilter = ({
prompts
:
ChatItemType
[];
prompts
:
ChatItemType
[];
maxTokens
:
number
;
maxTokens
:
number
;
})
=>
{
})
=>
{
const
systemPrompts
:
ChatItemType
[]
=
[];
const
rawTextLen
=
prompts
.
reduce
((
sum
,
item
)
=>
sum
+
item
.
value
.
length
,
0
);
const
chatPrompts
:
ChatItemType
[]
=
[];
let
rawTextLen
=
0
;
// If the text length is less than half of the maximum token, no calculation is required
prompts
.
forEach
((
item
)
=>
{
const
val
=
simplifyStr
(
item
.
value
);
rawTextLen
+=
val
.
length
;
const
data
=
{
_id
:
item
.
_id
,
obj
:
item
.
obj
,
value
:
val
};
if
(
item
.
obj
===
ChatRoleEnum
.
System
)
{
systemPrompts
.
push
(
data
);
}
else
{
chatPrompts
.
push
(
data
);
}
});
// 长度太小时,不需要进行 token 截断
if
(
rawTextLen
<
maxTokens
*
0.5
)
{
if
(
rawTextLen
<
maxTokens
*
0.5
)
{
return
[...
systemPrompts
,
...
chatPrompts
]
;
return
prompts
;
}
}
// 去掉 system 的 token
// filter startWith system prompt
const
chatStartIndex
=
prompts
.
findIndex
((
item
)
=>
item
.
obj
!==
ChatRoleEnum
.
System
);
const
systemPrompts
:
ChatItemType
[]
=
prompts
.
slice
(
0
,
chatStartIndex
);
const
chatPrompts
:
ChatItemType
[]
=
prompts
.
slice
(
chatStartIndex
);
// reduce token of systemPrompt
maxTokens
-=
modelToolMap
.
countTokens
({
maxTokens
-=
modelToolMap
.
countTokens
({
model
,
model
,
messages
:
systemPrompts
messages
:
systemPrompts
...
...
client/src/utils/app.ts
View file @
b7d18e38
import
type
{
AppModuleInputItemType
,
AppModuleItemType
,
VariableItemType
}
from
'@/types/app'
;
import
type
{
AppModuleInputItemType
,
AppModuleItemType
,
VariableItemType
}
from
'@/types/app'
;
import
{
chatModelList
,
vectorModelList
}
from
'@/store/static'
;
import
{
chatModelList
,
vectorModelList
}
from
'@/store/static'
;
import
{
FlowModuleTypeEnum
}
from
'@/constants/flow'
;
import
{
FlowModuleTypeEnum
,
SpecialInputKeyEnum
}
from
'@/constants/flow'
;
import
{
SystemInputEnum
}
from
'@/constants/app'
;
import
{
SystemInputEnum
}
from
'@/constants/app'
;
import
{
TaskResponseKeyEnum
}
from
'@/constants/chat'
;
import
type
{
SelectedKbType
}
from
'@/types/plugin'
;
import
type
{
SelectedKbType
}
from
'@/types/plugin'
;
export
type
EditFormType
=
{
export
type
EditFormType
=
{
...
@@ -128,7 +129,7 @@ export const appModules2Form = (modules: AppModuleItemType[]) => {
...
@@ -128,7 +129,7 @@ export const appModules2Form = (modules: AppModuleItemType[]) => {
if
(
emptyOutput
)
{
if
(
emptyOutput
)
{
const
target
=
modules
.
find
((
item
)
=>
item
.
moduleId
===
emptyOutput
.
moduleId
);
const
target
=
modules
.
find
((
item
)
=>
item
.
moduleId
===
emptyOutput
.
moduleId
);
defaultAppForm
.
kb
.
searchEmptyText
=
defaultAppForm
.
kb
.
searchEmptyText
=
target
?.
inputs
?.
find
((
item
)
=>
item
.
key
===
'answerText'
)?.
value
||
''
;
target
?.
inputs
?.
find
((
item
)
=>
item
.
key
===
SpecialInputKeyEnum
.
answerText
)?.
value
||
''
;
}
}
}
else
if
(
module
.
flowType
===
FlowModuleTypeEnum
.
userGuide
)
{
}
else
if
(
module
.
flowType
===
FlowModuleTypeEnum
.
userGuide
)
{
const
val
=
const
val
=
...
@@ -174,6 +175,10 @@ const chatModelInput = (formData: EditFormType): AppModuleInputItemType[] => [
...
@@ -174,6 +175,10 @@ const chatModelInput = (formData: EditFormType): AppModuleInputItemType[] => [
connected
:
true
connected
:
true
},
},
{
{
key
:
'switch'
,
connected
:
formData
.
kb
.
list
.
length
>
0
},
{
key
:
'quoteQA'
,
key
:
'quoteQA'
,
connected
:
formData
.
kb
.
list
.
length
>
0
connected
:
formData
.
kb
.
list
.
length
>
0
},
},
...
@@ -289,7 +294,7 @@ const simpleChatTemplate = (formData: EditFormType): AppModuleItemType[] => [
...
@@ -289,7 +294,7 @@ const simpleChatTemplate = (formData: EditFormType): AppModuleItemType[] => [
inputs
:
chatModelInput
(
formData
),
inputs
:
chatModelInput
(
formData
),
outputs
:
[
outputs
:
[
{
{
key
:
'answerText'
,
key
:
TaskResponseKeyEnum
.
answerText
,
targets
:
[]
targets
:
[]
}
}
],
],
...
@@ -439,7 +444,7 @@ const kbTemplate = (formData: EditFormType): AppModuleItemType[] => [
...
@@ -439,7 +444,7 @@ const kbTemplate = (formData: EditFormType): AppModuleItemType[] => [
connected
:
true
connected
:
true
},
},
{
{
key
:
'answerText'
,
key
:
SpecialInputKeyEnum
.
answerText
,
value
:
formData
.
kb
.
searchEmptyText
,
value
:
formData
.
kb
.
searchEmptyText
,
connected
:
true
connected
:
true
}
}
...
@@ -458,7 +463,7 @@ const kbTemplate = (formData: EditFormType): AppModuleItemType[] => [
...
@@ -458,7 +463,7 @@ const kbTemplate = (formData: EditFormType): AppModuleItemType[] => [
inputs
:
chatModelInput
(
formData
),
inputs
:
chatModelInput
(
formData
),
outputs
:
[
outputs
:
[
{
{
key
:
'answerText'
,
key
:
TaskResponseKeyEnum
.
answerText
,
targets
:
[]
targets
:
[]
}
}
],
],
...
...
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