Share prepared pipeline source validation
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
@@ -10,6 +11,30 @@ import (
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
// ParseSource parses and validates input using the prepared input adapter.
|
||||
func (prepared *PreparedPipeline) ParseSource(ctx context.Context, request contracts.ParseRequest) (*source.SourceDocument, error) {
|
||||
metadata, err := cloneMetadata(request.Metadata)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("clone input adapter metadata: %w", err)
|
||||
}
|
||||
if err := ctx.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
request.Metadata = metadata
|
||||
request.LLMProfile = prepared.resolved.Input.LLMProfile
|
||||
doc, err := prepared.input.Parse(ctx, request)
|
||||
if ctxErr := ctx.Err(); ctxErr != nil {
|
||||
return nil, ctxErr
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("parse input with adapter %q: %w", prepared.input.Key(), err)
|
||||
}
|
||||
if err := source.ValidateDocument(doc); err != nil {
|
||||
return nil, fmt.Errorf("validate source document: %w", err)
|
||||
}
|
||||
return doc, nil
|
||||
}
|
||||
|
||||
// PreparedPipeline owns the constructed, run-local implementation set for one
|
||||
// resolved pipeline. Its implementation values are private so execution cannot
|
||||
// replace or reconfigure them after preparation.
|
||||
|
||||
Reference in New Issue
Block a user