Prepare structured D&D reference context
This commit is contained in:
@@ -37,10 +37,21 @@ var _ contracts.Chunker = (*Chunker)(nil)
|
||||
|
||||
type Options struct{}
|
||||
|
||||
type Chunker struct{}
|
||||
type Chunker struct{ context shared.PreparedContext }
|
||||
|
||||
func New(_ Options) (*Chunker, error) {
|
||||
return &Chunker{}, nil
|
||||
func New(_ Options, references ...contracts.ReferenceSet) (*Chunker, error) {
|
||||
if len(references) > 1 {
|
||||
return nil, chunkerErrorf("at most one reference set may be supplied")
|
||||
}
|
||||
var set contracts.ReferenceSet
|
||||
if len(references) == 1 {
|
||||
set = references[0]
|
||||
}
|
||||
context, err := shared.PrepareContext(set)
|
||||
if err != nil {
|
||||
return nil, chunkerErrorf("prepare references: %w", err)
|
||||
}
|
||||
return &Chunker{context: context}, nil
|
||||
}
|
||||
|
||||
func (c *Chunker) Key() string {
|
||||
@@ -70,7 +81,7 @@ func (c *Chunker) PrepareChunk(ctx context.Context, req contracts.ChunkInput) (c
|
||||
if err := source.ValidateDocument(req.Source); err != nil {
|
||||
return nil, chunkerErrorf("validate source document: %w", err)
|
||||
}
|
||||
materials := shared.PromptInputs(req.SourceInput, req.References)
|
||||
materials := c.context.Inputs(req.SourceInput)
|
||||
inputs := make(map[string]promptkit.ArtifactRef, len(materials))
|
||||
for name, material := range materials {
|
||||
inputs[name] = promptkit.InlineWithURI(material.OriginURI, string(material.Content))
|
||||
@@ -121,7 +132,7 @@ func Register(registry *pipeline.ChunkerRegistry) error {
|
||||
if err := shared.ValidateReferenceSelections(request.References); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return New(options)
|
||||
return New(options, request.References)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user