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: knowledge tab list #1222

Merged
merged 17 commits into from
Sep 22, 2023
Merged

feat: knowledge tab list #1222

merged 17 commits into from
Sep 22, 2023

Conversation

gozineb
Copy link
Contributor

@gozineb gozineb commented Sep 20, 2023

Description

Please include a summary of the changes and the related issue. Please also include relevant motivation and context.

Checklist before requesting a review

Please delete options that are not relevant.

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented hard-to-understand areas
  • I have ideally added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged

Screenshots (if appropriate):

@vercel
Copy link

vercel bot commented Sep 20, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 22, 2023 8:03am
quivr-strapi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 22, 2023 8:03am
quivrapp ❌ Failed (Inspect) Sep 22, 2023 8:03am

@github-actions
Copy link
Contributor

github-actions bot commented Sep 20, 2023

Risk Level 2 - /home/runner/work/quivr/quivr/backend/routes/knowledge_routes.py

  1. The get_all_knowledge function is used without any exception handling. If it fails due to a database error or other unexpected issue, it could cause the entire endpoint to fail. Consider wrapping it in a try/except block to handle potential errors gracefully.

  2. The delete_endpoint function deletes a knowledge item and then attempts to delete its associated file. If the file deletion fails, the knowledge item will already have been deleted. Consider deleting the file first, and only deleting the knowledge item if the file deletion is successful.

  3. The delete_endpoint function assumes that every knowledge item has either a file_name or a url. If a knowledge item has neither, this could cause an error. Consider adding a check to ensure that at least one of these properties is present.

Example:

if not (knowledge.file_name or knowledge.url):
    raise Exception(\"Knowledge item has no associated file or URL\")

Risk Level 2 - /home/runner/work/quivr/quivr/frontend/app/brains-management/[brainId]/components/BrainManagementTabs/components/KnowledgeTab/KnowledgeItem/useKnowledgeItem.ts

  1. The onDeleteKnowledge function sets isDeleting to true at the start, but it only sets it back to false at the end of the function. If an error occurs during the deletion process and an exception is thrown, isDeleting will remain true indefinitely. Consider using a finally block to ensure that isDeleting is always set back to false, even if an error occurs.

  2. The onDeleteKnowledge function does not handle the case where currentBrain?.id is undefined. If this occurs, it will throw an error which is not caught by any catch block. Consider adding error handling for this case.

Example:

if (currentBrain?.id === undefined) {
    console.error(\"Current brain ID is undefined\");
    setIsDeleting(false);
    return;
}

Risk Level 2 - /home/runner/work/quivr/quivr/frontend/lib/api/knowledge/knowledge.ts

The code is generally well-written and follows good practices. However, there is a potential issue with error handling. When the knowledge.file_name and knowledge.url are both null, an error is thrown. It would be better to handle this error more gracefully, perhaps by returning a default value or logging the error for further investigation.


📚💣🔧


Powered by Code Review GPT


const canDeleteFile = currentBrain?.role === "Owner";

console.log("isDeleting", isDeleting);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

return (
<a
onClick={() => void downloadFile()}
style={{ display: "flex", flexDirection: "column", alignItems: "center" }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

Comment on lines +7 to +10

export const UploadedKnowledgeItem = ({
knowledge,
}: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to have many things in common with CrawledKnowledgeItem...

Maybe managing isUploadedKnowledge in another way ?

};

KnowledgeItem.displayName = "KnowledgeItem";
export default KnowledgeItem;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

});
console.error(`Error deleting ${knowledge_name ?? ""}`, error);
}
setIsDeleting(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems ok but inside finally should be better


const { getAllKnowledge } = useKnowledgeApi();
const { data: brainKnowledges, isLoading: isPending } = useQuery({
queryKey: [getKnowledgeDataKey(brainId)],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 🤩

@@ -19,7 +20,7 @@ const Layout = ({ children }: LayoutProps): JSX.Element => {
return (
<div className="relative h-full w-full flex justify-stretch items-stretch">
<BrainsList />
{children}
<KnowledgeProvider>{children}</KnowledgeProvider>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KnowledgeProvider seems to have be added 2 times

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KnowledgeTab/index.tsx too

@@ -0,0 +1,6 @@
import { UUID } from "crypto";

const brainDataKey = "quivr-knowledge";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

}: {
children: React.ReactNode;
}): JSX.Element => {
const [allKnowledge, setAllKnowledge] = useState<Knowledge[]>([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that allKnowledge is not being used. A new state has been introduced in useknowledgeTab, which is conflicting with this

Right ?

};
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const useKnowledgeTab = ({ brainId }: useKnowledgeTabProps) => {
const [allKnowledge, setAllKnowledge] = useState<Knowledge[]>([]);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replace get and set from the context

@gozineb gozineb merged commit d2b4ef4 into main Sep 22, 2023
9 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants