Skip to content

Commit

Permalink
fix(vector-store): unable to add new files (#181)
Browse files Browse the repository at this point in the history
Signed-off-by: Petr Kadlec <[email protected]>
  • Loading branch information
kapetr authored Jan 15, 2025
1 parent c931479 commit c2a7bc2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion src/modules/chat/layout/InputBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export const InputBar = memo(function InputBar({
const {
files,
isPending: isFilesPending,
hasFilesToUpload,
dropzone,
removeFile,
} = useFilesUpload();
Expand Down Expand Up @@ -117,7 +118,10 @@ export const InputBar = memo(function InputBar({
});

const isSubmitDisabled =
isFilesPending || !inputValue || (builderState && !builderState.isSaved);
isFilesPending ||
hasFilesToUpload ||
!inputValue ||
(builderState && !builderState.isSaved);

const placeholder = inputPlaceholder
? messages.length
Expand Down
5 changes: 5 additions & 0 deletions src/modules/chat/providers/FilesUploadProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const FilesUploadContext = createContext<{
files: VectoreStoreFileUpload[];
attachments: MessageAttachments | null;
isPending: boolean;
hasFilesToUpload: boolean;
dropzone?: DropzoneState;
vectorStoreId: string | null;
removeFile: (id: string) => void;
Expand All @@ -66,6 +67,7 @@ const FilesUploadContext = createContext<{
files: [],
attachments: null,
isPending: false,
hasFilesToUpload: false,
vectorStoreId: null,
removeFile: noop,
reset: noop,
Expand All @@ -87,6 +89,7 @@ export const FilesUploadProvider = ({ children }: PropsWithChildren) => {
setFiles,
onFileSubmit,
isPending,
hasFilesToUpload,
clearFiles,
setVectorStoreId,
vectorStoreId,
Expand Down Expand Up @@ -244,6 +247,7 @@ export const FilesUploadProvider = ({ children }: PropsWithChildren) => {
files,
attachments,
isPending,
hasFilesToUpload,
dropzone,
vectorStoreId,
removeFile,
Expand All @@ -256,6 +260,7 @@ export const FilesUploadProvider = ({ children }: PropsWithChildren) => {
files,
attachments,
isPending,
hasFilesToUpload,
dropzone,
vectorStoreId,
removeFile,
Expand Down
2 changes: 1 addition & 1 deletion src/modules/knowledge/create/CreateKnowledgeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
VectorStoreFilesUploadProvider,
} from '../files/VectorStoreFilesUploadProvider';
import { useToast } from '@/layout/providers/ToastProvider';
import { AppProvider, useAppContext } from '@/layout/providers/AppProvider';
import { useAppContext } from '@/layout/providers/AppProvider';

export interface CreateKnowledgeValues {
name: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export type VectoreStoreFileUpload = {
const Context = createContext<{
files: VectoreStoreFileUpload[];
isPending: boolean;
hasFilesToUpload: boolean;
vectorStoreId: string | null;
removeFile: (id: string) => void;
clearFiles: () => void;
Expand All @@ -65,6 +66,7 @@ const Context = createContext<{
}>({
files: [],
isPending: false,
hasFilesToUpload: false,
vectorStoreId: null,
removeFile: noop,
clearFiles: noop,
Expand Down Expand Up @@ -262,7 +264,10 @@ export const VectorStoreFilesUploadProvider = ({
const value = useMemo(() => {
return {
files,
isPending: files.some((file) => file.status !== 'complete'),
isPending: files.some(
(file) => file.status === 'uploading' || file.status === 'embedding',
),
hasFilesToUpload: files.some((file) => file.status === 'new'),
vectorStoreId,
onFileSubmit: (inputFile: VectoreStoreFileUpload, thread?: Thread) => {
if (inputFile.isReadable && !vectorStoreIdRef.current)
Expand Down

0 comments on commit c2a7bc2

Please sign in to comment.