fix(ai): request structured JSON for queued strategies
This commit is contained in:
@@ -72,7 +72,7 @@ public sealed class AiWorkspaceNotePersistenceTests
|
||||
var job = await SeedJobWithCvAsync(db);
|
||||
|
||||
var summarizer = new Mock<ISummarizerService>();
|
||||
summarizer.Setup(x => x.GenerateSectionWithMetadataAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
summarizer.Setup(x => x.GenerateSectionWithMetadataAsync(It.IsAny<string>(), It.IsAny<string>(), AiGenerationOutputMode.StructuredJson, It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(new AiGenerationResult("""{"strategicSummary":"Lead with backend delivery.","cvBulletIdeas":["Built APIs"],"proofPointsToLeadWith":["Led delivery"],"coverLetterAngles":["Relevant platform work"]}""", "ollama", "test-model"));
|
||||
|
||||
var service = new StrategySnapshotService(db, summarizer.Object);
|
||||
|
||||
@@ -71,6 +71,22 @@ public sealed class CvAiEvaluationTests
|
||||
Assert.Null(await service.GenerateSectionWithMetadataAsync("Improve", "Source", AiGenerationOutputMode.CvBlocksJson));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Structured_generation_has_an_explicit_mode_and_cannot_reuse_text_cache()
|
||||
{
|
||||
var handler = new CaptureHandler();
|
||||
var factory = new Mock<IHttpClientFactory>();
|
||||
factory.Setup(value => value.CreateClient("ai-service")).Returns(new HttpClient(handler) { BaseAddress = new Uri("http://localhost") });
|
||||
using var cache = new MemoryCache(new MemoryCacheOptions());
|
||||
var service = new SummarizerService(factory.Object, cache);
|
||||
await service.GenerateSectionWithMetadataAsync("Return JSON.", "Fictional source.");
|
||||
Assert.NotNull(await service.GenerateSectionWithMetadataAsync("Return JSON.", "Fictional source.", AiGenerationOutputMode.StructuredJson));
|
||||
Assert.Equal(2, handler.RequestCount);
|
||||
using var body = JsonDocument.Parse(handler.Body!);
|
||||
Assert.Equal("structured_json", body.RootElement.GetProperty("output_mode").GetString());
|
||||
Assert.Null(await ((ISummarizerService)new OlderSummarizer()).GenerateSectionWithMetadataAsync("Return JSON.", "Source", AiGenerationOutputMode.StructuredJson));
|
||||
}
|
||||
|
||||
private sealed class CaptureHandler : HttpMessageHandler
|
||||
{
|
||||
public string? Path { get; private set; }
|
||||
|
||||
@@ -128,7 +128,7 @@ public sealed class StrategySnapshotOperationTests
|
||||
await connection.OpenAsync();
|
||||
Fixture? fixture = null;
|
||||
var summarizer = new Mock<ISummarizerService>();
|
||||
summarizer.Setup(item => item.GenerateSectionWithMetadataAsync(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
summarizer.Setup(item => item.GenerateSectionWithMetadataAsync(It.IsAny<string>(), It.IsAny<string>(), AiGenerationOutputMode.StructuredJson, It.IsAny<int>(), It.IsAny<int>(), It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(() =>
|
||||
{
|
||||
fixture!.GenerationCalls++;
|
||||
|
||||
Reference in New Issue
Block a user