Prepare shared context for all D&D extractors

This commit is contained in:
2026-11-29 18:13:45 +00:00
parent e0554209f0
commit 03e4c0d64d
22 changed files with 189 additions and 176 deletions

View File

@@ -33,6 +33,7 @@ var _ contracts.Extractor[dnd.EnemyEventList] = (*Extractor)(nil)
type Options struct{}
type Extractor struct {
context shared.PreparedContext
grounding *groundingResolver
}
@@ -44,11 +45,15 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
if len(references) == 1 {
referenceSet = references[0]
}
context, err := shared.PrepareContext(referenceSet)
if err != nil {
return nil, extractorErrorf("prepare references: %w", err)
}
grounding, err := newGroundingResolver(referenceSet)
if err != nil {
return nil, extractorErrorf("prepare grounding: %w", err)
}
return &Extractor{grounding: grounding}, nil
return &Extractor{context: context, grounding: grounding}, nil
}
func (e *Extractor) Key() string { return Key }
@@ -87,7 +92,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
order := shared.NewSourceRefOrderForSource(req.Source, req.SourceIndex)
sourceID := req.Source.ID
materials := shared.PromptInputs(sourceInput, req.References)
materials := e.context.Inputs(sourceInput)
for name, material := range grounding.PromptInputs() {
materials[name] = material
}