24 lines
660 B
Python
24 lines
660 B
Python
from flask import Blueprint, jsonify
|
|
|
|
from ..conversation_store import list_conversations, load as load_conversation
|
|
|
|
bp = Blueprint("conversation", __name__, url_prefix="/api")
|
|
|
|
|
|
@bp.get("/conversations")
|
|
def conversations():
|
|
items = list_conversations()
|
|
return jsonify([{
|
|
"id": c.get('id'),
|
|
"title": c.get('title') or "未命名",
|
|
"updated_at": c.get('updated_at'),
|
|
} for c in items])
|
|
|
|
|
|
@bp.get("/conversations/<cid>")
|
|
def get_conversation(cid):
|
|
convo = load_conversation(cid)
|
|
if not convo:
|
|
return jsonify({"error": "not found"}), 404
|
|
return jsonify({"id": cid, "messages": convo.get('messages', [])})
|