build-flow.api/tests/BuildFlow.Rag.Tests/Stub/StubLlmRerankService.cs

27 lines
922 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;
namespace BuildFlow.Rag.Tests.Stub;
/// <summary>
/// 可控 LLM 重排 stub:按调用顺序依次返回预设结果(成功序/失败降级交替场景),也可固定返回。
/// </summary>
public sealed class StubLlmRerankService : ILlmRerankService
{
private readonly Queue<List<Guid>?> _responses;
/// <summary>调用计数,供测试断言降级路径是否真的触发了 LLM 尝试。</summary>
public int CallCount { get; private set; }
public StubLlmRerankService(params List<Guid>?[] responses) => _responses = new(responses);
public Task<List<Guid>?> RerankAsync(
string question,
IReadOnlyList<(Guid ChunkId, string Content)> candidates,
CancellationToken ct = default)
{
CallCount++;
var result = _responses.Count > 0 ? _responses.Dequeue() : null;
return Task.FromResult(result);
}
}