mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-03 21:29:08 +00:00
Use base64 encoded image instead of source URL for persistence
The source URL returned by OpenAI would expire soon. This would make the chat sessions contain non-accessible images/messages if using OpenaI image URL Get base64 encoded image from OpenAI and store directly in conversation logs. This resolves the image link expiring issue
This commit is contained in:
@@ -181,7 +181,7 @@
|
||||
|
||||
function renderMessageWithReference(message, by, context=null, dt=null, onlineContext=null, intentType=null) {
|
||||
if (intentType === "text-to-image") {
|
||||
let imageMarkdown = ``;
|
||||
let imageMarkdown = ``;
|
||||
renderMessage(imageMarkdown, by, dt);
|
||||
return;
|
||||
}
|
||||
@@ -254,20 +254,11 @@
|
||||
md.renderer.rules.image = function(tokens, idx, options, env, self) {
|
||||
let token = tokens[idx];
|
||||
|
||||
// Get image source url. Only render images with src links
|
||||
let srcIndex = token.attrIndex('src');
|
||||
if (srcIndex < 0) { return ''; }
|
||||
let src = token.attrs[srcIndex][1];
|
||||
|
||||
// Wrap the image in a link
|
||||
var aStart = `<a href="${src}" target="_blank">`;
|
||||
var aEnd = '</a>';
|
||||
|
||||
// Add class="text-to-image" to images
|
||||
token.attrPush(['class', 'text-to-image']);
|
||||
|
||||
// Use the default renderer to render image markdown format
|
||||
return aStart + self.renderToken(tokens, idx, options) + aEnd;
|
||||
return self.renderToken(tokens, idx, options);
|
||||
};
|
||||
|
||||
// Render markdown
|
||||
@@ -435,8 +426,8 @@
|
||||
if (chunk.startsWith("{") && chunk.endsWith("}")) {
|
||||
try {
|
||||
const responseAsJson = JSON.parse(chunk);
|
||||
if (responseAsJson.imageUrl) {
|
||||
rawResponse += ``;
|
||||
if (responseAsJson.image) {
|
||||
rawResponse += ``;
|
||||
}
|
||||
if (responseAsJson.detail) {
|
||||
rawResponse += responseAsJson.detail;
|
||||
|
||||
Reference in New Issue
Block a user