fix: markdown解析bug

This commit is contained in:
imeepos
2025-07-22 16:09:31 +08:00
parent 725514af2d
commit dde679fd6e
3 changed files with 59 additions and 13 deletions

View File

@@ -99,13 +99,13 @@ export const EnhancedMarkdownRenderer: React.FC<EnhancedMarkdownRendererProps> =
return null;
}
// 计算节点在原始文本中的字偏移位置
const nodeStartOffset = node.range?.start?.offset || 0;
const nodeEndOffset = node.range?.end?.offset || 0;
// 计算节点在原始文本中的字偏移位置与grounding数据的字节偏移匹配
const nodeStartOffset = node.range?.start?.byte_offset || 0;
const nodeEndOffset = node.range?.end?.byte_offset || 0;
// 查找与当前节点位置重叠的grounding支持信息
const relatedSupports = groundingMetadata.grounding_supports.filter(support => {
// 这里是字符串二进制的offset
// grounding数据使用字节偏移
const segmentStart = support.segment.startIndex;
const segmentEnd = support.segment.endIndex;
@@ -113,7 +113,11 @@ export const EnhancedMarkdownRenderer: React.FC<EnhancedMarkdownRendererProps> =
// 检查节点范围与grounding片段是否有重叠
return hasOverlap;
});
console.log({
relatedSupports,
nodeStartOffset,
nodeEndOffset
})
if (relatedSupports.length > 0) {
// 获取相关的来源信息
const relatedSources = relatedSupports.flatMap(support =>