Do not replace inline HTML img with image embed (#4063)
Signed| @@ -3566,7 +3566,7 @@ class StreamingProcessor { | ||
| 3566 | 3566 | } |
| 3567 | 3567 | |
| 3568 | 3568 | if (this.image) { |
| 3569 | 3569 | await processImageAttachment(chat[messageId], { imageUrl: this.image, parsedImage: null }); |
| 3570 | 3570 | appendMediaToMessage(chat[messageId], $(this.messageDom)); |
| 3571 | 3571 | } |
| 3572 | 3572 | |
| @@ -6309,17 +6309,11 @@ export function cleanUpMessage({ getMessage, isImpersonate, isContinue, displayI | ||
| 6309 | 6309 | * Adds an image to the message. |
| 6310 | 6310 | * @param {object} message Message object |
| 6311 | 6311 | * @param {object} sources Image sources |
| 6312 | - * @param {ParsedImage} [sources.parsedImage] Parsed image | |
| 6313 | 6312 | * @param {string} [sources.imageUrl] Image URL |
| 6314 | 6313 | * |
| 6315 | 6314 | * @returns {Promise<void>} |
| 6316 | 6315 | */ |
| 6317 | 6316 | async function processImageAttachment(message, { parsedImage, imageUrl }) { |
| 6318 | - if (parsedImage?.image) { | |
| 6319 | - saveImageToMessage(parsedImage, message); | |
| 6320 | - return; | |
| 6321 | - } | |
| 6322 | - | |
| 6323 | 6317 | if (!imageUrl) { |
| 6324 | 6318 | return; |
| 6325 | 6319 | } |
| @@ -6378,8 +6372,6 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title | ||
| 6378 | 6372 | |
| 6379 | 6373 | let oldMessage = ''; |
| 6380 | 6374 | const generationFinished = new Date(); |
| 6381 | - const parsedImage = extractImageFromMessage(getMessage); | |
| 6382 | - getMessage = parsedImage.getMessage; | |
| 6383 | 6375 | if (type === 'swipe') { |
| 6384 | 6376 | oldMessage = chat[chat.length - 1]['mes']; |
| 6385 | 6377 | chat[chat.length - 1]['swipes'].length++; |
| @@ -6393,7 +6385,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title | ||
| 6393 | 6385 | chat[chat.length - 1]['extra']['model'] = getGeneratingModel(); |
| 6394 | 6386 | chat[chat.length - 1]['extra']['reasoning'] = reasoning; |
| 6395 | 6387 | chat[chat.length - 1]['extra']['reasoning_duration'] = null; |
| 6396 | 6388 | await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl }); |
| 6397 | 6389 | if (power_user.message_token_count_enabled) { |
| 6398 | 6390 | const tokenCountText = (reasoning || '') + chat[chat.length - 1]['mes']; |
| 6399 | 6391 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); |
| @@ -6417,7 +6409,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title | ||
| 6417 | 6409 | chat[chat.length - 1]['extra']['model'] = getGeneratingModel(); |
| 6418 | 6410 | chat[chat.length - 1]['extra']['reasoning'] = reasoning; |
| 6419 | 6411 | chat[chat.length - 1]['extra']['reasoning_duration'] = null; |
| 6420 | 6412 | await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl }); |
| 6421 | 6413 | if (power_user.message_token_count_enabled) { |
| 6422 | 6414 | const tokenCountText = (reasoning || '') + chat[chat.length - 1]['mes']; |
| 6423 | 6415 | chat[chat.length - 1]['extra']['token_count'] = await getTokenCountAsync(tokenCountText, 0); |
| @@ -6437,7 +6429,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title | ||
| 6437 | 6429 | chat[chat.length - 1]['extra']['api'] = getGeneratingApi(); |
| 6438 | 6430 | chat[chat.length - 1]['extra']['model'] = getGeneratingModel(); |
| 6439 | 6431 | chat[chat.length - 1]['extra']['reasoning'] += reasoning; |
| 6440 | 6432 | await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl }); |
| 6441 | 6433 | // We don't know if the reasoning duration extended, so we don't update it here on purpose. |
| 6442 | 6434 | if (power_user.message_token_count_enabled) { |
| 6443 | 6435 | const tokenCountText = (reasoning || '') + chat[chat.length - 1]['mes']; |
| @@ -6483,7 +6475,7 @@ export async function saveReply({ type, getMessage, fromStreaming = false, title | ||
| 6483 | 6475 | chat[chat.length - 1]['extra']['gen_id'] = group_generation_id; |
| 6484 | 6476 | } |
| 6485 | 6477 | |
| 6486 | 6478 | await processImageAttachment(chat[chat.length - 1], { parsedImage, imageUrl: imageUrl }); |
| 6487 | 6479 | const chat_id = (chat.length - 1); |
| 6488 | 6480 | |
| 6489 | 6481 | !fromStreaming && await eventSource.emit(event_types.MESSAGE_RECEIVED, chat_id, type); |
| @@ -6700,15 +6692,6 @@ function getGeneratingModel(mes) { | ||
| 6700 | 6692 | return model; |
| 6701 | 6693 | } |
| 6702 | 6694 | |
| 6703 | -function extractImageFromMessage(getMessage) { | |
| 6704 | - const regex = /<img src="(.*?)".*?alt="(.*?)".*?>/g; | |
| 6705 | - const results = regex.exec(getMessage); | |
| 6706 | - const image = results ? results[1] : ''; | |
| 6707 | - const title = results ? results[2] : ''; | |
| 6708 | - getMessage = getMessage.replace(regex, ''); | |
| 6709 | - return { getMessage, image, title, inline: true }; | |
| 6710 | -} | |
| 6711 | - | |
| 6712 | 6695 | /** |
| 6713 | 6696 | * A function mainly used to switch 'generating' state - setting it to false and activating the buttons again |
| 6714 | 6697 | */ |