适配上传不同类型的文件,适配gpt-4-all,支持包含vision字段的模型,自动打开上传文件按钮

This commit is contained in:
Clivia
2024-02-08 02:30:45 +00:00
parent 9212773d88
commit f6afa671ed
5 changed files with 135 additions and 39 deletions

View File

@@ -373,17 +373,17 @@ function ChatAction(props: {
style={
props.icon && !props.loding
? ({
"--icon-width": `${width.icon}px`,
"--full-width": `${width.full}px`,
...props.style,
} as React.CSSProperties)
"--icon-width": `${width.icon}px`,
"--full-width": `${width.full}px`,
...props.style,
} as React.CSSProperties)
: props.loding
? ({
? ({
"--icon-width": `30px`,
"--full-width": `30px`,
...props.style,
} as React.CSSProperties)
: props.style
: props.style
}
>
{props.icon ? (
@@ -538,7 +538,7 @@ export function ChatActions(props: {
}
}
};
if (currentModel === "gpt-4-vision-preview") {
if (currentModel.includes("vision")) {
window.addEventListener("paste", onPaste);
return () => {
window.removeEventListener("paste", onPaste);
@@ -609,7 +609,7 @@ export function ChatActions(props: {
{config.pluginConfig.enable &&
/^gpt(?!.*03\d{2}$).*$/.test(currentModel) &&
currentModel != "gpt-4-vision-preview" && (
!currentModel.includes("vision") && (
<ChatAction
onClick={switchUsePlugins}
text={
@@ -620,16 +620,16 @@ export function ChatActions(props: {
icon={usePlugins ? <EnablePluginIcon /> : <DisablePluginIcon />}
/>
)}
{currentModel == "gpt-4-vision-preview" && (
{currentModel.includes("vision") && (
<ChatAction
onClick={selectImage}
text="选择图片"
text="选择文档"
loding={uploadLoading}
icon={<UploadIcon />}
innerNode={
<input
type="file"
accept=".png,.jpg,.webp,.jpeg"
accept="*/*"
id="chat-image-file-select-upload"
style={{ display: "none" }}
onChange={onImageSelected}
@@ -1031,28 +1031,28 @@ function _Chat() {
.concat(
isLoading
? [
{
...createMessage({
role: "assistant",
content: "……",
}),
preview: true,
},
]
{
...createMessage({
role: "assistant",
content: "……",
}),
preview: true,
},
]
: [],
)
.concat(
userInput.length > 0 && config.sendPreviewBubble
? [
{
...createMessage({
role: "user",
content: userInput,
image_url: userImage?.fileUrl,
}),
preview: true,
},
]
{
...createMessage({
role: "user",
content: userInput,
image_url: userImage?.fileUrl,
}),
preview: true,
},
]
: [],
);
}, [
@@ -1149,7 +1149,7 @@ function _Chat() {
if (payload.key || payload.url) {
showConfirm(
Locale.URLCommand.Settings +
`\n${JSON.stringify(payload, null, 4)}`,
`\n${JSON.stringify(payload, null, 4)}`,
).then((res) => {
if (!res) return;
if (payload.key) {
@@ -1412,7 +1412,7 @@ function _Chat() {
defaultShow={i >= messages.length - 6}
/>
</div>
{!isUser && message.model == "gpt-4-vision-preview" && (
{!isUser && message?.model?.includes("vision") && (
<div
className={[
styles["chat-message-actions"],