mirror of
https://github.com/Yanyutin753/ChatGPT-Next-Web-LangChain-Gpt-4-All.git
synced 2025-10-14 15:11:28 +00:00
修改适配url替代base64
This commit is contained in:
@@ -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,
|
||||
|
Reference in New Issue
Block a user