读取本地chatandrole初步成功

This commit is contained in:
2026-03-19 19:31:12 +08:00
parent 4b85b35cf8
commit 91d11abe90
9 changed files with 69 additions and 50 deletions

View File

@@ -1,18 +1,18 @@
from fastapi import FastAPI
# 假设这些函数已经在其他地方定义
from backend.core.items import ChatRequest
from backend.tools.get_all_role_and_chat import get_all_role_and_chat as get_chat_file
from fastapi import APIRouter
from ..core.items import ChatRequest
from ..tools.get_all_role_and_chat import get_all_role_and_chat
from ..tools.save_input_to_json import save_input_to_json
app = FastAPI()
router = APIRouter()
# 1. 将输入内容持久化存储到本地jsonl方便前端读
@app.post("/generate_reply")
async def save_input_to_json(chat_request: ChatRequest):
return 0
@router.post("/generate_reply")
async def save_chat_to_json(chat_request: ChatRequest):
# 调用实际的保存函数
return await save_input_to_json(chat_request)
# 2. 从本地jsonl中读取历史对话
@app.get("/api/get_all_role_and_chat")
def get_all_role_and_chat():
# 直接调用导入的函数
result = get_chat_file()
return result
@router.get("/tool_bar/get_all_role_and_chat")
def get_all_role_and_chat_endpoint():
# 正确调用函数并返回结果
return get_all_role_and_chat()