mirror of
https://github.com/Yanyutin753/ChatGPT-Next-Web-LangChain-Gpt-4-All.git
synced 2025-10-17 00:13:53 +00:00
修改适配url替代base64
This commit is contained in:
@@ -106,93 +106,93 @@ export class ChatGPTApi implements LLMApi {
|
|||||||
text: v.content,
|
text: v.content,
|
||||||
});
|
});
|
||||||
if (v.image_url) {
|
if (v.image_url) {
|
||||||
var base64Data = await getImageBase64Data(v.image_url);
|
// var base64Data = await getImageBase64Data(v.image_url);
|
||||||
interface MIMEMap {
|
// interface MIMEMap {
|
||||||
[key: string]: string;
|
// [key: string]: string;
|
||||||
}
|
// }
|
||||||
|
|
||||||
const extensionToMIME: MIMEMap = {
|
// const extensionToMIME: MIMEMap = {
|
||||||
'png': 'image/png',
|
// 'png': 'image/png',
|
||||||
'jpeg': 'image/jpeg',
|
// 'jpg': 'image/jpeg',
|
||||||
'jpg': 'image/jpeg',
|
// 'webp': 'image/webp',
|
||||||
'webp': 'image/webp',
|
// 'gif': 'image/gif',
|
||||||
'gif': 'image/gif',
|
// 'bmp': 'image/bmp',
|
||||||
'bmp': 'image/bmp',
|
// 'svg': 'image/svg+xml',
|
||||||
'svg': 'image/svg+xml',
|
// 'txt': 'text/plain',
|
||||||
'txt': 'text/plain',
|
// 'pdf': 'application/pdf',
|
||||||
'pdf': 'application/pdf',
|
// 'doc': 'application/msword',
|
||||||
'doc': 'application/msword',
|
// 'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
||||||
'docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
// 'xls': 'application/vnd.ms-excel',
|
||||||
'xls': 'application/vnd.ms-excel',
|
// 'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
||||||
'xlsx': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
// 'ppt': 'application/vnd.ms-powerpoint',
|
||||||
'ppt': 'application/vnd.ms-powerpoint',
|
// 'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
||||||
'pptx': 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
// 'zip': 'application/zip',
|
||||||
'zip': 'application/zip',
|
// 'rar': 'application/x-rar-compressed',
|
||||||
'rar': 'application/x-rar-compressed',
|
// 'bin': 'application/octet-stream',
|
||||||
'bin': 'application/octet-stream',
|
|
||||||
|
|
||||||
// Audio
|
// // Audio
|
||||||
'mp3': 'audio/mpeg',
|
// 'mp3': 'audio/mpeg',
|
||||||
'wav': 'audio/wav',
|
// 'wav': 'audio/wav',
|
||||||
'ogg': 'audio/ogg',
|
// 'ogg': 'audio/ogg',
|
||||||
'flac': 'audio/flac',
|
// 'flac': 'audio/flac',
|
||||||
'aac': 'audio/aac',
|
// 'aac': 'audio/aac',
|
||||||
'weba': 'audio/webm',
|
// 'weba': 'audio/webm',
|
||||||
'midi': 'audio/midi',
|
// 'midi': 'audio/midi',
|
||||||
|
|
||||||
// Video
|
// // Video
|
||||||
'mp4': 'video/mp4',
|
// 'mp4': 'video/mp4',
|
||||||
'webm': 'video/webm',
|
// 'webm': 'video/webm',
|
||||||
'avi': 'video/x-msvideo',
|
// 'avi': 'video/x-msvideo',
|
||||||
'wmv': 'video/x-ms-wmv',
|
// 'wmv': 'video/x-ms-wmv',
|
||||||
'flv': 'video/x-flv',
|
// 'flv': 'video/x-flv',
|
||||||
'3gp': 'video/3gpp',
|
// '3gp': 'video/3gpp',
|
||||||
'mkv': 'video/x-matroska',
|
// 'mkv': 'video/x-matroska',
|
||||||
|
|
||||||
//编程
|
// //编程
|
||||||
'js': 'application/javascript',
|
// 'js': 'application/javascript',
|
||||||
'json': 'application/json',
|
// 'json': 'application/json',
|
||||||
'html': 'text/html',
|
// 'html': 'text/html',
|
||||||
'css': 'text/css',
|
// 'css': 'text/css',
|
||||||
'xml': 'application/xml',
|
// 'xml': 'application/xml',
|
||||||
'csv': 'text/csv',
|
// 'csv': 'text/csv',
|
||||||
'ts': 'text/typescript',
|
// 'ts': 'text/typescript',
|
||||||
'java': 'text/x-java-source',
|
// 'java': 'text/x-java-source',
|
||||||
'py': 'text/x-python',
|
// 'py': 'text/x-python',
|
||||||
'c': 'text/x-csrc',
|
// 'c': 'text/x-csrc',
|
||||||
'cpp': 'text/x-c++src',
|
// 'cpp': 'text/x-c++src',
|
||||||
'h': 'text/x-chdr',
|
// 'h': 'text/x-chdr',
|
||||||
'hpp': 'text/x-c++hdr',
|
// 'hpp': 'text/x-c++hdr',
|
||||||
'php': 'application/x-httpd-php',
|
// 'php': 'application/x-httpd-php',
|
||||||
'rb': 'text/x-ruby',
|
// 'rb': 'text/x-ruby',
|
||||||
'go': 'text/x-go',
|
// 'go': 'text/x-go',
|
||||||
'rs': 'text/rust',
|
// 'rs': 'text/rust',
|
||||||
'swift': 'text/x-swift',
|
// 'swift': 'text/x-swift',
|
||||||
'kt': 'text/x-kotlin',
|
// 'kt': 'text/x-kotlin',
|
||||||
'scala': 'text/x-scala',
|
// 'scala': 'text/x-scala',
|
||||||
};
|
// };
|
||||||
|
|
||||||
let mimeType: string | undefined;
|
// let mimeType: string | undefined;
|
||||||
try {
|
// try {
|
||||||
// 使用正则表达式获取文件后缀
|
// // 使用正则表达式获取文件后缀
|
||||||
const match = v.image_url.match(/\.(\w+)$/);
|
// const match = v.image_url.match(/\.(\w+)$/);
|
||||||
if (match) {
|
// if (match) {
|
||||||
const fileExtension = match[1].toLowerCase();
|
// const fileExtension = match[1].toLowerCase();
|
||||||
mimeType = extensionToMIME[fileExtension];
|
// mimeType = extensionToMIME[fileExtension];
|
||||||
if (!mimeType) {
|
// if (!mimeType) {
|
||||||
throw new Error('Unknown file extension: ' + fileExtension);
|
// throw new Error('Unknown file extension: ' + fileExtension);
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
throw new Error('Unable to extract file extension from the URL');
|
// throw new Error('Unable to extract file extension from the URL');
|
||||||
}
|
// }
|
||||||
} catch (error) {
|
// } catch (error) {
|
||||||
// 使用通用的MIME类型
|
// mimeType = 'text/plain'; // 使用通用的MIME类型
|
||||||
mimeType = 'application/octet-stream';
|
// }
|
||||||
}
|
// console.log(mimeType);
|
||||||
|
var url = window.location.protocol + "//" + window.location.hostname;
|
||||||
message.content.push({
|
message.content.push({
|
||||||
type: "image_url",
|
type: "image_url",
|
||||||
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 = {
|
const modelConfig = {
|
||||||
...useAppConfig.getState().modelConfig,
|
...useAppConfig.getState().modelConfig,
|
||||||
...useChatStore.getState().currentSession().mask.modelConfig,
|
...useChatStore.getState().currentSession().mask.modelConfig,
|
||||||
|
Reference in New Issue
Block a user