feat: 添加飞书用户模块和订阅功能支持 - 新增feishu_users模块用于处理飞书用户身份验证和权限管理 - 新增subscriptions模块用于处理订阅相关功能 - 新增personalization模块用于个性化服务 - 在alembic迁移配置中注册新的模型模块 - 在API路由器中添加feishu_users和subscriptions路由 - 实现事件调度服务的改进,包括错误处理和状态更新优化 - 添加飞书命令处理的权限检查机制 - 实现飞书应用票据事件处理 - 改进审计日志记录功能 ```
65 lines
1.8 KiB
Python
65 lines
1.8 KiB
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from app.core.database import get_db
|
|
from app.core.security import ApiPrincipal, require_api_key
|
|
from app.modules.audit.constants import AuditSource
|
|
from app.modules.ai_agent.schemas import (
|
|
AIAskRequest,
|
|
AIAskResponse,
|
|
DraftPolicyRequest,
|
|
InvestmentResearchRequest,
|
|
)
|
|
from app.modules.ai_agent.service import AIService
|
|
|
|
router = APIRouter(dependencies=[Depends(require_api_key)])
|
|
|
|
|
|
@router.post("/ask", response_model=AIAskResponse)
|
|
def ask(
|
|
payload: AIAskRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).ask(
|
|
payload.prompt,
|
|
payload.context,
|
|
actor=principal.actor,
|
|
source=AuditSource.API,
|
|
)
|
|
|
|
|
|
@router.get("/provider-health")
|
|
def provider_health(
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).provider_health(actor=principal.actor)
|
|
|
|
|
|
@router.post("/draft-policy", response_model=AIAskResponse)
|
|
def draft_policy(
|
|
payload: DraftPolicyRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).draft_policy(
|
|
title=payload.title,
|
|
policy_type=payload.policy_type,
|
|
requirements=payload.requirements,
|
|
actor=principal.actor,
|
|
)
|
|
|
|
|
|
@router.post("/investment-research", response_model=AIAskResponse)
|
|
def investment_research(
|
|
payload: InvestmentResearchRequest,
|
|
db: Session = Depends(get_db),
|
|
principal: ApiPrincipal = Depends(require_api_key),
|
|
) -> dict:
|
|
return AIService(db).draft_investment_research(
|
|
symbol_or_topic=payload.symbol_or_topic,
|
|
risk_preference=payload.risk_preference,
|
|
actor=principal.actor,
|
|
)
|