diff --git a/src/renderer/src/utils/formats.ts b/src/renderer/src/utils/formats.ts index f08bb131..23a57913 100644 --- a/src/renderer/src/utils/formats.ts +++ b/src/renderer/src/utils/formats.ts @@ -71,12 +71,16 @@ export function withGeminiGrounding(message: Message) { let content = message.content groundingSupports.forEach((support) => { - const text = support.segment.text - const indices = support.groundingChunkIndices - const nodes = indices.reduce((acc, index) => { + const text = support?.segment + const indices = support?.groundingChunckIndices + + if (!text || !indices) return + + const nodes = indices.reduce((acc, index) => { acc.push(`${index + 1}`) return acc }, []) + content = content.replace(text, `${text} ${nodes.join(' ')}`) })