fix: knowledge files issue

This commit is contained in:
Timothy Jaeryang Baek 2024-11-20 10:02:14 -08:00
parent 4156b62811
commit 2b890cf747

View File

@ -43,6 +43,7 @@ async def get_knowledge(user=Depends(get_verified_user)):
knowledge_bases = Knowledges.get_knowledge_bases_by_user_id(user.id, "read") knowledge_bases = Knowledges.get_knowledge_bases_by_user_id(user.id, "read")
# Get files for each knowledge base # Get files for each knowledge base
knowledge_with_files = []
for knowledge_base in knowledge_bases: for knowledge_base in knowledge_bases:
files = [] files = []
if knowledge_base.data: if knowledge_base.data:
@ -70,12 +71,14 @@ async def get_knowledge(user=Depends(get_verified_user)):
files = Files.get_file_metadatas_by_ids(file_ids) files = Files.get_file_metadatas_by_ids(file_ids)
knowledge_base = KnowledgeResponse( knowledge_with_files.append(
**knowledge_base.model_dump(), KnowledgeUserResponse(
files=files, **knowledge_base.model_dump(),
files=files,
)
) )
return knowledge_bases return knowledge_with_files
@router.get("/list", response_model=list[KnowledgeUserResponse]) @router.get("/list", response_model=list[KnowledgeUserResponse])
@ -88,6 +91,7 @@ async def get_knowledge_list(user=Depends(get_verified_user)):
knowledge_bases = Knowledges.get_knowledge_bases_by_user_id(user.id, "write") knowledge_bases = Knowledges.get_knowledge_bases_by_user_id(user.id, "write")
# Get files for each knowledge base # Get files for each knowledge base
knowledge_with_files = []
for knowledge_base in knowledge_bases: for knowledge_base in knowledge_bases:
files = [] files = []
if knowledge_base.data: if knowledge_base.data:
@ -115,12 +119,13 @@ async def get_knowledge_list(user=Depends(get_verified_user)):
files = Files.get_file_metadatas_by_ids(file_ids) files = Files.get_file_metadatas_by_ids(file_ids)
knowledge_base = KnowledgeResponse( knowledge_with_files.append(
**knowledge_base.model_dump(), KnowledgeUserResponse(
files=files, **knowledge_base.model_dump(),
files=files,
)
) )
return knowledge_with_files
return knowledge_bases
############################ ############################