Prepare shared context for all D&D extractors
This commit is contained in:
@@ -65,6 +65,7 @@ var _ contracts.Extractor[dnd.SpellList] = (*Extractor)(nil)
|
||||
type Options struct{}
|
||||
|
||||
type Extractor struct {
|
||||
context shared.PreparedContext
|
||||
catalogPromptInput []byte
|
||||
npcResolver *npcregistry.Resolver
|
||||
}
|
||||
@@ -77,6 +78,10 @@ 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)
|
||||
}
|
||||
effectiveCatalog, err := spellcatalog.ResolveEffectiveCatalog(referenceSet)
|
||||
if err != nil {
|
||||
return nil, extractorErrorf("resolve effective spell catalog: %w", err)
|
||||
@@ -89,7 +94,7 @@ func New(_ Options, references ...contracts.ReferenceSet) (*Extractor, error) {
|
||||
if err != nil {
|
||||
return nil, extractorErrorf("prepare NPC registry prompt input: %w", err)
|
||||
}
|
||||
return &Extractor{catalogPromptInput: catalogPromptInput, npcResolver: npcResolver}, nil
|
||||
return &Extractor{context: context, catalogPromptInput: catalogPromptInput, npcResolver: npcResolver}, nil
|
||||
}
|
||||
|
||||
func (e *Extractor) Key() string {
|
||||
@@ -115,7 +120,7 @@ func (e *Extractor) PrepareExtraction(ctx context.Context, req contracts.Extract
|
||||
return nil, extractorErrorf("resolve NPC registry: %w", err)
|
||||
}
|
||||
|
||||
materials := shared.PromptInputs(sourceInput, req.References)
|
||||
materials := e.context.Inputs(sourceInput)
|
||||
inputs := make(map[string]promptkit.ArtifactRef, len(materials)+2)
|
||||
for name, material := range materials {
|
||||
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))
|
||||
|
||||
Reference in New Issue
Block a user