Separate pipeline reference and binding resolution
This commit is contained in:
114
internal/framework/pipeline/binding_resolution.go
Normal file
114
internal/framework/pipeline/binding_resolution.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
)
|
||||
|
||||
func resolveBinding(binding ModuleBinding, defaultModule string, referenceSlotLabel string) (ModuleBinding, error) {
|
||||
module := resolveModuleKey(binding.Module, defaultModule)
|
||||
llmProfile := strings.TrimSpace(binding.LLMProfile)
|
||||
validators := cloneValidatorOverride(binding.Validators)
|
||||
for i := range validators.Validators {
|
||||
normalizeBindingNames(&validators.Validators[i])
|
||||
}
|
||||
references, err := normalizeReferenceMap(binding.References, referenceSlotLabel)
|
||||
if err != nil {
|
||||
return ModuleBinding{}, err
|
||||
}
|
||||
return ModuleBinding{
|
||||
Module: module,
|
||||
Mode: cloneControl(binding.Mode),
|
||||
MaxAdditionalTurns: cloneControl(binding.MaxAdditionalTurns),
|
||||
Cache: cloneControl(binding.Cache),
|
||||
LLMProfile: llmProfile,
|
||||
Options: CloneModuleOptions(binding.Options),
|
||||
References: references,
|
||||
Validators: validators,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func resolveModuleKey(module string, defaultModule string) string {
|
||||
module = strings.TrimSpace(module)
|
||||
if module == "" {
|
||||
return defaultModule
|
||||
}
|
||||
return module
|
||||
}
|
||||
|
||||
func applyEffectiveLLMProfiles(resolved *ResolvedPipeline, pipelineProfile string, overrideProfile *string) error {
|
||||
pipelineProfile = strings.TrimSpace(pipelineProfile)
|
||||
|
||||
apply := func(stage ModuleStage, laneID, module string, binding *ModuleBinding, executionClass contracts.ExecutionClass, kind string) error {
|
||||
binding.LLMProfile = strings.TrimSpace(binding.LLMProfile)
|
||||
if executionClass != contracts.ExecutionClassLLMBacked {
|
||||
if binding.LLMProfile != "" {
|
||||
if laneID == "" {
|
||||
return fmt.Errorf("pipeline %q %s %q assigns llm_profile to deterministic %s %q", resolved.ID, stage, module, kind, binding.Module)
|
||||
}
|
||||
return fmt.Errorf("pipeline %q lane %q %s %q assigns llm_profile to deterministic %s %q", resolved.ID, laneID, stage, module, kind, binding.Module)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if overrideProfile != nil {
|
||||
binding.LLMProfile = strings.TrimSpace(*overrideProfile)
|
||||
return nil
|
||||
}
|
||||
if binding.LLMProfile == "" {
|
||||
binding.LLMProfile = pipelineProfile
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := apply(StageInput, "", resolved.Input.Module, &resolved.Input, resolved.InputExecutionClass, "module"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := apply(StageChunk, "", resolved.Chunk.Module, &resolved.Chunk, resolved.ChunkExecutionClass, "module"); err != nil {
|
||||
return err
|
||||
}
|
||||
for stepIndex := range resolved.Steps {
|
||||
for laneIndex := range resolved.Steps[stepIndex].ArtifactLanes {
|
||||
lane := &resolved.Steps[stepIndex].ArtifactLanes[laneIndex]
|
||||
if err := apply(StageExtract, lane.ID, lane.Extract.Module, &lane.Extract, lane.ExtractExecutionClass, "module"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := apply(StageMerge, lane.ID, lane.Merge.Module, &lane.Merge, lane.MergeExecutionClass, "module"); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := apply(StageNormalize, lane.ID, lane.Normalize.Module, &lane.Normalize, lane.NormalizeExecutionClass, "module"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := apply(StageOutput, "", resolved.Output.Module, &resolved.Output, resolved.OutputExecutionClass, "module"); err != nil {
|
||||
return err
|
||||
}
|
||||
for chainIndex := range resolved.ValidatorChains {
|
||||
chain := &resolved.ValidatorChains[chainIndex]
|
||||
for validatorIndex := range chain.Validators {
|
||||
validator := &chain.Validators[validatorIndex]
|
||||
if err := apply(chain.Stage, chain.LaneID, chain.ModuleKey, &validator.Binding, validator.ExecutionClass, "validator"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func resolveBindings(bindings []ModuleBinding, defaultModule string, referenceSlotLabel string) ([]ModuleBinding, error) {
|
||||
if len(bindings) == 0 {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
resolved := make([]ModuleBinding, 0, len(bindings))
|
||||
for index, binding := range bindings {
|
||||
resolvedBinding, err := resolveBinding(binding, defaultModule, fmt.Sprintf("%s %d", referenceSlotLabel, index))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resolved = append(resolved, resolvedBinding)
|
||||
}
|
||||
return resolved, nil
|
||||
}
|
||||
Reference in New Issue
Block a user