- 为 AssignPermissionsEndpoint 添加请求校验器 - 为 AssignRolesEndpoint 添加请求校验器 - 为分片上传相关端点添加请求校验器 - 为聊天功能相关端点添加请求校验器 - 为知识库管理相关端点添加请求校验器 - 为用户和角色管理相关端点添加请求校验器 - 为嵌入向量化相关端点添加请求校验器 - 为认证授权相关端点添加请求校验器 - 为通知系统相关端点添加请求校验器 - 为 Obsidian 同步功能添加请求校验器 - 移除不必要的 using 语句和依赖注入配置 - 统一参数校验失败响应格式为 ValidationErrorResponse
41 lines
1.3 KiB
C#
41 lines
1.3 KiB
C#
using FastEndpoints;
|
||
using MediatR;
|
||
using RAG.Application.RagQA.Commands;
|
||
using RAG.Application.RagQA.DTOs;
|
||
|
||
namespace RAG.Api.Endpoints.RAG;
|
||
|
||
/// <summary>
|
||
/// RAG 一次性问答端点(非流式)。返回完整答案 + 命中的来源片段,
|
||
/// 适合轻量查询或非交互场景;交互式前端优先用 /rag/stream 获得流式体验。
|
||
/// </summary>
|
||
public class RAGQueryEndpoint(IMediator mediator) : Endpoint<RAGQueryRequest, RAGQueryResponse>
|
||
{
|
||
public override void Configure()
|
||
{
|
||
Post("/rag/query");
|
||
AllowAnonymous();
|
||
}
|
||
|
||
public override async Task HandleAsync(RAGQueryRequest req, CancellationToken ct)
|
||
{
|
||
var result = await mediator.Send(new RAGQueryCommand(req.KnowledgeBaseId, req.Question), ct);
|
||
await Send.OkAsync(result, ct);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// RAG 问答请求校验。/rag/query 与 /rag/stream 共用同一请求 DTO,故此校验对两个端点同时生效。
|
||
/// </summary>
|
||
public class RAGQueryRequestValidator : Validator<RAGQueryRequest>
|
||
{
|
||
public RAGQueryRequestValidator()
|
||
{
|
||
RuleFor(x => x.KnowledgeBaseId).NotEmpty().WithMessage("知识库 ID 不能为空");
|
||
|
||
RuleFor(x => x.Question)
|
||
.NotEmpty().WithMessage("问题不能为空")
|
||
.MaximumLength(1000).WithMessage("问题不能超过 1000 个字符");
|
||
}
|
||
}
|