2025-03-14 03:28:53 +08:00
|
|
|
from fastapi import Request, Body
|
2024-10-02 20:11:28 +08:00
|
|
|
from fastapi import APIRouter
|
2025-03-16 01:11:13 +08:00
|
|
|
from fastapi import Request, Body
|
2024-10-02 20:11:28 +08:00
|
|
|
|
|
|
|
|
base = APIRouter()
|
|
|
|
|
|
2025-03-20 19:51:46 +08:00
|
|
|
from src import config, retriever, knowledge_base, graph_base
|
2025-02-27 19:35:25 +08:00
|
|
|
from src.utils import logger
|
2024-10-02 20:11:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@base.get("/")
|
|
|
|
|
async def route_index():
|
|
|
|
|
return {"message": "You Got It!"}
|
|
|
|
|
|
|
|
|
|
@base.get("/config")
|
2024-10-14 22:10:56 +08:00
|
|
|
def get_config():
|
2025-03-16 13:27:08 +08:00
|
|
|
return config.get_safe_config()
|
2024-10-02 20:11:28 +08:00
|
|
|
|
|
|
|
|
@base.post("/config")
|
2024-10-24 13:09:59 +08:00
|
|
|
async def update_config(key = Body(...), value = Body(...)):
|
2025-03-14 03:28:53 +08:00
|
|
|
if key == "custom_models":
|
2025-03-16 13:27:08 +08:00
|
|
|
value = config.compare_custom_models(value)
|
2025-03-14 03:28:53 +08:00
|
|
|
|
2025-03-16 01:11:13 +08:00
|
|
|
config[key] = value
|
|
|
|
|
config.save()
|
2025-03-16 13:27:08 +08:00
|
|
|
return config.get_safe_config()
|
2024-10-02 20:11:28 +08:00
|
|
|
|
|
|
|
|
@base.post("/restart")
|
|
|
|
|
async def restart():
|
2025-03-20 19:51:46 +08:00
|
|
|
knowledge_base.restart()
|
2025-04-05 17:27:52 +08:00
|
|
|
graph_base.start()
|
2025-03-16 01:11:13 +08:00
|
|
|
retriever.restart()
|
2024-10-02 20:11:28 +08:00
|
|
|
return {"message": "Restarted!"}
|
|
|
|
|
|
|
|
|
|
@base.get("/log")
|
2024-10-14 22:10:56 +08:00
|
|
|
def get_log():
|
2024-10-02 20:11:28 +08:00
|
|
|
from src.utils.logging_config import LOG_FILE
|
|
|
|
|
from collections import deque
|
|
|
|
|
|
|
|
|
|
with open(LOG_FILE, 'r') as f:
|
|
|
|
|
last_lines = deque(f, maxlen=1000)
|
|
|
|
|
|
|
|
|
|
log = ''.join(last_lines)
|
2025-02-28 00:38:59 +08:00
|
|
|
return {"log": log, "message": "success", "log_file": LOG_FILE}
|
2024-10-02 20:11:28 +08:00
|
|
|
|
|
|
|
|
|