mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Add inferred queries to image chat responses in Obsidian client
This commit is contained in:
@@ -4,6 +4,8 @@ import { KhojSetting } from 'src/settings';
|
|||||||
export interface ChatJsonResult {
|
export interface ChatJsonResult {
|
||||||
image?: string;
|
image?: string;
|
||||||
detail?: string;
|
detail?: string;
|
||||||
|
intentType?: string;
|
||||||
|
inferredQueries?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -145,11 +147,17 @@ export class KhojChatModal extends Modal {
|
|||||||
return referenceButton;
|
return referenceButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderMessageWithReferences(chatEl: Element, message: string, sender: string, context?: string[], dt?: Date, intentType?: string) {
|
renderMessageWithReferences(chatEl: Element, message: string, sender: string, context?: string[], dt?: Date, intentType?: string, inferredQueries?: string) {
|
||||||
if (!message) {
|
if (!message) {
|
||||||
return;
|
return;
|
||||||
} else if (intentType === "text-to-image") {
|
} else if (intentType === "text-to-image") {
|
||||||
let imageMarkdown = ``;
|
let imageMarkdown = ``;
|
||||||
|
if (inferredQueries) {
|
||||||
|
imageMarkdown += "\n\n**Inferred Query**:";
|
||||||
|
for (let inferredQuery of inferredQueries) {
|
||||||
|
imageMarkdown += `\n\n${inferredQuery}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
this.renderMessage(chatEl, imageMarkdown, sender, dt);
|
this.renderMessage(chatEl, imageMarkdown, sender, dt);
|
||||||
return;
|
return;
|
||||||
} else if (!context) {
|
} else if (!context) {
|
||||||
@@ -287,7 +295,15 @@ export class KhojChatModal extends Modal {
|
|||||||
} else if (responseJson.response) {
|
} else if (responseJson.response) {
|
||||||
let chatLogs = responseJson.response?.conversation_id ? responseJson.response.chat ?? [] : responseJson.response;
|
let chatLogs = responseJson.response?.conversation_id ? responseJson.response.chat ?? [] : responseJson.response;
|
||||||
chatLogs.forEach((chatLog: any) => {
|
chatLogs.forEach((chatLog: any) => {
|
||||||
this.renderMessageWithReferences(chatBodyEl, chatLog.message, chatLog.by, chatLog.context, new Date(chatLog.created), chatLog.intent?.type);
|
this.renderMessageWithReferences(
|
||||||
|
chatBodyEl,
|
||||||
|
chatLog.message,
|
||||||
|
chatLog.by,
|
||||||
|
chatLog.context,
|
||||||
|
new Date(chatLog.created),
|
||||||
|
chatLog.intent?.type,
|
||||||
|
chatLog.intent?.["inferred-queries"],
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -404,6 +420,10 @@ export class KhojChatModal extends Modal {
|
|||||||
const responseAsJson = await response.json() as ChatJsonResult;
|
const responseAsJson = await response.json() as ChatJsonResult;
|
||||||
if (responseAsJson.image) {
|
if (responseAsJson.image) {
|
||||||
responseText = ``;
|
responseText = ``;
|
||||||
|
const inferredQuery = responseAsJson.inferredQueries?.[0];
|
||||||
|
if (inferredQuery) {
|
||||||
|
responseText += `\n\n**Inferred Query**:\n\n${inferredQuery}`;
|
||||||
|
}
|
||||||
} else if (responseAsJson.detail) {
|
} else if (responseAsJson.detail) {
|
||||||
responseText = responseAsJson.detail;
|
responseText = responseAsJson.detail;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user