From 64732f05aa5fcc4e9508f89856ae1e4cca930583 Mon Sep 17 00:00:00 2001
From: Huu Le <39040748+leehuwuj@users.noreply.github.com>
Date: Thu, 27 Jun 2024 22:14:15 +0700
Subject: [PATCH] Fix: remove sandbox link from openai models (#145)

---
 .changeset/quick-socks-learn.md                     |  5 +++++
 .../components/ui/chat/chat-message/markdown.tsx    | 13 ++++++++++++-
 2 files changed, 17 insertions(+), 1 deletion(-)
 create mode 100644 .changeset/quick-socks-learn.md

diff --git a/.changeset/quick-socks-learn.md b/.changeset/quick-socks-learn.md
new file mode 100644
index 00000000..092d81c7
--- /dev/null
+++ b/.changeset/quick-socks-learn.md
@@ -0,0 +1,5 @@
+---
+"create-llama": patch
+---
+
+Fix the issue of images not showing with the sandbox URL from OpenAI's models
diff --git a/templates/types/streaming/nextjs/app/components/ui/chat/chat-message/markdown.tsx b/templates/types/streaming/nextjs/app/components/ui/chat/chat-message/markdown.tsx
index 54a17389..79791b46 100644
--- a/templates/types/streaming/nextjs/app/components/ui/chat/chat-message/markdown.tsx
+++ b/templates/types/streaming/nextjs/app/components/ui/chat/chat-message/markdown.tsx
@@ -28,8 +28,19 @@ const preprocessLaTeX = (content: string) => {
   return inlineProcessedContent;
 };
 
+const preprocessMedia = (content: string) => {
+  // Remove `sandbox:` from the beginning of the URL
+  // to fix OpenAI's models issue appending `sandbox:` to the relative URL
+  return content.replace(/(sandbox|attachment|snt):/g, "");
+};
+
+const preprocessContent = (content: string) => {
+  return preprocessMedia(preprocessLaTeX(content));
+};
+
 export default function Markdown({ content }: { content: string }) {
-  const processedContent = preprocessLaTeX(content);
+  const processedContent = preprocessContent(content);
+
   return (
     <MemoizedReactMarkdown
       className="prose dark:prose-invert prose-p:leading-relaxed prose-pre:p-0 break-words custom-markdown"
-- 
GitLab