From dc4e6f5de7270f38659c67cba0d8bcd1fcb0fb21 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sun, 28 Jul 2024 05:12:08 +0800 Subject: [PATCH 01/28] Update chat.ts --- src/types/chat.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/types/chat.ts b/src/types/chat.ts index 5b706952a..a57cc5732 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -50,6 +50,8 @@ export interface Folder { } export type ModelOptions = + | 'gpt-4o-mini' + | 'gpt-4o-mini-2024-07-18' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4' From f5a5a6a483fc041737d76484319fd1bb4339765a Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sun, 28 Jul 2024 05:22:00 +0800 Subject: [PATCH 02/28] Update chat.ts --- src/constants/chat.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/constants/chat.ts b/src/constants/chat.ts index f806ef1b6..192771c22 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -30,6 +30,8 @@ export const modelOptions: ModelOptions[] = [ 'gpt-4-turbo-2024-04-09', 'gpt-4o', 'gpt-4o-2024-05-13', + 'gpt-4o-mini', + 'gpt-4o-mini-2024-07-18', // 'gpt-3.5-turbo-0301', // 'gpt-4-0314', // 'gpt-4-32k-0314', @@ -57,6 +59,8 @@ export const modelMaxToken = { 'gpt-4-turbo-2024-04-09': 128000, 'gpt-4o': 128000, 'gpt-4o-2024-05-13': 128000, + 'gpt-4o-mini': 128000, + 'gpt-4o-mini-2024-07-18': 128000, }; export const modelCost = { @@ -136,6 +140,14 @@ export const modelCost = { prompt: { price: 0.005, unit: 1000 }, completion: { price: 0.015, unit: 1000 }, }, + 'gpt-4o-mini': { + prompt: { price: 0.00015, unit: 1000 }, + completion: { price: 0.00060, unit: 1000 }, + }, + 'gpt-4o-mini-2024-07-18': { + prompt: { price: 0.00015, unit: 1000 }, + completion: { price: 0.00060, unit: 1000 }, + }, }; export const defaultUserMaxToken = 4000; From a2246e48751112388acd37f67aa6b69b549498b3 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Mon, 5 Aug 2024 15:25:12 +0800 Subject: [PATCH 03/28] Update chat.ts Modify the model used for generating titles and the default model to 'gpt-4o-mini', and remove the extra space at the end of the second line in the default system prompt. --- src/constants/chat.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 192771c22..c0da9e78e 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -14,7 +14,7 @@ const dateString = export const _defaultSystemMessage = import.meta.env.VITE_DEFAULT_SYSTEM_MESSAGE ?? `You are ChatGPT, a large language model trained by OpenAI. -Carefully heed the user's instructions. +Carefully heed the user's instructions. Respond using Markdown.`; export const modelOptions: ModelOptions[] = [ @@ -37,7 +37,7 @@ export const modelOptions: ModelOptions[] = [ // 'gpt-4-32k-0314', ]; -export const defaultModel = 'gpt-3.5-turbo'; +export const defaultModel = 'gpt-4o-mini'; export const modelMaxToken = { 'gpt-3.5-turbo': 4096, From c73afd1b9d39f69a2243e7f9c1a39a1203779159 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Wed, 7 Aug 2024 06:24:10 +0800 Subject: [PATCH 04/28] Update chat.ts Add "gpt-4o-2024-08-06" --- src/constants/chat.ts | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/src/constants/chat.ts b/src/constants/chat.ts index c0da9e78e..53fce7e65 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -28,10 +28,11 @@ export const modelOptions: ModelOptions[] = [ 'gpt-4-0125-preview', 'gpt-4-turbo', 'gpt-4-turbo-2024-04-09', - 'gpt-4o', - 'gpt-4o-2024-05-13', 'gpt-4o-mini', 'gpt-4o-mini-2024-07-18', + 'gpt-4o', + 'gpt-4o-2024-05-13', + 'gpt-4o-2024-08-06', // 'gpt-3.5-turbo-0301', // 'gpt-4-0314', // 'gpt-4-32k-0314', @@ -57,10 +58,11 @@ export const modelMaxToken = { 'gpt-4-0125-preview': 128000, 'gpt-4-turbo': 128000, 'gpt-4-turbo-2024-04-09': 128000, - 'gpt-4o': 128000, - 'gpt-4o-2024-05-13': 128000, 'gpt-4o-mini': 128000, 'gpt-4o-mini-2024-07-18': 128000, + 'gpt-4o': 128000, + 'gpt-4o-2024-05-13': 128000, + 'gpt-4o-2024-08-06': 128000, }; export const modelCost = { @@ -132,6 +134,14 @@ export const modelCost = { prompt: { price: 0.01, unit: 1000 }, completion: { price: 0.03, unit: 1000 }, }, + 'gpt-4o-mini': { + prompt: { price: 0.00015, unit: 1000 }, + completion: { price: 0.00060, unit: 1000 }, + }, + 'gpt-4o-mini-2024-07-18': { + prompt: { price: 0.00015, unit: 1000 }, + completion: { price: 0.00060, unit: 1000 }, + }, 'gpt-4o': { prompt: { price: 0.005, unit: 1000 }, completion: { price: 0.015, unit: 1000 }, @@ -140,13 +150,9 @@ export const modelCost = { prompt: { price: 0.005, unit: 1000 }, completion: { price: 0.015, unit: 1000 }, }, - 'gpt-4o-mini': { - prompt: { price: 0.00015, unit: 1000 }, - completion: { price: 0.00060, unit: 1000 }, - }, - 'gpt-4o-mini-2024-07-18': { - prompt: { price: 0.00015, unit: 1000 }, - completion: { price: 0.00060, unit: 1000 }, + 'gpt-4o-2024-08-06': { + prompt: { price: 0.0025, unit: 1000 }, + completion: { price: 0.010, unit: 1000 }, }, }; From bff7ee37ab2d89d83ed5e82d14770e6c47b33a01 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Wed, 7 Aug 2024 06:24:58 +0800 Subject: [PATCH 05/28] Update chat.ts Add "gpt-4o-2024-08-06" --- src/types/chat.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/chat.ts b/src/types/chat.ts index a57cc5732..1a8945c23 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -54,6 +54,7 @@ export type ModelOptions = | 'gpt-4o-mini-2024-07-18' | 'gpt-4o' | 'gpt-4o-2024-05-13' + | 'gpt-4o-2024-08-06' | 'gpt-4' | 'gpt-4-32k' | 'gpt-4-1106-preview' From 486131cd1d6383b268d25b7a8a9bcaec65637cda Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Wed, 7 Aug 2024 11:59:27 +0800 Subject: [PATCH 06/28] Update chat.ts --- src/constants/chat.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 53fce7e65..8f92983b8 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -136,11 +136,11 @@ export const modelCost = { }, 'gpt-4o-mini': { prompt: { price: 0.00015, unit: 1000 }, - completion: { price: 0.00060, unit: 1000 }, + completion: { price: 0.0006, unit: 1000 }, }, 'gpt-4o-mini-2024-07-18': { prompt: { price: 0.00015, unit: 1000 }, - completion: { price: 0.00060, unit: 1000 }, + completion: { price: 0.0006, unit: 1000 }, }, 'gpt-4o': { prompt: { price: 0.005, unit: 1000 }, @@ -152,7 +152,7 @@ export const modelCost = { }, 'gpt-4o-2024-08-06': { prompt: { price: 0.0025, unit: 1000 }, - completion: { price: 0.010, unit: 1000 }, + completion: { price: 0.01, unit: 1000 }, }, }; From 3c3db0c7d0f312b50dd03751eab6896bd0eb3f04 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Wed, 7 Aug 2024 23:43:36 +0800 Subject: [PATCH 07/28] Update DownloadChat.tsx Optimize the functionality for downloading chat record images. --- .../Chat/ChatContent/DownloadChat.tsx | 177 ++++++++++-------- 1 file changed, 96 insertions(+), 81 deletions(-) diff --git a/src/components/Chat/ChatContent/DownloadChat.tsx b/src/components/Chat/ChatContent/DownloadChat.tsx index 98243462c..61bad422e 100644 --- a/src/components/Chat/ChatContent/DownloadChat.tsx +++ b/src/components/Chat/ChatContent/DownloadChat.tsx @@ -20,6 +20,32 @@ const DownloadChat = React.memo( ({ saveRef }: { saveRef: React.RefObject }) => { const { t } = useTranslation(); const [isModalOpen, setIsModalOpen] = useState(false); + const [isGenerating, setIsGenerating] = useState(false); + + const handleImageDownload = () => { + const currentRef = saveRef?.current; + if (currentRef) { + setIsGenerating(true); + requestAnimationFrame(async () => { + try { + currentRef.offsetHeight; + const imgData = await htmlToImg(currentRef); + await downloadImg( + imgData, + `${ + useStore + .getState() + .chats?.[useStore.getState().currentChatIndex].title.trim() ?? + 'download' + }.png` + ); + } finally { + setIsGenerating(false); + } + }); + } + }; + return ( <> - {/* */} - + {/* - + }} + > + + PDF + */} + + + )} From 7d92fea1aedc436c33e1546de0b8e58a1d6767ef Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Wed, 7 Aug 2024 23:44:31 +0800 Subject: [PATCH 08/28] Update chat.ts Optimize the functionality for downloading chat record images. --- src/utils/chat.ts | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index 8c0672643..86ff9aea6 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -8,21 +8,55 @@ export const htmlToImg = async (html: HTMLDivElement) => { if (needResize) { html.style.width = '1023px'; } - const canvas = await html2canvas(html); + await Promise.all( + Array.from(html.querySelectorAll('img')) + 。filter(img => !img.complete) + 。map(img => new Promise(resolve => { img.onload = img.onerror = resolve; })) + ); + const canvas = await html2canvas(html, { + useCORS: true, + }); if (needResize) html.style.width = initialWidth; - const dataURL = canvas.toDataURL('image/png'); + const croppedCanvas = document.createElement('canvas'); + const ctx = croppedCanvas.getContext('2d'); + if (ctx) { + const cropHeight = 3; + const cropWidth = 3; + croppedCanvas.width = canvas.width - cropWidth; + croppedCanvas.height = canvas.height - cropHeight; + ctx.drawImage( + canvas, + 0, 0, + canvas.width - cropWidth, canvas.height - cropHeight, + 0, 0, + canvas.width - cropWidth, canvas.height - cropHeight + ); + } + const dataURL = croppedCanvas.toDataURL('image/png'); return dataURL; }; // Function to download the image as a file export const downloadImg = (imgData: string, fileName: string) => { + const byteString = atob(imgData.split(',')[1]); + const mimeString = imgData.split(',')[0].split(':')[1].split(';')[0]; + const ab = new ArrayBuffer(byteString.length); + const ia = new Uint8Array(ab); + for (let i = 0; i < byteString.length; i++) { + ia[i] = byteString.charCodeAt(i); + } + const blob = new Blob([ab], {type: mimeString}); + const url = URL.createObjectURL(blob); const link = document.createElement('a'); - link.href = imgData; + link.href = url; link.download = fileName; + document.body.appendChild(link); link.click(); - link.remove(); + document.body.removeChild(link); + URL.revokeObjectURL(url); }; + // Function to convert a chat object to markdown format export const chatToMarkdown = (chat: ChatInterface) => { let markdown = `# ${chat.title}\n\n`; @@ -38,6 +72,7 @@ export const downloadMarkdown = (markdown: string, fileName: string) => { const markdownFile = new Blob([markdown], { type: 'text/markdown' }); link.href = URL.createObjectURL(markdownFile); link.download = fileName; + document.body.appendChild(link); link.click(); - link.remove(); + document.body.removeChild(link); }; From f7e3e8de26ea46c147ad52fed0a3451850266936 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Wed, 14 Aug 2024 18:24:23 +0800 Subject: [PATCH 09/28] Update chat.ts ADD chatgpt-4o-latest --- src/types/chat.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/chat.ts b/src/types/chat.ts index 1a8945c23..dd37d51fe 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -55,6 +55,7 @@ export type ModelOptions = | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' + | 'chatgpt-4o-latest' | 'gpt-4' | 'gpt-4-32k' | 'gpt-4-1106-preview' From 99ffcd4cf8fcaadee600d99c3ed8b6d6a2189b33 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Wed, 14 Aug 2024 18:26:44 +0800 Subject: [PATCH 10/28] Update chat.ts Add chatgpt-4o-latest --- src/constants/chat.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 8f92983b8..552e08f40 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -33,6 +33,7 @@ export const modelOptions: ModelOptions[] = [ 'gpt-4o', 'gpt-4o-2024-05-13', 'gpt-4o-2024-08-06', + 'chatgpt-4o-latest', // 'gpt-3.5-turbo-0301', // 'gpt-4-0314', // 'gpt-4-32k-0314', @@ -63,6 +64,7 @@ export const modelMaxToken = { 'gpt-4o': 128000, 'gpt-4o-2024-05-13': 128000, 'gpt-4o-2024-08-06': 128000, + 'chatgpt-4o-latest': 128000, }; export const modelCost = { @@ -154,6 +156,10 @@ export const modelCost = { prompt: { price: 0.0025, unit: 1000 }, completion: { price: 0.01, unit: 1000 }, }, + 'chatgpt-4o-latest': { + prompt: { price: 0.0025, unit: 1000 }, + completion: { price: 0.01, unit: 1000 }, + }, }; export const defaultUserMaxToken = 4000; From 955f1d30436178e4be0fa4e7c05e878a14feb77e Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 13 Sep 2024 09:14:34 +0800 Subject: [PATCH 11/28] Update chat.ts Add 'o1-mini' 'o1-mini-2024-09-12' 'o1-preview' 'o1-preview-2024-09-12' --- src/types/chat.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/types/chat.ts b/src/types/chat.ts index dd37d51fe..fa2856e9a 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -56,6 +56,10 @@ export type ModelOptions = | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'chatgpt-4o-latest' + | 'o1-mini' + | 'o1-mini-2024-09-12' + | 'o1-preview' + | 'o1-preview-2024-09-12' | 'gpt-4' | 'gpt-4-32k' | 'gpt-4-1106-preview' From e0a1590ff67318f23733a1d49ae6c043d9e4825e Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 13 Sep 2024 09:21:51 +0800 Subject: [PATCH 12/28] Update chat.ts Add 'o1-mini' 'o1-mini-2024-09-12' 'o1-preview' 'o1-preview-2024-09-12' --- src/constants/chat.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 552e08f40..39d8e3ba2 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -34,6 +34,10 @@ export const modelOptions: ModelOptions[] = [ 'gpt-4o-2024-05-13', 'gpt-4o-2024-08-06', 'chatgpt-4o-latest', + 'o1-mini', + 'o1-mini-2024-09-12', + 'o1-preview', + 'o1-preview-2024-09-12', // 'gpt-3.5-turbo-0301', // 'gpt-4-0314', // 'gpt-4-32k-0314', @@ -65,6 +69,10 @@ export const modelMaxToken = { 'gpt-4o-2024-05-13': 128000, 'gpt-4o-2024-08-06': 128000, 'chatgpt-4o-latest': 128000, + 'o1-mini': 128000, + 'o1-mini-2024-09-12': 128000, + 'o1-preview': 128000, + 'o1-preview-2024-09-12': 128000, }; export const modelCost = { @@ -160,6 +168,22 @@ export const modelCost = { prompt: { price: 0.0025, unit: 1000 }, completion: { price: 0.01, unit: 1000 }, }, + 'o1-mini': { + prompt: { price: 0.003, unit: 1000 }, + completion: { price: 0.012, unit: 1000 }, + }, + 'o1-mini-2024-09-12': { + prompt: { price: 0.003, unit: 1000 }, + completion: { price: 0.012, unit: 1000 }, + }, + 'o1-preview': { + prompt: { price: 0.015, unit: 1000 }, + completion: { price: 0.06, unit: 1000 }, + }, + 'o1-preview-2024-09-12': { + prompt: { price: 0.015, unit: 1000 }, + completion: { price: 0.06, unit: 1000 }, + }, }; export const defaultUserMaxToken = 4000; From 10c6c1d0675b208914df04b817b49c0d35674671 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 18 Oct 2024 22:04:11 +0800 Subject: [PATCH 13/28] Update chat.ts --- src/utils/chat.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index 86ff9aea6..b3b456332 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -39,20 +39,27 @@ export const htmlToImg = async (html: HTMLDivElement) => { // Function to download the image as a file export const downloadImg = (imgData: string, fileName: string) => { const byteString = atob(imgData.split(',')[1]); - const mimeString = imgData.split(',')[0].split(':')[1].split(';')[0]; + const mimeString = 'image/png'; const ab = new ArrayBuffer(byteString.length); const ia = new Uint8Array(ab); + for (let i = 0; i < byteString.length; i++) { ia[i] = byteString.charCodeAt(i); } - const blob = new Blob([ab], {type: mimeString}); + + const blob = new Blob([ab], { type: mimeString }); + const url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; + + fileName = fileName.endsWith('.png') ? fileName : `${fileName}.png`; link.download = fileName; + document.body.appendChild(link); link.click(); document.body.removeChild(link); + URL.revokeObjectURL(url); }; From afbc303e5ef9c902203e2c5c2235503bc822ad3b Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 18 Oct 2024 22:11:48 +0800 Subject: [PATCH 14/28] Update chat.ts --- src/utils/chat.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index b3b456332..b5a968344 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -57,7 +57,8 @@ export const downloadImg = (imgData: string, fileName: string) => { link.download = fileName; document.body.appendChild(link); - link.click(); + const event = new MouseEvent('click'); + link.dispatchEvent(event); document.body.removeChild(link); URL.revokeObjectURL(url); From a17ded915897f5fe45e0ff6acde1dc548c41c128 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 18 Oct 2024 22:14:06 +0800 Subject: [PATCH 15/28] Update chat.ts --- src/utils/chat.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index b5a968344..617e6c436 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -15,6 +15,7 @@ export const htmlToImg = async (html: HTMLDivElement) => { ); const canvas = await html2canvas(html, { useCORS: true, + allowTaint: true, }); if (needResize) html.style.width = initialWidth; const croppedCanvas = document.createElement('canvas'); From a6c1a9a0848cb438a824459b669a012f58d4e99a Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 18 Oct 2024 22:23:37 +0800 Subject: [PATCH 16/28] Update chat.ts --- src/utils/chat.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index 617e6c436..05b15000b 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -10,8 +10,8 @@ export const htmlToImg = async (html: HTMLDivElement) => { } await Promise.all( Array.from(html.querySelectorAll('img')) - 。filter(img => !img.complete) - 。map(img => new Promise(resolve => { img.onload = img.onerror = resolve; })) + .filter(img => !img.complete) + .map(img => new Promise(resolve => { img.onload = img.onerror = resolve; })) ); const canvas = await html2canvas(html, { useCORS: true, @@ -32,9 +32,12 @@ export const htmlToImg = async (html: HTMLDivElement) => { 0, 0, canvas.width - cropWidth, canvas.height - cropHeight ); - } const dataURL = croppedCanvas.toDataURL('image/png'); return dataURL; + } else { + const dataURL = canvas.toDataURL('image/png'); + return dataURL; + } }; // Function to download the image as a file From 6031bdc121945d3a33d20d2fdf5595b7f45c33ee Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 18 Oct 2024 22:48:50 +0800 Subject: [PATCH 17/28] Update chat.ts --- src/utils/chat.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index 05b15000b..ce3f85598 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -15,7 +15,6 @@ export const htmlToImg = async (html: HTMLDivElement) => { ); const canvas = await html2canvas(html, { useCORS: true, - allowTaint: true, }); if (needResize) html.style.width = initialWidth; const croppedCanvas = document.createElement('canvas'); From 5879bf7df7193eb6bd0c0f74ae59db9dbcd7ac4f Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 18 Oct 2024 23:05:49 +0800 Subject: [PATCH 18/28] Update chat.ts --- src/utils/chat.ts | 48 +++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index ce3f85598..698b05de4 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -52,22 +52,26 @@ export const downloadImg = (imgData: string, fileName: string) => { const blob = new Blob([ab], { type: mimeString }); - const url = URL.createObjectURL(blob); - const link = document.createElement('a'); - link.href = url; + if (window.navigator && window.navigator.msSaveOrOpenBlob) { + fileName = fileName.endsWith('.png') ? fileName : `${fileName}.png`; + window.navigator.msSaveOrOpenBlob(blob, fileName); + } else { + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; - fileName = fileName.endsWith('.png') ? fileName : `${fileName}.png`; - link.download = fileName; + fileName = fileName.endsWith('.png') ? fileName : `${fileName}.png`; + link.download = fileName; - document.body.appendChild(link); - const event = new MouseEvent('click'); - link.dispatchEvent(event); - document.body.removeChild(link); + document.body.appendChild(link); + const event = new MouseEvent('click'); + link.dispatchEvent(event); + document.body.removeChild(link); - URL.revokeObjectURL(url); + URL.revokeObjectURL(url); + } }; - // Function to convert a chat object to markdown format export const chatToMarkdown = (chat: ChatInterface) => { let markdown = `# ${chat.title}\n\n`; @@ -79,11 +83,19 @@ export const chatToMarkdown = (chat: ChatInterface) => { // Function to download the markdown content as a file export const downloadMarkdown = (markdown: string, fileName: string) => { - const link = document.createElement('a'); - const markdownFile = new Blob([markdown], { type: 'text/markdown' }); - link.href = URL.createObjectURL(markdownFile); - link.download = fileName; - document.body.appendChild(link); - link.click(); - document.body.removeChild(link); + const markdownFile = new Blob([markdown], { type: 'text/markdown;charset=utf-8' }); + + if (window.navigator && window.navigator.msSaveOrOpenBlob) { + fileName = fileName.endsWith('.md') ? fileName : `${fileName}.md`; + window.navigator.msSaveOrOpenBlob(markdownFile, fileName); + } else { + const link = document.createElement('a'); + link.href = URL.createObjectURL(markdownFile); + fileName = fileName.endsWith('.md') ? fileName : `${fileName}.md`; + link.download = fileName; + document.body.appendChild(link); + const event = new MouseEvent('click'); + link.dispatchEvent(event); + document.body.removeChild(link); + } }; From 0a30764c8cb94451a659b2255944e03325b189cf Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sat, 19 Oct 2024 03:33:42 +0800 Subject: [PATCH 19/28] Update ContentView.tsx --- .../Chat/ChatContent/Message/View/ContentView.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/Chat/ChatContent/Message/View/ContentView.tsx b/src/components/Chat/ChatContent/Message/View/ContentView.tsx index ad4c415a9..dc3fc6a92 100644 --- a/src/components/Chat/ChatContent/Message/View/ContentView.tsx +++ b/src/components/Chat/ChatContent/Message/View/ContentView.tsx @@ -57,6 +57,16 @@ const ContentView = memo( const inlineLatex = useStore((state) => state.inlineLatex); const markdownMode = useStore((state) => state.markdownMode); + const preprocessContent = (text: string) => { + return text + .replace(/\\\[/g, '$$') + .replace(/\\\]/g, '$$') + .replace(/\\\(/g, '$') + .replace(/\\\)/g, '$'); + }; + + const preprocessedContent = preprocessContent(content); + const handleDelete = () => { const updatedChats: ChatInterface[] = JSON.parse( JSON.stringify(useStore.getState().chats) From 2aea8151037d4063bf075739b7a2d56f5ede2dbf Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sat, 19 Oct 2024 03:40:55 +0800 Subject: [PATCH 20/28] Update ContentView.tsx LaTeX --- src/components/Chat/ChatContent/Message/View/ContentView.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/Chat/ChatContent/Message/View/ContentView.tsx b/src/components/Chat/ChatContent/Message/View/ContentView.tsx index dc3fc6a92..cb20f8675 100644 --- a/src/components/Chat/ChatContent/Message/View/ContentView.tsx +++ b/src/components/Chat/ChatContent/Message/View/ContentView.tsx @@ -139,10 +139,10 @@ const ContentView = memo( p, }} > - {content} + {preprocessedContent} ) : ( - {content} + {preprocessedContent} )}
From 5b93c2c5f21193880f08b93411f92c731b984911 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sat, 19 Oct 2024 03:42:27 +0800 Subject: [PATCH 21/28] Update chat.ts Browser compatibility --- src/utils/chat.ts | 46 ++++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/src/utils/chat.ts b/src/utils/chat.ts index 698b05de4..a585fd1a3 100644 --- a/src/utils/chat.ts +++ b/src/utils/chat.ts @@ -52,24 +52,19 @@ export const downloadImg = (imgData: string, fileName: string) => { const blob = new Blob([ab], { type: mimeString }); - if (window.navigator && window.navigator.msSaveOrOpenBlob) { - fileName = fileName.endsWith('.png') ? fileName : `${fileName}.png`; - window.navigator.msSaveOrOpenBlob(blob, fileName); - } else { - const url = URL.createObjectURL(blob); - const link = document.createElement('a'); - link.href = url; + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; - fileName = fileName.endsWith('.png') ? fileName : `${fileName}.png`; - link.download = fileName; + fileName = fileName.endsWith('.png') ? fileName : `${fileName}.png`; + link.download = fileName; - document.body.appendChild(link); - const event = new MouseEvent('click'); - link.dispatchEvent(event); - document.body.removeChild(link); + document.body.appendChild(link); + const event = new MouseEvent('click'); + link.dispatchEvent(event); + document.body.removeChild(link); - URL.revokeObjectURL(url); - } + URL.revokeObjectURL(url); }; // Function to convert a chat object to markdown format @@ -85,17 +80,12 @@ export const chatToMarkdown = (chat: ChatInterface) => { export const downloadMarkdown = (markdown: string, fileName: string) => { const markdownFile = new Blob([markdown], { type: 'text/markdown;charset=utf-8' }); - if (window.navigator && window.navigator.msSaveOrOpenBlob) { - fileName = fileName.endsWith('.md') ? fileName : `${fileName}.md`; - window.navigator.msSaveOrOpenBlob(markdownFile, fileName); - } else { - const link = document.createElement('a'); - link.href = URL.createObjectURL(markdownFile); - fileName = fileName.endsWith('.md') ? fileName : `${fileName}.md`; - link.download = fileName; - document.body.appendChild(link); - const event = new MouseEvent('click'); - link.dispatchEvent(event); - document.body.removeChild(link); - } + const link = document.createElement('a'); + link.href = URL.createObjectURL(markdownFile); + fileName = fileName.endsWith('.md') ? fileName : `${fileName}.md`; + link.download = fileName; + document.body.appendChild(link); + const event = new MouseEvent('click'); + link.dispatchEvent(event); + document.body.removeChild(link); }; From 521a567bedd72ad90b6312614cc8e14ba5db65f5 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sat, 19 Oct 2024 05:45:02 +0800 Subject: [PATCH 22/28] Update ContentView.tsx --- .../ChatContent/Message/View/ContentView.tsx | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/components/Chat/ChatContent/Message/View/ContentView.tsx b/src/components/Chat/ChatContent/Message/View/ContentView.tsx index cb20f8675..9b9335d8d 100644 --- a/src/components/Chat/ChatContent/Message/View/ContentView.tsx +++ b/src/components/Chat/ChatContent/Message/View/ContentView.tsx @@ -57,16 +57,6 @@ const ContentView = memo( const inlineLatex = useStore((state) => state.inlineLatex); const markdownMode = useStore((state) => state.markdownMode); - const preprocessContent = (text: string) => { - return text - .replace(/\\\[/g, '$$') - .replace(/\\\]/g, '$$') - .replace(/\\\(/g, '$') - .replace(/\\\)/g, '$'); - }; - - const preprocessedContent = preprocessContent(content); - const handleDelete = () => { const updatedChats: ChatInterface[] = JSON.parse( JSON.stringify(useStore.getState().chats) @@ -120,7 +110,7 @@ const ContentView = memo( - {preprocessedContent} + {content} ) : ( - {preprocessedContent} + {content} )}
From 6cda49764764d19fd1a7b8aad764aff4fd2603ee Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sat, 19 Oct 2024 15:34:59 +0800 Subject: [PATCH 23/28] Update ContentView.tsx --- .../Chat/ChatContent/Message/View/ContentView.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/Chat/ChatContent/Message/View/ContentView.tsx b/src/components/Chat/ChatContent/Message/View/ContentView.tsx index 9b9335d8d..8e9af1c1b 100644 --- a/src/components/Chat/ChatContent/Message/View/ContentView.tsx +++ b/src/components/Chat/ChatContent/Message/View/ContentView.tsx @@ -45,6 +45,11 @@ const ContentView = memo( setIsEdit: React.Dispatch>; messageIndex: number; }) => { + const replaceMathDelimiters = (text: string) => { + text = text.replace(/\\\((.+?)\\\)/g, (match, p1) => `$${p1}$`); + text = text.replace(/\\\[(.+?)\\\]/gs, (match, p1) => `$$${p1}$$`); + return text; + }; const { handleSubmit } = useSubmit(); const [isDelete, setIsDelete] = useState(false); @@ -103,6 +108,8 @@ const ContentView = memo( navigator.clipboard.writeText(content); }; + const processedContent = replaceMathDelimiters(content); + return ( <>
@@ -110,7 +117,7 @@ const ContentView = memo( - {content} + {replaceMathDelimiters(content)} ) : ( {content} From e9c4e1388cc796790520b32c824b37896f8ba329 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sat, 19 Oct 2024 18:04:43 +0800 Subject: [PATCH 24/28] Update ContentView.tsx --- .../ChatContent/Message/View/ContentView.tsx | 33 +++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/src/components/Chat/ChatContent/Message/View/ContentView.tsx b/src/components/Chat/ChatContent/Message/View/ContentView.tsx index 8e9af1c1b..cfd49eae5 100644 --- a/src/components/Chat/ChatContent/Message/View/ContentView.tsx +++ b/src/components/Chat/ChatContent/Message/View/ContentView.tsx @@ -45,11 +45,6 @@ const ContentView = memo( setIsEdit: React.Dispatch>; messageIndex: number; }) => { - const replaceMathDelimiters = (text: string) => { - text = text.replace(/\\\((.+?)\\\)/g, (match, p1) => `$${p1}$`); - text = text.replace(/\\\[(.+?)\\\]/gs, (match, p1) => `$$${p1}$$`); - return text; - }; const { handleSubmit } = useSubmit(); const [isDelete, setIsDelete] = useState(false); @@ -62,6 +57,32 @@ const ContentView = memo( const inlineLatex = useStore((state) => state.inlineLatex); const markdownMode = useStore((state) => state.markdownMode); + const replaceMathDelimiters = (text: string) => { + text = text.replace(/\\\((.+?)\\\)/g, (match, p1) => `$${p1}$`); + text = text.replace(/\\\[(.+?)\\\]/gs, (match, p1) => `$$${p1}$$`); + return text; + }; + + const processContent = (text: string) => { + const regex = /(```[\s\S]*?```|'[^']*'|"[^"]*")/g; + let lastIndex = 0; + let result = ''; + + text.replace(regex, (match, offset) => { + const precedingText = text.slice(lastIndex, offset); + result += replaceMathDelimiters(precedingText); + + result += match; + + lastIndex = offset + match.length; + return match; + }); + + result += replaceMathDelimiters(text.slice(lastIndex)); + + return result; + }; + const handleDelete = () => { const updatedChats: ChatInterface[] = JSON.parse( JSON.stringify(useStore.getState().chats) @@ -136,7 +157,7 @@ const ContentView = memo( p, }} > - {replaceMathDelimiters(content)} + {processContent(content)} ) : ( {content} From 5c83918b21206f9f20a38a27767a174d11863d92 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 22 Nov 2024 23:42:34 +0800 Subject: [PATCH 25/28] Update chat.ts add gpt-4o-2024-08-06 --- src/types/chat.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/types/chat.ts b/src/types/chat.ts index fa2856e9a..886570f10 100644 --- a/src/types/chat.ts +++ b/src/types/chat.ts @@ -55,6 +55,7 @@ export type ModelOptions = | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' + | 'gpt-4o-2024-11-20' | 'chatgpt-4o-latest' | 'o1-mini' | 'o1-mini-2024-09-12' From 93ceadadc8bbfd3831539d7ebba7b8c083b9c2eb Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 22 Nov 2024 23:42:55 +0800 Subject: [PATCH 26/28] Update chat.ts add gpt-4o-2024-11-20 From e46be5bde3cfdeab5bbeb05ec2fafa53343cf0f2 Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Fri, 22 Nov 2024 23:45:12 +0800 Subject: [PATCH 27/28] Update chat.ts add gpt-4o-2024-11-20 --- src/constants/chat.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/constants/chat.ts b/src/constants/chat.ts index 39d8e3ba2..a9ac60dd5 100644 --- a/src/constants/chat.ts +++ b/src/constants/chat.ts @@ -33,6 +33,7 @@ export const modelOptions: ModelOptions[] = [ 'gpt-4o', 'gpt-4o-2024-05-13', 'gpt-4o-2024-08-06', + 'gpt-4o-2024-11-20', 'chatgpt-4o-latest', 'o1-mini', 'o1-mini-2024-09-12', @@ -68,6 +69,7 @@ export const modelMaxToken = { 'gpt-4o': 128000, 'gpt-4o-2024-05-13': 128000, 'gpt-4o-2024-08-06': 128000, + 'gpt-4o-2024-11-20': 128000, 'chatgpt-4o-latest': 128000, 'o1-mini': 128000, 'o1-mini-2024-09-12': 128000, @@ -164,6 +166,10 @@ export const modelCost = { prompt: { price: 0.0025, unit: 1000 }, completion: { price: 0.01, unit: 1000 }, }, + 'gpt-4o-2024-11-20': { + prompt: { price: 0.0025, unit: 1000 }, + completion: { price: 0.01, unit: 1000 }, + }, 'chatgpt-4o-latest': { prompt: { price: 0.0025, unit: 1000 }, completion: { price: 0.01, unit: 1000 }, From 58ccc440e09b6b9a4e1ab5e80d12a8a1a73d8f9b Mon Sep 17 00:00:00 2001 From: ChenYuZe519 Date: Sat, 23 Nov 2024 20:57:43 +0800 Subject: [PATCH 28/28] Update ContentView.tsx --- .../ChatContent/Message/View/ContentView.tsx | 30 +------------------ 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/src/components/Chat/ChatContent/Message/View/ContentView.tsx b/src/components/Chat/ChatContent/Message/View/ContentView.tsx index cfd49eae5..ad4c415a9 100644 --- a/src/components/Chat/ChatContent/Message/View/ContentView.tsx +++ b/src/components/Chat/ChatContent/Message/View/ContentView.tsx @@ -57,32 +57,6 @@ const ContentView = memo( const inlineLatex = useStore((state) => state.inlineLatex); const markdownMode = useStore((state) => state.markdownMode); - const replaceMathDelimiters = (text: string) => { - text = text.replace(/\\\((.+?)\\\)/g, (match, p1) => `$${p1}$`); - text = text.replace(/\\\[(.+?)\\\]/gs, (match, p1) => `$$${p1}$$`); - return text; - }; - - const processContent = (text: string) => { - const regex = /(```[\s\S]*?```|'[^']*'|"[^"]*")/g; - let lastIndex = 0; - let result = ''; - - text.replace(regex, (match, offset) => { - const precedingText = text.slice(lastIndex, offset); - result += replaceMathDelimiters(precedingText); - - result += match; - - lastIndex = offset + match.length; - return match; - }); - - result += replaceMathDelimiters(text.slice(lastIndex)); - - return result; - }; - const handleDelete = () => { const updatedChats: ChatInterface[] = JSON.parse( JSON.stringify(useStore.getState().chats) @@ -129,8 +103,6 @@ const ContentView = memo( navigator.clipboard.writeText(content); }; - const processedContent = replaceMathDelimiters(content); - return ( <>
@@ -157,7 +129,7 @@ const ContentView = memo( p, }} > - {processContent(content)} + {content} ) : ( {content}