({
similarChunks,
messages
}: {
similarChunks: SimilarChunk[];
messages: Message[];
})
| 110 | }; |
| 111 | |
| 112 | export const getAugmentedContext = ({ |
| 113 | similarChunks, |
| 114 | messages |
| 115 | }: { |
| 116 | similarChunks: SimilarChunk[]; |
| 117 | messages: Message[]; |
| 118 | }) => { |
| 119 | if (similarChunks.length === 0) return ''; |
| 120 | |
| 121 | const memoryContext = similarChunks |
| 122 | .map(chunk => `${chunk.text} \n\n Source: ${chunk.attributes.docName}`) |
| 123 | .join('\n\n'); |
| 124 | |
| 125 | // Extract Rag prompt from the messages. |
| 126 | const ragMsg = messages.find(m => m.role === 'system' && m.name === 'rag'); |
| 127 | // If there is no rag prompt, use the default rag prompt. |
| 128 | const ragPrompt = ragMsg?.content || defaultRagPrompt; |
| 129 | |
| 130 | const contextContent = `"""CONTEXT:\n ${memoryContext}"""`; |
| 131 | const augmentedContext = `"""${ragPrompt}""" \n\n ${contextContent}`; |
| 132 | |
| 133 | return augmentedContext; |
| 134 | }; |
| 135 | |
| 136 | export const addContextFromMemory = async ({ |
| 137 | messages, |
nothing calls this directly
no outgoing calls
no test coverage detected