Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow user to chat while feed process is pending #1120

Merged
merged 3 commits into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const ActionsBar = (): JSX.Element => {
shouldDisplayUploadCard={shouldDisplayUploadCard}
setShouldDisplayUploadCard={setShouldDisplayUploadCard}
feedBrain={() => void feedBrain()}
hasContentToFeedBrain={contents.length > 0}
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable max-lines */
"use client";
import { useFeature } from "@growthbook/growthbook-react";
import { useTranslation } from "react-i18next";
import { MdAddCircle, MdSend } from "react-icons/md";

Expand All @@ -15,17 +15,18 @@ type ChatInputProps = {
shouldDisplayUploadCard: boolean;
feedBrain: () => void;
setShouldDisplayUploadCard: (shouldDisplayUploadCard: boolean) => void;
hasContentToFeedBrain: boolean;
};

export const ChatInput = ({
shouldDisplayUploadCard,
feedBrain,
setShouldDisplayUploadCard,
hasContentToFeedBrain,
}: ChatInputProps): JSX.Element => {
const { setMessage, submitQuestion, chatId, generatingAnswer, message } =
useChatInput();
const { t } = useTranslation(["chat"]);
const shouldDisplayUploadButton = useFeature("ux-upload").on;
const { currentBrainId } = useBrainContext();

return (
Expand All @@ -37,7 +38,7 @@ export const ChatInput = ({
}}
className="sticky flex items-star bottom-0 bg-white dark:bg-black w-full flex justify-center gap-2 z-20"
>
{!shouldDisplayUploadCard && shouldDisplayUploadButton && (
{!shouldDisplayUploadCard && (
<div className="flex items-start">
<Button
className="p-0"
Expand Down Expand Up @@ -67,9 +68,12 @@ export const ChatInput = ({
{shouldDisplayUploadCard ? (
<div className="flex items-center">
<Button
disabled={currentBrainId === null}
disabled={currentBrainId === null || !hasContentToFeedBrain}
variant="tertiary"
onClick={feedBrain}
onClick={() => {
setShouldDisplayUploadCard(false);
feedBrain();
}}
type="button"
>
<MdSend className="text-3xl transform -rotate-90" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export const useKnowledgeUploader = () => {
variant: "danger",
text: t("crawlFailed", {
message: JSON.stringify(error),
ns: "upload",
}),
});
}
Expand Down Expand Up @@ -80,7 +79,7 @@ export const useKnowledgeUploader = () => {
} else {
publish({
variant: "danger",
text: t("error", { message: e, ns: "upload" }),
text: t("error", { message: e }),
});
}
}
Expand All @@ -106,11 +105,22 @@ export const useKnowledgeUploader = () => {
return;
}
try {
await Promise.all([
...files.map((file) => uploadFileHandler(file, currentBrainId)),
...urls.map((url) => crawlWebsiteHandler(url, currentBrainId)),
]);
} catch (e: unknown) {
const uploadPromises = files.map((file) =>
uploadFileHandler(file, currentBrainId)
);
const crawlPromises = urls.map((url) =>
crawlWebsiteHandler(url, currentBrainId)
);

await Promise.all([...uploadPromises, ...crawlPromises]);

setContents([]);

publish({
variant: "success",
text: t("knowledgeUploaded"),
});
} catch (e) {
publish({
variant: "danger",
text: JSON.stringify(e),
Expand Down
3 changes: 2 additions & 1 deletion frontend/public/locales/en/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ohNo": "Oh no!",
"selectBrainFirst": "You need to select a brain first. 🧠💡🥲",
"missingNecessaryRole": "You don't have the necessary role to upload content to the selected brain. 🧠💡🥲",
"invalidFileType": "Invalid file type"
"invalidFileType": "Invalid file type",
"knowledgeUploaded": "Knowledge uploaded"
}
3 changes: 2 additions & 1 deletion frontend/public/locales/es/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"success": "Archivo subido correctamente",
"title": "Subir conocimiento",
"webSite": "Ingrese la URL del sitio web",
"invalidFileType": "Tipo de archivo no permitido"
"invalidFileType": "Tipo de archivo no permitido",
"knowledgeUploaded": "Conocimiento subido"
}
3 changes: 2 additions & 1 deletion frontend/public/locales/fr/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ohNo": "Oh non !",
"selectBrainFirst": "Vous devez d'abord sélectionner un cerveau. 🧠💡🥲",
"missingNecessaryRole": "Vous n'avez pas le rôle nécessaire pour télécharger du contenu dans le cerveau sélectionné. 🧠💡🥲",
"invalidFileType": "Type de fichier invalide"
"invalidFileType": "Type de fichier invalide",
"knowledgeUploaded": "Connaissance téléchargée"
}
3 changes: 2 additions & 1 deletion frontend/public/locales/pt-br/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ohNo": "Oh, não!",
"selectBrainFirst": "Você precisa selecionar um cérebro primeiro. 🧠💡🥲",
"missingNecessaryRole": "Você não possui a função necessária para enviar conteúdo para o cérebro selecionado. 🧠💡🥲",
"invalidFileType": "Tipo de arquivo inválido"
"invalidFileType": "Tipo de arquivo inválido",
"knowledgeUploaded": "Conhecimento enviado"
}
3 changes: 2 additions & 1 deletion frontend/public/locales/ru/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ohNo": "О нет!",
"selectBrainFirst": "Сначала вам нужно выбрать мозг. 🧠💡🥲",
"missingNecessaryRole": "У вас нет необходимой роли для загрузки контента в выбранный мозг. 🧠💡🥲",
"invalidFileType": "Неверный тип файла"
"invalidFileType": "Неверный тип файла",
"knowledgeUploaded": "Знания загружены"
}
3 changes: 2 additions & 1 deletion frontend/public/locales/zh-cn/upload.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
"ohNo": "不好了!",
"selectBrainFirst": "你需要先选择一个大脑。 🧠💡🥲",
"missingNecessaryRole": "您没有所选大脑的上传权限。 🧠💡🥲",
"invalidFileType": "文件类型不受支持"
"invalidFileType": "文件类型不受支持",
"knowledgeUploaded": "知识已上传"
}
Loading