Skip to content

Commit

Permalink
fix content display of full documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Leg0shii committed Oct 1, 2024
1 parent 46c1afa commit e4978b2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions backend/app/ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
logger = logging.getLogger(__name__)


async def generate_summary(file_path: str) -> str:
async def generate_summary(file_path: str) -> dict[str, str | list[str | dict]]:
try:
with open(file_path, "r", encoding="utf-8") as f:
text = f.read()
Expand All @@ -38,8 +38,7 @@ async def generate_summary(file_path: str) -> str:
None, lambda: chat_llm.invoke(prompt)
)

summary = summary_message.content

summary = {"summary": summary_message.content, "full_text": text}
logger.info("Summary generated successfully.")
return summary

Expand Down
2 changes: 1 addition & 1 deletion backend/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Document(Base):
user_id = Column(Integer, ForeignKey("users.id"), nullable=False)
title = Column(String(255), nullable=False, index=True)
description = Column(Text, nullable=True)
# content = Column(Text)
content = Column(Text, nullable=True)
file_path = Column(String(500), nullable=False)
uploaded_at = Column(DateTime, default=datetime.utcnow)
summary = Column(Text, nullable=True)
Expand Down
5 changes: 4 additions & 1 deletion backend/app/routers/documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
async def upload_document(
title: str = Form(...),
description: Optional[str] = Form(None),
content: Optional[str] = Form(None),
tags: Optional[List[str]] = Form([]),
file: UploadFile = File(...),
db: Session = Depends(get_db),
Expand All @@ -36,6 +37,7 @@ async def upload_document(
user_id=user_id,
title=title,
description=description,
content=content,
file_path=file_path,
uploaded_at=datetime.utcnow(),
)
Expand Down Expand Up @@ -66,7 +68,8 @@ async def upload_document(
embeddings = await generate_embeddings(file_path)

# Update Document with summary
document.summary = summary
document.summary = summary["summary"]
document.content = summary["full_text"]
db.commit()
db.refresh(document)

Expand Down
2 changes: 1 addition & 1 deletion backend/app/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class DocumentDetailResponse(BaseModel):
user_id: int
title: str
description: Optional[str]
# content: str
content: Optional[str]
uploaded_at: datetime
uploader: UserBase
tags: List[str] = []
Expand Down

0 comments on commit e4978b2

Please sign in to comment.