feat: 增加案例/任务日志/LLM配置/系统配置管理功能\n\n- 扩展案例数据至30个\n- 新增Case, TaskLog, LLMConfig, SystemConfig的API路由\n- 完善initial_data导入脚本\n- 创建前端管理页面admin.html,支持完整增删改查\n- 更新导航菜单,增加系统管理入口
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import Case
|
||||
from ..schemas import CaseBase, CaseResponse
|
||||
|
||||
router = APIRouter(prefix="/api/admin/cases", tags=["admin"])
|
||||
|
||||
def get_current_admin(request: Request, db: Session = Depends(get_db)):
|
||||
"""依赖项:验证管理员权限"""
|
||||
from .auth import verify_token
|
||||
auth_header = request.headers.get("Authorization")
|
||||
if not auth_header or not auth_header.startswith("Bearer "):
|
||||
raise HTTPException(status_code=401, detail="未提供认证令牌")
|
||||
token = auth_header.split(" ")[1]
|
||||
user = verify_token(token, db)
|
||||
if user.role != "admin":
|
||||
raise HTTPException(status_code=403, detail="需要管理员权限")
|
||||
return user
|
||||
|
||||
@router.get("", response_model=List[CaseResponse])
|
||||
def list_cases(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""获取案例列表(管理员)"""
|
||||
cases = db.query(Case).all()
|
||||
return [CaseResponse.from_orm(c) for c in cases]
|
||||
|
||||
@router.get("/{case_id}", response_model=CaseResponse)
|
||||
def get_case(
|
||||
case_id: int,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""获取单个案例详情"""
|
||||
case = db.query(Case).filter(Case.id == case_id).first()
|
||||
if not case:
|
||||
raise HTTPException(status_code=404, detail="案例不存在")
|
||||
return case
|
||||
|
||||
@router.post("", response_model=CaseResponse)
|
||||
def create_case(
|
||||
case_data: CaseBase,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""创建新案例"""
|
||||
existing = db.query(Case).filter(Case.id == case_data.id).first()
|
||||
if existing:
|
||||
raise HTTPException(status_code=400, detail="案例ID已存在")
|
||||
case = Case(**case_data.dict())
|
||||
db.add(case)
|
||||
db.commit()
|
||||
db.refresh(case)
|
||||
return case
|
||||
|
||||
@router.put("/{case_id}", response_model=CaseResponse)
|
||||
def update_case(
|
||||
case_id: int,
|
||||
case_update: CaseBase,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""更新案例"""
|
||||
case = db.query(Case).filter(Case.id == case_id).first()
|
||||
if not case:
|
||||
raise HTTPException(status_code=404, detail="案例不存在")
|
||||
update_data = case_update.dict(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(case, field, value)
|
||||
db.commit()
|
||||
db.refresh(case)
|
||||
return case
|
||||
|
||||
@router.delete("/{case_id}")
|
||||
def delete_case(
|
||||
case_id: int,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""删除案例"""
|
||||
case = db.query(Case).filter(Case.id == case_id).first()
|
||||
if not case:
|
||||
raise HTTPException(status_code=404, detail="案例不存在")
|
||||
db.delete(case)
|
||||
db.commit()
|
||||
return {"message": "删除成功"}
|
||||
@@ -0,0 +1,92 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import LLMConfig
|
||||
from ..schemas import LLMConfigBase, LLMConfigResponse
|
||||
|
||||
router = APIRouter(prefix="/api/admin/llmconfigs", tags=["admin"])
|
||||
|
||||
def get_current_admin(request: Request, db: Session = Depends(get_db)):
|
||||
"""依赖项:验证管理员权限"""
|
||||
from .auth import verify_token
|
||||
auth_header = request.headers.get("Authorization")
|
||||
if not auth_header or not auth_header.startswith("Bearer "):
|
||||
raise HTTPException(status_code=401, detail="未提供认证令牌")
|
||||
token = auth_header.split(" ")[1]
|
||||
user = verify_token(token, db)
|
||||
if user.role != "admin":
|
||||
raise HTTPException(status_code=403, detail="需要管理员权限")
|
||||
return user
|
||||
|
||||
@router.get("", response_model=List[LLMConfigResponse])
|
||||
def list_llm_configs(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""获取 LLM 配置列表"""
|
||||
configs = db.query(LLMConfig).all()
|
||||
return [LLMConfigResponse.from_orm(c) for c in configs]
|
||||
|
||||
@router.get("/{config_id}", response_model=LLMConfigResponse)
|
||||
def get_llm_config(
|
||||
config_id: int,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""获取单个 LLM 配置详情"""
|
||||
config = db.query(LLMConfig).filter(LLMConfig.id == config_id).first()
|
||||
if not config:
|
||||
raise HTTPException(status_code=404, detail="配置不存在")
|
||||
return config
|
||||
|
||||
@router.post("", response_model=LLMConfigResponse)
|
||||
def create_llm_config(
|
||||
config_data: LLMConfigBase,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""创建 LLM 配置"""
|
||||
config = LLMConfig(**config_data.dict())
|
||||
db.add(config)
|
||||
db.commit()
|
||||
db.refresh(config)
|
||||
return config
|
||||
|
||||
@router.put("/{config_id}", response_model=LLMConfigResponse)
|
||||
def update_llm_config(
|
||||
config_id: int,
|
||||
config_update: LLMConfigBase,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""更新 LLM 配置"""
|
||||
config = db.query(LLMConfig).filter(LLMConfig.id == config_id).first()
|
||||
if not config:
|
||||
raise HTTPException(status_code=404, detail="配置不存在")
|
||||
update_data = config_update.dict(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(config, field, value)
|
||||
db.commit()
|
||||
db.refresh(config)
|
||||
return config
|
||||
|
||||
@router.delete("/{config_id}")
|
||||
def delete_llm_config(
|
||||
config_id: int,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""删除 LLM 配置"""
|
||||
config = db.query(LLMConfig).filter(LLMConfig.id == config_id).first()
|
||||
if not config:
|
||||
raise HTTPException(status_code=404, detail="配置不存在")
|
||||
db.delete(config)
|
||||
db.commit()
|
||||
return {"message": "删除成功"}
|
||||
@@ -0,0 +1,129 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Dict, Any
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import SystemConfig
|
||||
from ..schemas import SystemConfigBase, SystemConfigResponse
|
||||
|
||||
router = APIRouter(prefix="/api/admin/systemconfigs", tags=["admin"])
|
||||
|
||||
def get_current_admin(request: Request, db: Session = Depends(get_db)):
|
||||
"""依赖项:验证管理员权限"""
|
||||
from .auth import verify_token
|
||||
auth_header = request.headers.get("Authorization")
|
||||
if not auth_header or not auth_header.startswith("Bearer "):
|
||||
raise HTTPException(status_code=401, detail="未提供认证令牌")
|
||||
token = auth_header.split(" ")[1]
|
||||
user = verify_token(token, db)
|
||||
if user.role != "admin":
|
||||
raise HTTPException(status_code=403, detail="需要管理员权限")
|
||||
return user
|
||||
|
||||
@router.get("", response_model=List[SystemConfigResponse])
|
||||
def list_system_configs(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""获取所有系统配置(键值对列表)"""
|
||||
configs = db.query(SystemConfig).all()
|
||||
# 将 value 解析为 JSON(如果是 JSON 字符串)
|
||||
result = []
|
||||
for c in configs:
|
||||
resp = SystemConfigResponse.from_orm(c)
|
||||
# 尝试解析 value 为 JSON
|
||||
if c.value:
|
||||
try:
|
||||
import json
|
||||
resp.value = json.loads(c.value)
|
||||
except Exception:
|
||||
pass # 保持原字符串
|
||||
result.append(resp)
|
||||
return result
|
||||
|
||||
@router.get("/{config_key}", response_model=SystemConfigResponse)
|
||||
def get_system_config(
|
||||
config_key: str,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""获取单个系统配置"""
|
||||
config = db.query(SystemConfig).filter(SystemConfig.key == config_key).first()
|
||||
if not config:
|
||||
raise HTTPException(status_code=404, detail="配置不存在")
|
||||
resp = SystemConfigResponse.from_orm(config)
|
||||
if config.value:
|
||||
try:
|
||||
import json
|
||||
resp.value = json.loads(config.value)
|
||||
except Exception:
|
||||
pass
|
||||
return resp
|
||||
|
||||
@router.post("", response_model=SystemConfigResponse)
|
||||
def create_system_config(
|
||||
config_data: SystemConfigBase,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""创建或更新系统配置(UPSERT)"""
|
||||
# key 是主键,如果已存在则更新
|
||||
existing = db.query(SystemConfig).filter(SystemConfig.key == config_data.key).first()
|
||||
if existing:
|
||||
# 若已存在,更新字段
|
||||
if config_data.value is not None:
|
||||
# 若 value 是 dict/list,转为 JSON 字符串存储
|
||||
if isinstance(config_data.value, (dict, list)):
|
||||
import json
|
||||
existing.value = json.dumps(config_data.value, ensure_ascii=False)
|
||||
else:
|
||||
existing.value = str(config_data.value)
|
||||
if config_data.description is not None:
|
||||
existing.description = config_data.description
|
||||
db.commit()
|
||||
db.refresh(existing)
|
||||
resp = SystemConfigResponse.from_orm(existing)
|
||||
if existing.value:
|
||||
try:
|
||||
import json
|
||||
resp.value = json.loads(existing.value)
|
||||
except Exception:
|
||||
pass
|
||||
return resp
|
||||
else:
|
||||
# 新建
|
||||
data = config_data.dict()
|
||||
# 将 value 转为字符串(如果是复杂类型则 JSON)
|
||||
if isinstance(data.get('value'), (dict, list)):
|
||||
import json
|
||||
data['value'] = json.dumps(data['value'], ensure_ascii=False)
|
||||
config = SystemConfig(**data)
|
||||
db.add(config)
|
||||
db.commit()
|
||||
db.refresh(config)
|
||||
resp = SystemConfigResponse.from_orm(config)
|
||||
if config.value:
|
||||
try:
|
||||
import json
|
||||
resp.value = json.loads(config.value)
|
||||
except Exception:
|
||||
pass
|
||||
return resp
|
||||
|
||||
@router.delete("/{config_key}")
|
||||
def delete_system_config(
|
||||
config_key: str,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""删除系统配置"""
|
||||
config = db.query(SystemConfig).filter(SystemConfig.key == config_key).first()
|
||||
if not config:
|
||||
raise HTTPException(status_code=404, detail="配置不存在")
|
||||
db.delete(config)
|
||||
db.commit()
|
||||
return {"message": "删除成功"}
|
||||
@@ -0,0 +1,102 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import List, Optional
|
||||
|
||||
from ..database import get_db
|
||||
from ..models import TaskLog
|
||||
from ..schemas import TaskLogBase, TaskLogResponse
|
||||
|
||||
router = APIRouter(prefix="/api/admin/tasklogs", tags=["admin"])
|
||||
|
||||
def get_current_admin(request: Request, db: Session = Depends(get_db)):
|
||||
"""依赖项:验证管理员权限"""
|
||||
from .auth import verify_token
|
||||
auth_header = request.headers.get("Authorization")
|
||||
if not auth_header or not auth_header.startswith("Bearer "):
|
||||
raise HTTPException(status_code=401, detail="未提供认证令牌")
|
||||
token = auth_header.split(" ")[1]
|
||||
user = verify_token(token, db)
|
||||
if user.role != "admin":
|
||||
raise HTTPException(status_code=403, detail="需要管理员权限")
|
||||
return user
|
||||
|
||||
@router.get("", response_model=List[TaskLogResponse])
|
||||
def list_task_logs(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin),
|
||||
topic_id: Optional[str] = None,
|
||||
task_name: Optional[str] = None,
|
||||
status: Optional[str] = None
|
||||
):
|
||||
"""获取任务日志列表(可过滤)"""
|
||||
query = db.query(TaskLog)
|
||||
if topic_id:
|
||||
query = query.filter(TaskLog.topic_id == topic_id)
|
||||
if task_name:
|
||||
query = query.filter(TaskLog.task_name == task_name)
|
||||
if status:
|
||||
query = query.filter(TaskLog.status == status)
|
||||
logs = query.order_by(TaskLog.started_at.desc()).all()
|
||||
return [TaskLogResponse.from_orm(l) for l in logs]
|
||||
|
||||
@router.get("/{log_id}", response_model=TaskLogResponse)
|
||||
def get_task_log(
|
||||
log_id: int,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""获取单个任务日志详情"""
|
||||
log = db.query(TaskLog).filter(TaskLog.id == log_id).first()
|
||||
if not log:
|
||||
raise HTTPException(status_code=404, detail="日志不存在")
|
||||
return log
|
||||
|
||||
@router.post("", response_model=TaskLogResponse)
|
||||
def create_task_log(
|
||||
log_data: TaskLogBase,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""创建任务日志(用于手动记录)"""
|
||||
log = TaskLog(**log_data.dict())
|
||||
db.add(log)
|
||||
db.commit()
|
||||
db.refresh(log)
|
||||
return log
|
||||
|
||||
@router.put("/{log_id}", response_model=TaskLogResponse)
|
||||
def update_task_log(
|
||||
log_id: int,
|
||||
log_update: TaskLogBase,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""更新任务日志"""
|
||||
log = db.query(TaskLog).filter(TaskLog.id == log_id).first()
|
||||
if not log:
|
||||
raise HTTPException(status_code=404, detail="日志不存在")
|
||||
update_data = log_update.dict(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(log, field, value)
|
||||
db.commit()
|
||||
db.refresh(log)
|
||||
return log
|
||||
|
||||
@router.delete("/{log_id}")
|
||||
def delete_task_log(
|
||||
log_id: int,
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
admin_user = Depends(get_current_admin)
|
||||
):
|
||||
"""删除任务日志"""
|
||||
log = db.query(TaskLog).filter(TaskLog.id == log_id).first()
|
||||
if not log:
|
||||
raise HTTPException(status_code=404, detail="日志不存在")
|
||||
db.delete(log)
|
||||
db.commit()
|
||||
return {"message": "删除成功"}
|
||||
@@ -3,7 +3,7 @@ import os
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from .database import SessionLocal, init_db
|
||||
from .models import Topic, User
|
||||
from .models import Topic, User, Case, LLMConfig, SystemConfig
|
||||
import bcrypt
|
||||
|
||||
# 计算项目根目录(backend/app/initial_data.py -> 上升3层到 yu-zhi-ran)
|
||||
@@ -11,6 +11,7 @@ PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
if os.getenv('PROJECT_ROOT'):
|
||||
PROJECT_ROOT = Path(os.getenv('PROJECT_ROOT'))
|
||||
TOPICS_FILE = PROJECT_ROOT / "automation" / "data" / "sustainability_topics.json"
|
||||
CASES_FILE = PROJECT_ROOT / "automation" / "data" / "initial_cases.json"
|
||||
|
||||
# 从环境变量读取管理员配置
|
||||
DEFAULT_ADMIN_USERNAME = os.getenv('DEFAULT_ADMIN_USERNAME', 'admin')
|
||||
@@ -56,7 +57,78 @@ def import_initial_data():
|
||||
else:
|
||||
print("数据库已有选题数据,跳过导入")
|
||||
|
||||
# 2. 创建默认管理员用户(bcrypt 哈希)
|
||||
|
||||
# 3. 导入案例数据(如果为空)
|
||||
if db.query(Case).count() == 0:
|
||||
if __import__('os').path.exists(CASES_FILE):
|
||||
cases_data = json.loads(open(CASES_FILE, encoding='utf-8').read())
|
||||
for c in cases_data:
|
||||
case = Case(
|
||||
id=c['id'],
|
||||
title=c['title'],
|
||||
field=c['field'],
|
||||
summary=c['summary'],
|
||||
key_metrics=c.get('key_metrics'),
|
||||
date=c.get('date'),
|
||||
source=c['source'],
|
||||
source_url=c.get('source_url'),
|
||||
credibility_rating=c.get('credibility_rating'),
|
||||
china_applicability=c.get('china_applicability')
|
||||
)
|
||||
db.add(case)
|
||||
db.commit()
|
||||
print(f"✅ 导入 {len(cases_data)} 条案例")
|
||||
else:
|
||||
print(f"⚠️ 案例文件不存在: {CASES_FILE}")
|
||||
|
||||
# 4. 插入 LLM 默认配置
|
||||
if db.query(LLMConfig).count() == 0:
|
||||
default_llm = LLMConfig(
|
||||
name="default_expand",
|
||||
system_prompt="你是一个专业的内容创作者。",
|
||||
user_prompt_template="""你是一个专业的内容创作者,风格精炼、直接、切中要点。请将以下大纲扩展为完整的文章章节,要求如下:
|
||||
|
||||
### 选题信息
|
||||
标题:{topic.get('title')}
|
||||
领域:{topic.get('field')}
|
||||
核心观点:{topic.get('core_concept', '')}
|
||||
受众痛点:{topic.get('audience_pain', '')}
|
||||
独特视角:{topic.get('unique_angle', '')}
|
||||
|
||||
### 当前章节
|
||||
## {section_title}
|
||||
{section_content}
|
||||
|
||||
### 输出要求
|
||||
- 以 "## {section_title}" 开始
|
||||
- 字数:200-300 字(精炼为主)
|
||||
- 语言:直白、有冲击力,避免空洞套话
|
||||
- 使用 Markdown 格式
|
||||
- 每个论点配具体案例或数据支撑
|
||||
- 确保与整体文章调性一致
|
||||
|
||||
直接输出完整 Markdown 章节(包括标题和正文)。""",
|
||||
temperature=0.8,
|
||||
max_tokens=1000,
|
||||
model="stepfun-ai/step-3.5-flash",
|
||||
is_active=True
|
||||
)
|
||||
db.add(default_llm)
|
||||
db.commit()
|
||||
print("✅ 插入默认 LLM 配置")
|
||||
|
||||
# 5. 插入系统配置默认值
|
||||
default_system_configs = [
|
||||
{"key": "collector_enabled", "value": "false", "description": "是否启用采集器"},
|
||||
{"key": "scheduler_interval", "value": "daily", "description": "调度间隔:daily/hourly/weekly"},
|
||||
]
|
||||
for cfg in default_system_configs:
|
||||
if db.query(SystemConfig).filter(SystemConfig.key == cfg["key"]).first() is None:
|
||||
db.add(SystemConfig(**cfg))
|
||||
db.commit()
|
||||
print("✅ 插入默认系统配置")
|
||||
|
||||
# 2. 创建默认管理员用户(bcrypt 哈希)
|
||||
admin_exists = db.query(User).filter(User.username == DEFAULT_ADMIN_USERNAME).first()
|
||||
if not admin_exists:
|
||||
hashed = bcrypt.hashpw(DEFAULT_ADMIN_PASSWORD.encode('utf-8'), bcrypt.gensalt())
|
||||
|
||||
@@ -9,7 +9,7 @@ from pathlib import Path
|
||||
|
||||
from .database import engine, get_db, init_db
|
||||
from .models import Base
|
||||
from .api import topics, system, articles, publishing, auth, admin, audit, optimizer_logs
|
||||
from .api import topics, system, articles, publishing, auth, admin, audit, optimizer_logs, cases, task_logs, llm_configs, system_configs
|
||||
from .initial_data import import_initial_data
|
||||
|
||||
app = FastAPI(title="宇之然内容创作平台", version="0.1.0")
|
||||
@@ -38,6 +38,10 @@ app.include_router(auth.router)
|
||||
app.include_router(admin.router)
|
||||
app.include_router(audit.router)
|
||||
app.include_router(optimizer_logs.router)
|
||||
app.include_router(cases.router)
|
||||
app.include_router(task_logs.router)
|
||||
app.include_router(llm_configs.router)
|
||||
app.include_router(system_configs.router)
|
||||
|
||||
# 挂载前端
|
||||
FRONTEND_DIR = Path(__file__).parent.parent.parent / "frontend"
|
||||
|
||||
@@ -135,3 +135,69 @@ class AuditLogResponse(BaseModel):
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# --- 案例库 Schema ---
|
||||
class CaseBase(BaseModel):
|
||||
title: str
|
||||
field: str
|
||||
summary: str
|
||||
key_metrics: Optional[str] = None
|
||||
date: Optional[str] = None
|
||||
source: str
|
||||
source_url: Optional[str] = None
|
||||
credibility_rating: Optional[str] = None
|
||||
china_applicability: Optional[str] = None
|
||||
|
||||
class CaseResponse(CaseBase):
|
||||
id: int
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# --- 任务日志 Schema ---
|
||||
class TaskLogBase(BaseModel):
|
||||
task_name: str
|
||||
topic_id: Optional[str] = None
|
||||
status: str
|
||||
message: Optional[str] = None
|
||||
started_at: Optional[datetime] = None
|
||||
finished_at: Optional[datetime] = None
|
||||
duration_seconds: Optional[int] = None
|
||||
|
||||
class TaskLogResponse(TaskLogBase):
|
||||
id: int
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# --- LLM 配置 Schema ---
|
||||
class LLMConfigBase(BaseModel):
|
||||
name: str
|
||||
system_prompt: Optional[str] = None
|
||||
user_prompt_template: str
|
||||
temperature: float = 0.7
|
||||
max_tokens: int = 2000
|
||||
model: Optional[str] = None
|
||||
is_active: bool = True
|
||||
|
||||
class LLMConfigResponse(LLMConfigBase):
|
||||
id: int
|
||||
created_at: Optional[datetime] = None
|
||||
updated_at: Optional[datetime] = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
# --- 系统配置 Schema ---
|
||||
class SystemConfigBase(BaseModel):
|
||||
key: str
|
||||
value: Optional[str] = None
|
||||
description: Optional[str] = None
|
||||
|
||||
class SystemConfigResponse(SystemConfigBase):
|
||||
updated_at: Optional[datetime] = None
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user