Easonwangzk commited on
Commit
290da9f
·
1 Parent(s): 57a2f48

Fix image path in LLM answers

Browse files
Files changed (1) hide show
  1. frontend/main.js +8 -1
frontend/main.js CHANGED
@@ -266,7 +266,14 @@ class MultimodalAssistant {
266
  // Pattern: ![alt text](image_url)
267
  formattedContent = formattedContent.replace(
268
  /!\[(.*?)\]\((.*?)\)/g,
269
- '<br><img src="$2" alt="$1" class="max-w-md rounded-lg shadow-md my-4" /><br>'
 
 
 
 
 
 
 
270
  );
271
 
272
  if (answerContent) answerContent.innerHTML = formattedContent;
 
266
  // Pattern: ![alt text](image_url)
267
  formattedContent = formattedContent.replace(
268
  /!\[(.*?)\]\((.*?)\)/g,
269
+ (match, alt, url) => {
270
+ // 如果是 images/ 开头的路径,转换为 /product_images/
271
+ let correctedUrl = url;
272
+ if (url.startsWith('images/')) {
273
+ correctedUrl = url.replace('images/', '/product_images/');
274
+ }
275
+ return `<br><img src="${correctedUrl}" alt="${alt}" class="max-w-md rounded-lg shadow-md my-4" onerror="this.src='https://via.placeholder.com/300?text=Image+Not+Found'" /><br>`;
276
+ }
277
  );
278
 
279
  if (answerContent) answerContent.innerHTML = formattedContent;