mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-09 05:39:12 +00:00
Show online references used to generate response in Obsidian chat view
This commit is contained in:
@@ -324,6 +324,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
message: string,
|
message: string,
|
||||||
sender: string,
|
sender: string,
|
||||||
context?: string[],
|
context?: string[],
|
||||||
|
onlineContext?: object,
|
||||||
dt?: Date,
|
dt?: Date,
|
||||||
intentType?: string,
|
intentType?: string,
|
||||||
inferredQueries?: string[],
|
inferredQueries?: string[],
|
||||||
@@ -339,13 +340,15 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If no document or online context is provided, skip rendering the reference section
|
// If no document or online context is provided, skip rendering the reference section
|
||||||
if (context == null || context.length == 0) {
|
if ((context == null || context.length == 0)
|
||||||
|
&& (onlineContext == null || (onlineContext && Object.keys(onlineContext).length == 0))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If document or online context is provided, render the message with its references
|
// If document or online context is provided, render the message with its references
|
||||||
let references: any = {};
|
let references: any = {};
|
||||||
if (!!context) references["notes"] = context;
|
if (!!context) references["notes"] = context;
|
||||||
|
if (!!onlineContext) references["online"] = onlineContext;
|
||||||
let chatMessageBodyEl = chatMessageEl.getElementsByClassName("khoj-chat-message-text")[0];
|
let chatMessageBodyEl = chatMessageEl.getElementsByClassName("khoj-chat-message-text")[0];
|
||||||
chatMessageBodyEl.appendChild(this.createReferenceSection(references));
|
chatMessageBodyEl.appendChild(this.createReferenceSection(references));
|
||||||
}
|
}
|
||||||
@@ -493,6 +496,7 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
chatLog.message,
|
chatLog.message,
|
||||||
chatLog.by,
|
chatLog.by,
|
||||||
chatLog.context,
|
chatLog.context,
|
||||||
|
chatLog.onlineContext,
|
||||||
new Date(chatLog.created),
|
new Date(chatLog.created),
|
||||||
chatLog.intent?.type,
|
chatLog.intent?.type,
|
||||||
chatLog.intent?.["inferred-queries"],
|
chatLog.intent?.["inferred-queries"],
|
||||||
@@ -887,6 +891,8 @@ export class KhojChatView extends KhojPaneView {
|
|||||||
let references: any = {};
|
let references: any = {};
|
||||||
if (rawReferenceAsJson instanceof Array) {
|
if (rawReferenceAsJson instanceof Array) {
|
||||||
references["notes"] = rawReferenceAsJson;
|
references["notes"] = rawReferenceAsJson;
|
||||||
|
} else if (typeof rawReferenceAsJson === "object" && rawReferenceAsJson !== null) {
|
||||||
|
references["online"] = rawReferenceAsJson;
|
||||||
}
|
}
|
||||||
return references;
|
return references;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user