mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-10-10 05:05:34 +02:00
Bugfix/chat images (#4618)
* keep chatfiletype as image instead of user_knowledge * improve continue message * fix to image handling * greptile code review --------- Co-authored-by: Richard Kuo (Onyx) <rkuo@onyx.app>
This commit is contained in:
@@ -141,6 +141,11 @@ const TEMP_USER_MESSAGE_ID = -1;
|
||||
const TEMP_ASSISTANT_MESSAGE_ID = -2;
|
||||
const SYSTEM_MESSAGE_ID = -3;
|
||||
|
||||
export enum UploadIntent {
|
||||
ATTACH_TO_MESSAGE, // For files uploaded via ChatInputBar (paste, drag/drop)
|
||||
ADD_TO_DOCUMENTS, // For files uploaded via FilePickerModal or similar (just add to repo)
|
||||
}
|
||||
|
||||
export function ChatPage({
|
||||
toggle,
|
||||
documentSidebarInitialWidth,
|
||||
@@ -633,7 +638,7 @@ export function ChatPage({
|
||||
}: {
|
||||
messages: Message[];
|
||||
// if calling this function repeatedly with short delay, stay may not update in time
|
||||
// and result in weird behavipr
|
||||
// and result in weird behavior
|
||||
completeMessageMapOverride?: Map<number, Message> | null;
|
||||
chatSessionId?: string;
|
||||
replacementsMap?: Map<number, number> | null;
|
||||
@@ -1946,7 +1951,10 @@ export function ChatPage({
|
||||
}
|
||||
};
|
||||
|
||||
const handleImageUpload = async (acceptedFiles: File[]) => {
|
||||
const handleImageUpload = async (
|
||||
acceptedFiles: File[],
|
||||
intent: UploadIntent
|
||||
) => {
|
||||
const [_, llmModel] = getFinalLLM(
|
||||
llmProviders,
|
||||
liveAssistant,
|
||||
@@ -1969,14 +1977,34 @@ export function ChatPage({
|
||||
|
||||
updateChatState("uploading", currentSessionId());
|
||||
|
||||
const newlyUploadedFileDescriptors: FileDescriptor[] = [];
|
||||
|
||||
for (let file of acceptedFiles) {
|
||||
const formData = new FormData();
|
||||
formData.append("files", file);
|
||||
const response = await uploadFile(formData, null);
|
||||
const response: FileResponse[] = await uploadFile(formData, null);
|
||||
|
||||
if (response.length > 0) {
|
||||
const uploadedFile = response[0];
|
||||
addSelectedFile(uploadedFile);
|
||||
|
||||
if (intent == UploadIntent.ADD_TO_DOCUMENTS) {
|
||||
addSelectedFile(uploadedFile);
|
||||
} else {
|
||||
const newFileDescriptor: FileDescriptor = {
|
||||
// Use file_id (storage ID) if available, otherwise fallback to DB id
|
||||
// Ensure it's a string as FileDescriptor expects
|
||||
id: uploadedFile.file_id
|
||||
? String(uploadedFile.file_id)
|
||||
: String(uploadedFile.id),
|
||||
type: uploadedFile.chat_file_type
|
||||
? uploadedFile.chat_file_type
|
||||
: ChatFileType.PLAIN_TEXT,
|
||||
name: uploadedFile.name,
|
||||
isUploading: false, // Mark as successfully uploaded
|
||||
};
|
||||
|
||||
setCurrentMessageFiles((prev) => [...prev, newFileDescriptor]);
|
||||
}
|
||||
} else {
|
||||
setPopup({
|
||||
type: "error",
|
||||
@@ -2582,7 +2610,12 @@ export function ChatPage({
|
||||
{documentSidebarInitialWidth !== undefined && isReady ? (
|
||||
<Dropzone
|
||||
key={currentSessionId()}
|
||||
onDrop={handleImageUpload}
|
||||
onDrop={(acceptedFiles) =>
|
||||
handleImageUpload(
|
||||
acceptedFiles,
|
||||
UploadIntent.ATTACH_TO_MESSAGE
|
||||
)
|
||||
}
|
||||
noClick
|
||||
>
|
||||
{({ getRootProps }) => (
|
||||
|
Reference in New Issue
Block a user