build-flow.api/tests/BuildFlow.Rag.Tests/AiChatOutputSanitizerTests.cs
xiangning 54dc3fc26e refactor(rag): 重构AI对话和工作流集成实现
- 移除IWorkflowTriggerService接口及其实现,改用Mediator模式直接发送命令
- 更新AiBotHandler移除workflowTrigger依赖,使用新命令模式触发工作流
- 修改ApproveTaskEndpoint和RejectTaskEndpoint返回bool类型并使用Send.OkAsync
- 更新appsettings.json中AI助手的默认指令配置
- 在BuildFlowHostModule.cs中移除旧的工作流触发服务注册
- 添加SSE流式响应路径前缀配置以支持RAG聊天流
- 重构ChatAgentService使用HTTP客户端工厂和运行时配置解析
- 实现AiChatOutputSanitizer用于清洗AI输出中的模板内容
- 更新EmbeddingService使用运行时配置解析器动态创建客户端
- 调整RAG查询处理器中的系统提示指令内容
- 添加构建流按钮操作的单元测试验证发布和禁用功能
- 扩展即时消息集成测试覆盖文件消息元数据处理场景
- 更新平台权限种子数据添加按钮发布和禁用权限
- 实现AI模型运行时配置解析器支持动态模型切换
2026-07-04 21:29:37 +08:00

31 lines
950 B
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using BuildFlow.Infrastructure.AI;
using Xunit;
namespace BuildFlow.Rag.Tests;
/// <summary>
/// AI 对话输出清洗测试。确保模型模板开场不进入最终消息气泡。
/// </summary>
public class AiChatOutputSanitizerTests
{
[Fact]
public void SanitizeFinalTextShouldRemoveRagAssistantBoilerplate()
{
const string raw = "您好!作为RAG知识库助手,我需要您提供具体的问题以及相关的上下文或知识库内容,才能为您准确解答。";
var cleaned = AiChatOutputSanitizer.SanitizeFinalText(raw);
Assert.Equal("请先输入要查询的问题,或选择知识库后再提问。", cleaned);
}
[Fact]
public void SanitizeFinalTextShouldRemoveThinkTags()
{
const string raw = "<think>内部推理</think>\n答案正文";
var cleaned = AiChatOutputSanitizer.SanitizeFinalText(raw);
Assert.Equal("答案正文", cleaned);
}
}