feat: QYLAW 法律法规知识库
- 语义检索(FAISS + embedding)+ 精确查找(法规名+条号) - RAG 问答(SSE 流式,支持 thinking 折叠显示) - 法规浏览(原文阅读) - 历史记录(检索+对话持久化到 SQLite) - 设置页(系统提示词/模板/LLM 参数可配置) - 检索质量评估脚本 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
"""提示词配置 API — /api/prompts"""
|
||||
from fastapi import APIRouter, Request
|
||||
from pydantic import BaseModel
|
||||
from typing import Optional
|
||||
|
||||
from app.services.prompt_config import (
|
||||
get_all_configs,
|
||||
set_config,
|
||||
get_llm_params,
|
||||
DEFAULTS,
|
||||
TEMPLATE_KEY_MAP,
|
||||
)
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
class PromptUpdateRequest(BaseModel):
|
||||
"""提示词更新请求"""
|
||||
system_prompt: Optional[str] = None
|
||||
template_simple: Optional[str] = None
|
||||
template_professional: Optional[str] = None
|
||||
template_compare: Optional[str] = None
|
||||
# LLM 参数
|
||||
llm_thinking_enabled: Optional[str] = None # "true" / "false"
|
||||
llm_max_tokens: Optional[str] = None # 字符串,后端转 int
|
||||
llm_temperature: Optional[str] = None # 字符串,后端转 float
|
||||
llm_thinking_budget: Optional[str] = None # 字符串,后端转 int
|
||||
|
||||
|
||||
@router.get("/prompts")
|
||||
async def get_prompts(request: Request):
|
||||
"""获取所有提示词配置(含默认值)"""
|
||||
trace_id = getattr(request.state, "trace_id", "")
|
||||
configs = get_all_configs()
|
||||
return {
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": {
|
||||
"configs": configs,
|
||||
"defaults": DEFAULTS,
|
||||
"template_keys": list(TEMPLATE_KEY_MAP.keys()),
|
||||
"llm_params": get_llm_params(),
|
||||
},
|
||||
"trace_id": trace_id,
|
||||
}
|
||||
|
||||
|
||||
@router.put("/prompts")
|
||||
async def update_prompts(req: PromptUpdateRequest, request: Request):
|
||||
"""更新提示词配置(空字符串表示恢复默认)"""
|
||||
trace_id = getattr(request.state, "trace_id", "")
|
||||
updated = []
|
||||
# 系统提示词
|
||||
if req.system_prompt is not None:
|
||||
if set_config("system_prompt", req.system_prompt):
|
||||
updated.append("system_prompt")
|
||||
# 模板正文
|
||||
for tpl_key in ["template_simple", "template_professional", "template_compare"]:
|
||||
val = getattr(req, tpl_key, None)
|
||||
if val is not None:
|
||||
if set_config(tpl_key, val):
|
||||
updated.append(tpl_key)
|
||||
# LLM 参数
|
||||
for llm_key in ["llm_thinking_enabled", "llm_max_tokens", "llm_temperature", "llm_thinking_budget"]:
|
||||
val = getattr(req, llm_key, None)
|
||||
if val is not None:
|
||||
if set_config(llm_key, val):
|
||||
updated.append(llm_key)
|
||||
return {
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": {"updated": updated},
|
||||
"trace_id": trace_id,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/prompts/reset")
|
||||
async def reset_prompts(request: Request):
|
||||
"""重置所有提示词配置为默认值"""
|
||||
trace_id = getattr(request.state, "trace_id", "")
|
||||
for key in DEFAULTS.keys():
|
||||
set_config(key, "")
|
||||
return {
|
||||
"code": 0,
|
||||
"message": "ok",
|
||||
"data": {"reset": list(DEFAULTS.keys())},
|
||||
"trace_id": trace_id,
|
||||
}
|
||||
Reference in New Issue
Block a user