From 74678ece61d35be619308e33b85ba5a8e306ce92 Mon Sep 17 00:00:00 2001 From: Clivia <132346501+Yanyutin753@users.noreply.github.com> Date: Mon, 26 Feb 2024 23:23:12 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=80=82=E9=85=8Durl?= =?UTF-8?q?=E6=9B=BF=E4=BB=A3base64?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/client/platforms/openai.ts | 159 ++++++++++++++++----------------- 1 file changed, 79 insertions(+), 80 deletions(-) diff --git a/app/client/platforms/openai.ts b/app/client/platforms/openai.ts index 9429ca5..5d5d868 100644 --- a/app/client/platforms/openai.ts +++ b/app/client/platforms/openai.ts @@ -106,93 +106,93 @@ export class ChatGPTApi implements LLMApi { text: v.content, }); if (v.image_url) { - var base64Data = await getImageBase64Data(v.image_url); - interface MIMEMap { - [key: string]: string; - } + // var base64Data = await getImageBase64Data(v.image_url); + // interface MIMEMap { + // [key: string]: string; + // } - const extensionToMIME: MIMEMap = { - 'png': 'image/png', - 'jpeg': 'image/jpeg', - 'jpg': 'image/jpeg', - 'webp': 'image/webp', - 'gif': 'image/gif', - 'bmp': 'image/bmp', - 'svg': 'image/svg+xml', - 'txt': 'text/plain', - 'pdf': 'application/pdf', - 'doc': 'application/msword', - 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', - 'xls': 'application/vnd.ms-excel', - 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', - 'ppt': 'application/vnd.ms-powerpoint', - 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', - 'zip': 'application/zip', - 'rar': 'application/x-rar-compressed', - 'bin': 'application/octet-stream', + // const extensionToMIME: MIMEMap = { + // 'png': 'image/png', + // 'jpg': 'image/jpeg', + // 'webp': 'image/webp', + // 'gif': 'image/gif', + // 'bmp': 'image/bmp', + // 'svg': 'image/svg+xml', + // 'txt': 'text/plain', + // 'pdf': 'application/pdf', + // 'doc': 'application/msword', + // 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + // 'xls': 'application/vnd.ms-excel', + // 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + // 'ppt': 'application/vnd.ms-powerpoint', + // 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation', + // 'zip': 'application/zip', + // 'rar': 'application/x-rar-compressed', + // 'bin': 'application/octet-stream', - // Audio - 'mp3': 'audio/mpeg', - 'wav': 'audio/wav', - 'ogg': 'audio/ogg', - 'flac': 'audio/flac', - 'aac': 'audio/aac', - 'weba': 'audio/webm', - 'midi': 'audio/midi', + // // Audio + // 'mp3': 'audio/mpeg', + // 'wav': 'audio/wav', + // 'ogg': 'audio/ogg', + // 'flac': 'audio/flac', + // 'aac': 'audio/aac', + // 'weba': 'audio/webm', + // 'midi': 'audio/midi', - // Video - 'mp4': 'video/mp4', - 'webm': 'video/webm', - 'avi': 'video/x-msvideo', - 'wmv': 'video/x-ms-wmv', - 'flv': 'video/x-flv', - '3gp': 'video/3gpp', - 'mkv': 'video/x-matroska', + // // Video + // 'mp4': 'video/mp4', + // 'webm': 'video/webm', + // 'avi': 'video/x-msvideo', + // 'wmv': 'video/x-ms-wmv', + // 'flv': 'video/x-flv', + // '3gp': 'video/3gpp', + // 'mkv': 'video/x-matroska', - //编程 - 'js': 'application/javascript', - 'json': 'application/json', - 'html': 'text/html', - 'css': 'text/css', - 'xml': 'application/xml', - 'csv': 'text/csv', - 'ts': 'text/typescript', - 'java': 'text/x-java-source', - 'py': 'text/x-python', - 'c': 'text/x-csrc', - 'cpp': 'text/x-c++src', - 'h': 'text/x-chdr', - 'hpp': 'text/x-c++hdr', - 'php': 'application/x-httpd-php', - 'rb': 'text/x-ruby', - 'go': 'text/x-go', - 'rs': 'text/rust', - 'swift': 'text/x-swift', - 'kt': 'text/x-kotlin', - 'scala': 'text/x-scala', - }; + // //编程 + // 'js': 'application/javascript', + // 'json': 'application/json', + // 'html': 'text/html', + // 'css': 'text/css', + // 'xml': 'application/xml', + // 'csv': 'text/csv', + // 'ts': 'text/typescript', + // 'java': 'text/x-java-source', + // 'py': 'text/x-python', + // 'c': 'text/x-csrc', + // 'cpp': 'text/x-c++src', + // 'h': 'text/x-chdr', + // 'hpp': 'text/x-c++hdr', + // 'php': 'application/x-httpd-php', + // 'rb': 'text/x-ruby', + // 'go': 'text/x-go', + // 'rs': 'text/rust', + // 'swift': 'text/x-swift', + // 'kt': 'text/x-kotlin', + // 'scala': 'text/x-scala', + // }; - let mimeType: string | undefined; - try { - // 使用正则表达式获取文件后缀 - const match = v.image_url.match(/\.(\w+)$/); - if (match) { - const fileExtension = match[1].toLowerCase(); - mimeType = extensionToMIME[fileExtension]; - if (!mimeType) { - throw new Error('Unknown file extension: ' + fileExtension); - } - } else { - throw new Error('Unable to extract file extension from the URL'); - } - } catch (error) { - // 使用通用的MIME类型 - mimeType = 'application/octet-stream'; - } + // let mimeType: string | undefined; + // try { + // // 使用正则表达式获取文件后缀 + // const match = v.image_url.match(/\.(\w+)$/); + // if (match) { + // const fileExtension = match[1].toLowerCase(); + // mimeType = extensionToMIME[fileExtension]; + // if (!mimeType) { + // throw new Error('Unknown file extension: ' + fileExtension); + // } + // } else { + // throw new Error('Unable to extract file extension from the URL'); + // } + // } catch (error) { + // mimeType = 'text/plain'; // 使用通用的MIME类型 + // } + // console.log(mimeType); + var url = window.location.protocol + "//" + window.location.hostname; message.content.push({ type: "image_url", image_url: { - url: `data:${mimeType};base64,${base64Data}`, + url: `${url}${v.image_url}`, }, }); } @@ -206,7 +206,6 @@ export class ChatGPTApi implements LLMApi { }), ); } - const modelConfig = { ...useAppConfig.getState().modelConfig, ...useChatStore.getState().currentSession().mask.modelConfig,