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