Skip to content
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
11 changes: 7 additions & 4 deletions app/api/v1/endpoints/aichat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@ async def ai_stream():

@router.get("/graph", response_model=dict)
async def generate_graph(
note_id: int,
article_id: int,
db : AsyncSession = Depends(get_db),
):
# 读取数据库获取笔记内容
from app.curd.note import get_note_by_id
note = await get_note_by_id(db, note_id)
if not note:
notes = await get_note_by_id(db, article_id)
if not notes:
raise HTTPException(status_code=404, detail="Note not found")
text = note.content
text = f"以下是关于文章ID {article_id} 的笔记内容:\n\n"
for note in notes:
text += f"标题: {note.title}\n" if note.title else ""
text += note.content if note.content else ""
text += """
我需要你对于上面的内容生成思维导图,请仅给我返回mermaid代码,不要有其他内容,下面是生成样例,
graph TD
Expand Down
8 changes: 5 additions & 3 deletions app/curd/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,12 @@ async def find_self_notes_count_in_db(db: AsyncSession, user_id: int):
count = result.scalar_one_or_none()
return count

async def get_note_by_id(db: AsyncSession, note_id: int):
async def get_note_by_id(db: AsyncSession, article_id: int):
"""
根据 ID 获取笔记
"""
stmt = select(Note).where(Note.id == note_id, Note.visible == True)
stmt = select(Note).where(Note.article_id == article_id and Note.visible == True)
result = await db.execute(stmt)
return result.scalar_one_or_none() # 返回单个笔记或 None
# 返回所有笔记
notes = result.scalars().all()
return notes if notes else None