Order spell and NPC extraction by document position

This commit is contained in:
2026-07-24 14:29:19 +00:00
parent 83fde83a58
commit 9bbf2535dd
8 changed files with 138 additions and 111 deletions

View File

@@ -13,7 +13,7 @@ import (
const Key = "dnd/npcs"
const mappingPolicy = "dnd.npcs.extract_mapping.v1"
const mappingPolicy = "dnd.npcs.extract_mapping.v2"
var requiredCapabilities = []string{
"chunks",
@@ -129,6 +129,7 @@ func (e *Extractor) Extract(ctx context.Context, req contracts.TypedExtractionRe
if err != nil {
return contracts.TypedExtractionResult[dnd.NPCList]{}, extractorErrorf("%w", err)
}
order := shared.NewSourceRefOrder(req.Source)
var response extractionResponse
if _, err := e.llm.CompleteStructured(ctx, contracts.StructuredCompletionRequest{
@@ -141,7 +142,7 @@ func (e *Extractor) Extract(ctx context.Context, req contracts.TypedExtractionRe
}, &response); err != nil {
return contracts.TypedExtractionResult[dnd.NPCList]{}, extractorErrorf("complete structured output: %w", err)
}
canonicalizeResponse(&response, req.Source)
canonicalizeResponse(&response, order, req.Source.ID)
return contracts.TypedExtractionResult[dnd.NPCList]{Value: canonicalNPCList(response, req.Source.ID)}, nil
}