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
9923a402
authored
Apr 27, 2025
by
heheer
Committed by
GitHub
Apr 27, 2025
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: chat quote number (#4679)
parent
6763ac60
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
81 deletions
+42
-81
packages/global/core/ai/prompt/AIChat.ts
+8
-10
packages/service/core/workflow/dispatch/chat/oneapi.ts
+2
-28
projects/app/src/components/Markdown/A.tsx
+8
-34
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx
+5
-2
projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/NodeTemplatesModal.tsx
+4
-1
projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/nodes/render/RenderInput/templates/SettingQuotePrompt.tsx
+2
-2
projects/app/src/pageComponents/chat/ChatQuoteList/CollectionQuoteReader.tsx
+12
-4
projects/app/src/web/core/chat/context/chatItemContext.tsx
+1
-0
No files found.
packages/global/core/ai/prompt/AIChat.ts
View file @
9923a402
...
...
@@ -8,7 +8,6 @@ export const Prompt_QuoteTemplateList: PromptTemplateItem[] = [
desc
:
i18nT
(
'app:template.standard_template_des'
),
value
:
{
[
'4.9.7'
]:
`{
"sourceIndex": "{{sourceIndex}}",
"id": "{{id}}",
"sourceName": "{{source}}",
"content": "{{q}}\n{{a}}"
...
...
@@ -39,7 +38,6 @@ export const Prompt_QuoteTemplateList: PromptTemplateItem[] = [
desc
:
i18nT
(
'app:template.standard_strict_des'
),
value
:
{
[
'4.9.7'
]:
`{
"sourceIndex": "{{sourceIndex}}",
"id": "{{id}}",
"sourceName": "{{source}}",
"content": "{{q}}\n{{a}}"
...
...
@@ -90,8 +88,8 @@ export const Prompt_userQuotePromptList: PromptTemplateItem[] = [
- 保持答案与 <Reference></Reference> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
- 使用 [id](QUOTE
{{sourceIndex}}) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 和 sourceIndex 分别为引文中的值
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE
1
)。"
- 使用 [id](QUOTE
) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 为引文中的 id
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE)。"
- 每段至少包含一个引用,也可根据内容需要加入多个引用,按顺序排列。`
,
[
'4.9.2'
]:
`使用 <Reference></Reference> 标记中的内容作为本次对话的参考:
...
...
@@ -148,8 +146,8 @@ export const Prompt_userQuotePromptList: PromptTemplateItem[] = [
- 保持答案与 <Reference></Reference> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
- 使用 [id](QUOTE
{{sourceIndex}}) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 和 sourceIndex 分别为引文中的值
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE
1
)。"
- 使用 [id](QUOTE
) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 为引文中的 id
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE)。"
- 每段至少包含一个引用,也可根据内容需要加入多个引用,按顺序排列。
问题:"""{{question}}"""`
,
...
...
@@ -219,8 +217,8 @@ export const Prompt_systemQuotePromptList: PromptTemplateItem[] = [
- 保持答案与 <Reference></Reference> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
- 使用 [id](QUOTE
{{sourceIndex}}) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 和 sourceIndex 分别为引文中的值
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE
1
)。"
- 使用 [id](QUOTE
) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 为引文中的 id
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE)。"
- 每段至少包含一个引用,也可根据内容需要加入多个引用,按顺序排列。`
,
[
'4.9.2'
]:
`使用 <Reference></Reference> 标记中的内容作为本次对话的参考:
...
...
@@ -273,8 +271,8 @@ export const Prompt_systemQuotePromptList: PromptTemplateItem[] = [
- 保持答案与 <Reference></Reference> 中描述的一致。
- 使用 Markdown 语法优化回答格式。
- 使用与问题相同的语言回答。
- 使用 [id](QUOTE
{{sourceIndex}}) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 和 sourceIndex 分别为引文中的值
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE
1
)。"
- 使用 [id](QUOTE
) 格式来引用<Reference></Reference>中的知识,其中 QUOTE 是固定常量, id 为引文中的 id
。
- 在每段结尾自然地整合引用。例如: "FastGPT 是一个基于大语言模型(LLM)的知识库问答系统[67e517e74767063e882d6861](QUOTE)。"
- 每段至少包含一个引用,也可根据内容需要加入多个引用,按顺序排列。
问题:"""{{question}}"""`
,
...
...
packages/service/core/workflow/dispatch/chat/oneapi.ts
View file @
9923a402
...
...
@@ -348,17 +348,7 @@ async function filterDatasetQuote({
model
:
LLMModelItemType
;
quoteTemplate
:
string
;
})
{
function
getValue
({
item
,
index
,
sourceList
}:
{
item
:
SearchDataResponseItemType
;
index
:
number
;
sourceList
:
{
sourceName
:
string
;
sourceId
:
string
;
sourceIndex
:
number
}[];
})
{
const
source
=
sourceList
.
find
((
source
)
=>
source
.
sourceId
===
item
.
sourceId
);
function
getValue
({
item
,
index
}:
{
item
:
SearchDataResponseItemType
;
index
:
number
})
{
return
replaceVariable
(
quoteTemplate
,
{
id
:
item
.
id
,
q
:
item
.
q
,
...
...
@@ -366,7 +356,6 @@ async function filterDatasetQuote({
updateTime
:
formatTime2YMDHM
(
item
.
updateTime
),
source
:
item
.
sourceName
,
sourceId
:
String
(
item
.
sourceId
||
''
),
sourceIndex
:
source
?.
sourceIndex
||
1
,
index
:
index
+
1
});
}
...
...
@@ -374,24 +363,9 @@ async function filterDatasetQuote({
// slice filterSearch
const
filterQuoteQA
=
await
filterSearchResultsByMaxChars
(
quoteQA
,
model
.
quoteMaxToken
);
const
sourceList
=
Object
.
values
(
filterQuoteQA
.
reduce
((
acc
:
Record
<
string
,
SearchDataResponseItemType
[]
>
,
cur
)
=>
{
if
(
!
acc
[
cur
.
collectionId
])
{
acc
[
cur
.
collectionId
]
=
[
cur
];
}
return
acc
;
},
{})
)
.
flat
()
.
map
((
item
,
index
)
=>
({
sourceName
:
item
.
sourceName
||
''
,
sourceId
:
item
.
sourceId
||
''
,
sourceIndex
:
index
+
1
}));
const
datasetQuoteText
=
filterQuoteQA
.
length
>
0
?
`
${
filterQuoteQA
.
map
((
item
,
index
)
=>
getValue
({
item
,
index
,
sourceList
}).
trim
()).
join
(
'\n------\n'
)}
`
?
`
${
filterQuoteQA
.
map
((
item
,
index
)
=>
getValue
({
item
,
index
}).
trim
()).
join
(
'\n------\n'
)}
`
:
''
;
return
{
...
...
projects/app/src/components/Markdown/A.tsx
View file @
9923a402
...
...
@@ -56,9 +56,6 @@ const A = ({ children, ...props }: any) => {
// Quote
if
(
props
.
href
?.
startsWith
(
'QUOTE'
)
&&
typeof
children
?.[
0
]
===
'string'
)
{
const
indexMatch
=
props
.
href
.
match
(
/QUOTE
(\d
+
)
/
);
const
index
=
indexMatch
?
indexMatch
[
1
]
:
'1'
;
const
sourceData
=
useMemo
(
()
=>
getCollectionSourceData
(
quoteData
?.
collection
),
[
quoteData
?.
collection
]
...
...
@@ -80,27 +77,17 @@ const A = ({ children, ...props }: any) => {
onOpen
();
runAsync
(
String
(
children
));
}
}
trigger=
{
'hover'
}
gutter=
{
4
}
>
<
PopoverTrigger
>
<
Button
variant=
{
'unstyled'
}
minH=
{
0
}
minW=
{
0
}
h=
{
'auto'
}
>
<
MyTooltip
label=
{
t
(
'common:read_quote'
)
}
>
<
Box
w=
{
'14px'
}
h=
{
'14px'
}
borderRadius=
{
'full'
}
bg=
{
'rgba(0, 0, 0, 0.08)'
}
color=
{
'myGray.600'
}
fontSize=
{
'10px'
}
display=
{
'flex'
}
alignItems=
{
'center'
}
justifyContent=
{
'center'
}
ml=
{
0.5
}
transform=
{
'translateY(-3px)'
}
>
{
index
}
</
Box
>
</
MyTooltip
>
<
MyIcon
name=
{
'core/chat/quoteSign'
}
w=
{
'1rem'
}
color=
{
'primary.700'
}
cursor=
{
'pointer'
}
/>
</
Button
>
</
PopoverTrigger
>
<
PopoverContent
boxShadow=
{
'lg'
}
w=
{
'500px'
}
py=
{
4
}
>
...
...
@@ -118,19 +105,6 @@ const A = ({ children, ...props }: any) => {
height=
{
6
}
mr=
{
1
}
>
<
Flex
color=
{
'myGray.500'
}
bg=
{
'myGray.150'
}
w=
{
4
}
justifyContent=
{
'center'
}
fontSize=
{
'10px'
}
h=
{
'full'
}
alignItems=
{
'center'
}
mr=
{
1
}
flexShrink=
{
0
}
>
{
index
}
</
Flex
>
<
Flex
px=
{
1.5
}
>
<
MyIcon
name=
{
icon
as
any
}
mr=
{
1
}
flexShrink=
{
0
}
w=
{
'12px'
}
/>
<
Box
...
...
@@ -151,7 +125,7 @@ const A = ({ children, ...props }: any) => {
onClick=
{
()
=>
{
onClose
();
eventBus
.
emit
(
EventNameEnum
.
openQuoteReader
,
{
//
quoteId: String(children),
quoteId
:
String
(
children
),
sourceId
:
sourceData
.
sourceId
,
sourceName
:
sourceData
.
sourceName
,
datasetId
:
quoteData
?.
collection
.
datasetId
,
...
...
projects/app/src/components/core/chat/ChatContainer/ChatBox/components/ChatItem.tsx
View file @
9923a402
...
...
@@ -227,12 +227,14 @@ const ChatItem = (props: Props) => {
collectionId
,
sourceId
,
sourceName
,
datasetId
datasetId
,
quoteId
}:
{
collectionId
?:
string
;
sourceId
?:
string
;
sourceName
?:
string
;
datasetId
?:
string
;
quoteId
?:
string
;
})
=>
{
if
(
!
setQuoteData
)
return
;
...
...
@@ -252,7 +254,8 @@ const ChatItem = (props: Props) => {
sourceId
:
sourceId
||
''
,
sourceName
:
sourceName
||
''
,
datasetId
:
datasetId
||
''
,
outLinkAuthData
outLinkAuthData
,
quoteId
}
:
{
appId
:
appId
,
...
...
projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/NodeTemplatesModal.tsx
View file @
9923a402
...
...
@@ -72,6 +72,7 @@ type RenderHeaderProps = {
onUpdateParentId
:
(
parentId
:
ParentIdType
)
=>
void
;
};
type
RenderListProps
=
{
templateType
:
TemplateTypeEnum
;
templates
:
NodeTemplateListItemType
[];
type
:
TemplateTypeEnum
;
onClose
:
()
=>
void
;
...
...
@@ -247,6 +248,7 @@ const NodeTemplatesModal = ({ isOpen, onClose }: ModuleTemplateListProps) => {
setSearchKey=
{
setSearchKey
}
/>
<
RenderList
templateType=
{
templateType
}
templates=
{
templates
}
type=
{
templateType
}
onClose=
{
onClose
}
...
...
@@ -402,6 +404,7 @@ const RenderHeader = React.memo(function RenderHeader({
});
const
RenderList
=
React
.
memo
(
function
RenderList
({
templateType
,
templates
,
type
,
onClose
,
...
...
@@ -712,7 +715,7 @@ const RenderList = React.memo(function RenderList({
{
t
(
template
.
name
as
any
)
}
</
Box
>
{
template
.
isFolder
&&
(
{
template
.
isFolder
&&
templateType
===
TemplateTypeEnum
.
teamPlugin
&&
(
<
Box
color=
{
'myGray.500'
}
_hover=
{
{
...
...
projects/app/src/pageComponents/app/detail/WorkflowComponents/Flow/nodes/render/RenderInput/templates/SettingQuotePrompt.tsx
View file @
9923a402
...
...
@@ -94,8 +94,8 @@ const EditModal = ({ onClose, ...props }: RenderInputProps & { onClose: () => vo
icon
:
'core/app/simpleMode/variable'
},
{
key
:
'sourceI
ndex
'
,
label
:
t
(
'common:core.dataset.search.Source i
ndex
'
),
key
:
'sourceI
d
'
,
label
:
t
(
'common:core.dataset.search.Source i
d
'
),
icon
:
'core/app/simpleMode/variable'
},
{
...
...
projects/app/src/pageComponents/chat/ChatQuoteList/CollectionQuoteReader.tsx
View file @
9923a402
...
...
@@ -35,7 +35,7 @@ const CollectionReader = ({
const
router
=
useRouter
();
const
{
userInfo
}
=
useUserStore
();
const
{
collectionId
,
datasetId
,
chatItemDataId
,
sourceId
,
sourceName
}
=
metadata
;
const
{
collectionId
,
datasetId
,
chatItemDataId
,
sourceId
,
sourceName
,
quoteId
}
=
metadata
;
const
[
quoteIndex
,
setQuoteIndex
]
=
useState
(
0
);
// Get dataset permission
...
...
@@ -45,11 +45,19 @@ const CollectionReader = ({
});
const
filterResults
=
useMemo
(()
=>
{
setQuoteIndex
(
0
);
return
rawSearch
const
res
=
rawSearch
.
filter
((
item
)
=>
item
.
collectionId
===
collectionId
)
.
sort
((
a
,
b
)
=>
(
a
.
chunkIndex
||
0
)
-
(
b
.
chunkIndex
||
0
));
},
[
collectionId
,
rawSearch
]);
if
(
quoteId
)
{
setQuoteIndex
(
res
.
findIndex
((
item
)
=>
item
.
id
===
quoteId
));
}
else
{
setQuoteIndex
(
0
);
}
return
res
;
},
[
collectionId
,
quoteId
,
rawSearch
]);
const
currentQuoteItem
=
useMemo
(()
=>
{
const
item
=
filterResults
[
quoteIndex
];
if
(
item
)
{
...
...
projects/app/src/web/core/chat/context/chatItemContext.tsx
View file @
9923a402
...
...
@@ -41,6 +41,7 @@ export type GetQuoteDataBasicProps = {
};
// 获取单个集合引用
export
type
GetCollectionQuoteDataProps
=
GetQuoteDataBasicProps
&
{
quoteId
?:
string
;
collectionId
:
string
;
sourceId
:
string
;
sourceName
:
string
;
...
...
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