diff --git a/src/components/remark-content.tsx b/src/components/remark-content.tsx index 83274c53..7d423e7b 100644 --- a/src/components/remark-content.tsx +++ b/src/components/remark-content.tsx @@ -30,19 +30,33 @@ const production: RehypeReactOptions = { return ( { if (open) { - const a = document.querySelector(`${props.href} a:first-child`) as HTMLAnchorElement | null; - if (a) { - setLink({ title: a.textContent ?? a.href, href: a.href }); - } else { - setLink(undefined); + const id = props.href?.replace(/^#/, ''); + if (id) { + const li = document.getElementById(id); + if (li) { + const a = li.querySelector(`a:first-child`) as HTMLAnchorElement | null; + if (a) { + setLink({ title: a.textContent ?? a.href, href: a.href }); + return; + } + } } + setLink(undefined); } }}> - + { + event.preventDefault(); + event.stopPropagation(); + }} + /> - + e.preventDefault()} className="p-1 w-[200px] overflow-hidden rounded-lg border text-xs"> diff --git a/src/core/services/llamaindex/chating.ts b/src/core/services/llamaindex/chating.ts index 7d3bb076..940d69e3 100644 --- a/src/core/services/llamaindex/chating.ts +++ b/src/core/services/llamaindex/chating.ts @@ -279,10 +279,19 @@ export class LlamaindexChatService extends AppChatService { trace, )); + const promptContext = { + ...kgContext, + sources: Array.from(allSources.values()).map((source, index) => ({ + ordinal: index + 1, + ...source + })), + originalQuestion: options.userInput, + } + // Build Query Engine. const { textQa, refine } = prompts; - const textQaPrompt = this.getPrompt(textQa, defaultTextQaPrompt, kgContext); - const refinePrompt = this.getPrompt(refine, defaultRefinePrompt, kgContext); + const textQaPrompt = this.getPrompt(textQa, defaultTextQaPrompt, promptContext); + const refinePrompt = this.getPrompt(refine, defaultRefinePrompt, promptContext); const responseBuilder = new CompactAndRefine(serviceContext, textQaPrompt, refinePrompt); const responseSynthesizer = new ResponseSynthesizer({ serviceContext, @@ -297,7 +306,7 @@ export class LlamaindexChatService extends AppChatService { content: message.content, additionalKwargs: {}, })); - const condenseMessagePrompt = this.getPrompt(prompts?.condenseQuestion, defaultCondenseQuestionPrompt, kgContext); + const condenseMessagePrompt = this.getPrompt(prompts?.condenseQuestion, defaultCondenseQuestionPrompt, promptContext); const chatEngine = new CondenseQuestionChatEngine({ serviceContext, queryEngine,