Skip to content

Commit

Permalink
修改: app/api/bedrock.ts
Browse files Browse the repository at this point in the history
	删除:     app/api/bedrock/models.ts
	删除:     app/api/bedrock/utils.ts
	修改:     app/client/platforms/bedrock.ts
	删除:     app/components/chat-actions.tsx
	修改:     app/components/chat.tsx
	修改:     app/constant.ts
	删除:     app/icons/document.svg
  • Loading branch information
glayyiyi committed Nov 4, 2024
1 parent dca4a0e commit fc39116
Show file tree
Hide file tree
Showing 8 changed files with 355 additions and 1,158 deletions.
410 changes: 350 additions & 60 deletions app/api/bedrock.ts

Large diffs are not rendered by default.

405 changes: 0 additions & 405 deletions app/api/bedrock/models.ts

This file was deleted.

400 changes: 0 additions & 400 deletions app/api/bedrock/utils.ts

This file was deleted.

2 changes: 1 addition & 1 deletion app/client/platforms/bedrock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class BedrockApi implements LLMApi {
// Add error message as text content
content.push({
type: "text",
text: `Error processing image: ${e.message}`,
text: `Error processing image: ${e}`,
});
}
}
Expand Down
188 changes: 0 additions & 188 deletions app/components/chat-actions.tsx

This file was deleted.

95 changes: 1 addition & 94 deletions app/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, {
Fragment,
RefObject,
} from "react";
import DocumentIcon from "../icons/document.svg";

import SendWhiteIcon from "../icons/send-white.svg";
import BrainIcon from "../icons/brain.svg";
import RenameIcon from "../icons/rename.svg";
Expand Down Expand Up @@ -548,91 +548,6 @@ export function ChatActions(props: {
);
}
}, [chatStore, currentModel, models]);
const isBedrockProvider = currentProviderName === ServiceProvider.Bedrock;

// ... (rest of the existing state and functions)

async function uploadDocument() {
const fileInput = document.createElement("input");
fileInput.type = "file";
fileInput.accept = ".pdf,.csv,.doc,.docx,.xls,.xlsx,.html,.txt,.md";
fileInput.onchange = async (event: any) => {
const file = event.target.files[0];
if (!file) return;

props.setUploading(true);
try {
// Convert file to base64
const base64 = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
if (!e.target?.result) return reject("Failed to read file");
const base64 = (e.target.result as string).split(",")[1];
resolve(base64);
};
reader.onerror = reject;
reader.readAsDataURL(file);
});

// Get file extension
const format = file.name.split(".").pop()?.toLowerCase() || "";
const supportedFormats = [
"pdf",
"csv",
"doc",
"docx",
"xls",
"xlsx",
"html",
"txt",
"md",
];

if (!supportedFormats.includes(format)) {
throw new Error("Unsupported file format");
}

// Format file size
const size = file.size;
let sizeStr = "";
if (size < 1024) {
sizeStr = size + " B";
} else if (size < 1024 * 1024) {
sizeStr = (size / 1024).toFixed(2) + " KB";
} else {
sizeStr = (size / (1024 * 1024)).toFixed(2) + " MB";
}

// Create document content with only filename and size
const documentContent = {
type: "document",
document: {
format,
name: file.name,
size: sizeStr,
source: {
bytes: base64,
},
},
};

// Submit the document content as a JSON string but only display filename and size
const displayContent = `Document: ${file.name} (${sizeStr})`;
chatStore.onUserInput(displayContent);

// Store the actual document content separately if needed
// chatStore.updateCurrentSession((session) => {
// session.lastDocument = documentContent;
// });
} catch (error) {
console.error("Failed to upload document:", error);
showToast("Failed to upload document");
} finally {
props.setUploading(false);
}
};
fileInput.click();
}

return (
<div className={styles["chat-input-actions"]}>
Expand Down Expand Up @@ -665,14 +580,6 @@ export function ChatActions(props: {
icon={props.uploading ? <LoadingButtonIcon /> : <ImageIcon />}
/>
)}
{/* Add document upload button for Bedrock */}
{isBedrockProvider && (
<ChatAction
onClick={uploadDocument}
text={Locale.Chat.InputActions.UploadDocument}
icon={props.uploading ? <LoadingButtonIcon /> : <DocumentIcon />}
/>
)}
<ChatAction
onClick={nextTheme}
text={Locale.Chat.InputActions.Theme[theme]}
Expand Down
6 changes: 3 additions & 3 deletions app/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ const bedrockModels = [
"anthropic.claude-3-opus-20240229-v1:0",
"anthropic.claude-3-5-sonnet-20241022-v2:0",
// Meta Llama Models
"meta.llama3-2-11b-instruct-v1:0",
"meta.llama3-2-90b-instruct-v1:0",
"us.meta.llama3-2-11b-instruct-v1:0",
"us.meta.llama3-2-90b-instruct-v1:0",
//Mistral
"mistral.mistral-large-2402-v1:0",
"mistral.mistral-large-2407-v1:0",
Expand Down Expand Up @@ -529,7 +529,7 @@ export const DEFAULT_MODELS = [
id: "bedrock",
providerName: "Bedrock",
providerType: "bedrock",
sorted: 12,
sorted: 13,
},
})),
] as const;
Expand Down
7 changes: 0 additions & 7 deletions app/icons/document.svg

This file was deleted.

0 comments on commit fc39116

Please sign in to comment.