mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-24 10:40:07 +08:00
fix: knowledge base url error (#5735)
This commit is contained in:
parent
97130cfb1e
commit
636c788e2b
@ -1,5 +1,5 @@
|
||||
/* eslint-disable react-hooks/rules-of-hooks */
|
||||
import { db } from '@renderer/databases/index'
|
||||
import { db } from '@renderer/databases'
|
||||
import KnowledgeQueue from '@renderer/queue/KnowledgeQueue'
|
||||
import FileManager from '@renderer/services/FileManager'
|
||||
import { getKnowledgeBaseParams } from '@renderer/services/KnowledgeService'
|
||||
|
||||
@ -146,12 +146,15 @@ const WebSearchCitation: React.FC<{ citation: Citation }> = ({ citation }) => {
|
||||
}
|
||||
|
||||
const KnowledgeCitation: React.FC<{ citation: Citation }> = ({ citation }) => (
|
||||
<>
|
||||
{citation.showFavicon && <FileSearch width={16} />}
|
||||
<CitationLink href={citation.url} onClick={(e) => handleLinkClick(citation.url, e)}>
|
||||
{citation.title}
|
||||
</CitationLink>
|
||||
</>
|
||||
<WebSearchCard>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 8, marginBottom: 6 }}>
|
||||
{citation.showFavicon && <FileSearch width={16} />}
|
||||
<CitationLink href={citation.url} onClick={(e) => handleLinkClick(citation.url, e)}>
|
||||
{citation.title}
|
||||
</CitationLink>
|
||||
</div>
|
||||
{citation.content && truncateText(citation.content, 100)}
|
||||
</WebSearchCard>
|
||||
)
|
||||
|
||||
const OpenButton = styled(Button)`
|
||||
@ -177,9 +180,10 @@ const PreviewIcon = styled.div`
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fff;
|
||||
border: 1px solid #fff;
|
||||
background: #f0f2f5;
|
||||
border: 1px solid #e1e4e8;
|
||||
margin-left: -8px;
|
||||
color: var(--color-text-2);
|
||||
|
||||
&:first-child {
|
||||
margin-left: 0;
|
||||
|
||||
@ -155,7 +155,7 @@ export const processKnowledgeSearch = async (
|
||||
})
|
||||
)
|
||||
|
||||
const references = await Promise.all(
|
||||
return await Promise.all(
|
||||
processdResults.map(async (item, index) => {
|
||||
// const baseItem = base.items.find((i) => i.uniqueId === item.metadata.uniqueLoaderId)
|
||||
return {
|
||||
@ -166,7 +166,6 @@ export const processKnowledgeSearch = async (
|
||||
} as KnowledgeReference
|
||||
})
|
||||
)
|
||||
return references
|
||||
} catch (error) {
|
||||
console.error(`Error searching knowledge base ${base.name}:`, error)
|
||||
return []
|
||||
@ -177,9 +176,8 @@ export const processKnowledgeSearch = async (
|
||||
|
||||
const allReferencesRaw = resultsPerBase.flat().filter((ref): ref is KnowledgeReference => !!ref)
|
||||
// 重新为引用分配ID
|
||||
const references = allReferencesRaw.map((ref, index) => ({
|
||||
return allReferencesRaw.map((ref, index) => ({
|
||||
...ref,
|
||||
id: index + 1
|
||||
}))
|
||||
return references
|
||||
}
|
||||
|
||||
@ -187,14 +187,29 @@ const formatCitationsFromBlock = (block: CitationMessageBlock | undefined): Cita
|
||||
// 3. Handle Knowledge Base References
|
||||
if (block.knowledge && block.knowledge.length > 0) {
|
||||
formattedCitations.push(
|
||||
...block.knowledge.map((result, index) => ({
|
||||
number: index + 1,
|
||||
url: result.sourceUrl,
|
||||
title: result.sourceUrl,
|
||||
content: result.content,
|
||||
showFavicon: true,
|
||||
type: 'knowledge'
|
||||
}))
|
||||
...block.knowledge.map((result, index) => {
|
||||
const filePattern = /\[(.*?)]\(http:\/\/file\/(.*?)\)/
|
||||
const fileMatch = result.sourceUrl.match(filePattern)
|
||||
|
||||
let url = result.sourceUrl
|
||||
let title = result.sourceUrl
|
||||
let showFavicon = true
|
||||
|
||||
// 如果匹配文件链接格式 [filename](http://file/xxx)
|
||||
if (fileMatch) {
|
||||
title = fileMatch[1]
|
||||
url = `http://file/${fileMatch[2]}`
|
||||
}
|
||||
|
||||
return {
|
||||
number: index + 1,
|
||||
url: url,
|
||||
title: title,
|
||||
content: result.content,
|
||||
showFavicon: showFavicon,
|
||||
type: 'knowledge'
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
// 4. Deduplicate by URL and Renumber Sequentially
|
||||
|
||||
Loading…
Reference in New Issue
Block a user