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: implement knowledge update functionality for bots #547

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sedationh
Copy link
Contributor

@sedationh sedationh commented Dec 1, 2024

  • Added a new hook useKnowledgeUpdate to manage knowledge updates.
  • Integrated knowledge update feature in BotCard component with loading state.
  • Created updateKnowledge API in BotsController to handle knowledge updates.
  • Updated FastAPI router to include endpoint for knowledge updates, validating bot existence.
  • Refactored retrieval logic to check and update knowledge based on document changes.

close #547

- Added a new hook `useKnowledgeUpdate` to manage knowledge updates.
- Integrated knowledge update feature in `BotCard` component with loading state.
- Created `updateKnowledge` API in `BotsController` to handle knowledge updates.
- Updated FastAPI router to include endpoint for knowledge updates, validating bot existence.
- Refactored retrieval logic to check and update knowledge based on document changes.
Copy link

vercel bot commented Dec 1, 2024

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

Name Status Preview Comments Updated (UTC)
petercat ❌ Failed (Inspect) Dec 20, 2024 7:38am

Copy link

Walkthrough

This PR introduces a knowledge update functionality for bots. It includes a new hook useKnowledgeUpdate for managing updates, integrates this feature into the BotCard component with a loading state, and creates an updateKnowledge API in BotsController. The FastAPI router is updated to include a new endpoint for knowledge updates, ensuring bot existence validation. Additionally, the retrieval logic is refactored to check and update knowledge based on document changes.

Changes

File Summary
client/app/factory/list/components/BotCard.tsx Integrated useKnowledgeUpdate hook and added loading state for knowledge updates.
client/app/hooks/useKnowledgeUpdate.ts Added a new hook to manage knowledge updates using useMutation.
client/app/services/BotsController.ts Created updateKnowledge API to handle knowledge updates.
petercat_utils/rag_helper/git_doc_task.py Refactored to use check_and_update_knowledge instead of add_knowledge_by_doc.
petercat_utils/rag_helper/retrieval.py Implemented check_and_update_knowledge function to handle document changes and updates.
server/rag/router.py Added new endpoint for updating knowledge with validation of bot existence.

class UpdateKnowledgeRequest(BaseModel):
bot_id: str

@router.post("/rag/update_knowledge", dependencies=[Depends(verify_rate_limit)])

Choose a reason for hiding this comment

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

Consider adding authentication checks to ensure that only authorized users can update the knowledge of a bot. This will prevent unauthorized access and potential misuse of the update functionality.

Comment on lines +209 to +215
existing_docs = (
client.table(TABLE_NAME)
.select("id, file_sha")
.eq("repo_name", config.repo_name)
.eq("file_path", config.file_path)
.execute()
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

我本地跑这里总超时, 不知道为啥, 还没能解决

Copy link
Contributor Author

Choose a reason for hiding this comment

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

'canceling statement due to statement timeout'

Copy link
Contributor

Choose a reason for hiding this comment

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

see this issue #531

export function useKnowledgeUpdate() {
return useMutation({
mutationKey: ['updateKnowledge'],
mutationFn: updateKnowledge
Copy link
Contributor

Choose a reason for hiding this comment

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

在完成更新后,可以将 useGetBotRagTask client 重刷一遍,更新下 taskInfo,这样可以让 BotCard 组件下的 任务状态 ICON 转起来

Copy link

codecov bot commented Dec 20, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
petercat_utils/rag_helper/git_doc_task.py 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
petercat_utils/rag_helper/retrieval.py 28.98% <ø> (ø)
server/rag/router.py 37.50% <100.00%> (ø)
petercat_utils/rag_helper/git_doc_task.py 24.59% <0.00%> (ø)

... and 2 files with indirect coverage changes

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.

3 participants