Resolve producer modes turn allowances cache controls and shared workers
This commit is contained in:
@@ -2,7 +2,6 @@ package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
@@ -12,50 +11,20 @@ func (c Config) Validate() error {
|
||||
if err := validateStateSurfaces(c); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateTotalLLMConcurrency(c.Concurrency.TotalLLM); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateStageWorkers(c.Concurrency); err != nil {
|
||||
if err := validateWorkers(c.Concurrency.Workers); err != nil {
|
||||
return err
|
||||
}
|
||||
return validatePipelineProfiles(c.Pipelines)
|
||||
}
|
||||
|
||||
func validateStageWorkers(cfg ConcurrencyConfig) error {
|
||||
keys := make([]string, 0, len(cfg.StageWorkers))
|
||||
for key := range cfg.StageWorkers {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
if err := validateStageWorkerKey(key); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
extractWorkers, ok := cfg.StageWorkers["extract"]
|
||||
if !ok {
|
||||
extractWorkers = cfg.TotalLLM
|
||||
}
|
||||
return validateExtractWorkerCount(extractWorkers, cfg.TotalLLM)
|
||||
}
|
||||
|
||||
func validateStateSurfaces(cfg Config) error {
|
||||
if err := validateRequiredPath("output.directory", cfg.Output.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateRequiredPath("debug.directory", cfg.Debug.Directory); err != nil {
|
||||
if err := validateOptionalPath("debug.directory", cfg.Debug.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateChunkPlanCacheMode(string(cfg.Cache.ChunkPlans.Mode)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateOptionalPath("cache.chunk_plans.directory", cfg.Cache.ChunkPlans.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := validateOptionalPath("cache.checkpoints.directory", cfg.Cache.Checkpoints.Directory); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return validateOptionalPath("cache_directory", cfg.CacheDirectory)
|
||||
}
|
||||
|
||||
func validatePipelineProfiles(profiles map[string]pipeline.PipelineProfile) error {
|
||||
@@ -73,13 +42,8 @@ func validatePipelineProfiles(profiles map[string]pipeline.PipelineProfile) erro
|
||||
if profile.ID != "" && strings.TrimSpace(profile.ID) != id {
|
||||
return fmt.Errorf("pipeline %q profile id %q does not match map key", id, profile.ID)
|
||||
}
|
||||
if err := validateStructuredOutputRepairAttempts(fmt.Sprintf("pipeline %q", id), profile.StructuredOutputRepairAttempts); err != nil {
|
||||
return err
|
||||
}
|
||||
if profile.ValidationPolicy != nil {
|
||||
if err := profile.ValidationPolicy.Validate(); err != nil {
|
||||
return fmt.Errorf("pipeline %q validation_policy: %w", id, err)
|
||||
}
|
||||
if _, err := pipeline.ResolveProducerControls(pipeline.ModuleBinding{}, profile, nil); err != nil {
|
||||
return fmt.Errorf("pipeline %q: %w", id, err)
|
||||
}
|
||||
if err := validateBinding(id, "", "input", profile.Input, false); err != nil {
|
||||
return err
|
||||
@@ -160,28 +124,12 @@ func validateBinding(
|
||||
binding pipeline.ModuleBinding,
|
||||
referencesAllowed bool,
|
||||
) error {
|
||||
if binding.ValidationPolicy != nil {
|
||||
switch slot {
|
||||
case "chunk", "extract", "merge", "normalize":
|
||||
default:
|
||||
return fmt.Errorf("%s validation_policy is not supported", referenceContext(pipelineID, laneID, slot))
|
||||
}
|
||||
if err := binding.ValidationPolicy.Validate(); err != nil {
|
||||
return fmt.Errorf("%s validation_policy: %w", referenceContext(pipelineID, laneID, slot), err)
|
||||
}
|
||||
}
|
||||
if err := validateStructuredOutputRepairAttempts(referenceContext(pipelineID, laneID, slot), binding.StructuredOutputRepairAttempts); err != nil {
|
||||
return err
|
||||
if _, err := pipeline.ResolveProducerControls(binding, pipeline.PipelineProfile{}, nil); err != nil {
|
||||
return fmt.Errorf("%s: %w", referenceContext(pipelineID, laneID, slot), err)
|
||||
}
|
||||
if err := validateBindingLLMProfile(pipelineID, laneID, slot, binding); err != nil {
|
||||
return err
|
||||
}
|
||||
if binding.Retries < 0 {
|
||||
if laneID != "" {
|
||||
return fmt.Errorf("pipeline %q lane %q %s retries must be greater than or equal to zero", pipelineID, laneID, slot)
|
||||
}
|
||||
return fmt.Errorf("pipeline %q %s retries must be greater than or equal to zero", pipelineID, slot)
|
||||
}
|
||||
if err := validateValidatorOverride(pipelineID, laneID, slot, binding.Validators); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -197,13 +145,6 @@ func validateBinding(
|
||||
return validateReferenceMapForContext(pipelineID, laneID, slot, binding.References, true)
|
||||
}
|
||||
|
||||
func validateStructuredOutputRepairAttempts(context string, attempts *int) error {
|
||||
if attempts != nil && (*attempts < 0 || *attempts > 3) {
|
||||
return fmt.Errorf("%s structured_output_repair_attempts must be between zero and three", context)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func validateValidatorOverride(pipelineID string, laneID string, slot string, override pipeline.ValidatorOverride) error {
|
||||
if !override.Set {
|
||||
return nil
|
||||
@@ -215,9 +156,6 @@ func validateValidatorOverride(pipelineID string, laneID string, slot string, ov
|
||||
}
|
||||
for i, validator := range override.Validators {
|
||||
context := fmt.Sprintf("%s validators[%d]", referenceContext(pipelineID, laneID, slot), i)
|
||||
if err := validateStructuredOutputRepairAttempts(context, validator.StructuredOutputRepairAttempts); err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(validator.Module) == "" {
|
||||
return fmt.Errorf("%s module must not be empty", context)
|
||||
}
|
||||
@@ -227,11 +165,8 @@ func validateValidatorOverride(pipelineID string, laneID string, slot string, ov
|
||||
if validator.Validators.Set {
|
||||
return fmt.Errorf("%s nested validators are not supported", context)
|
||||
}
|
||||
if validator.ValidationPolicy != nil {
|
||||
return fmt.Errorf("%s validation_policy is not supported", context)
|
||||
}
|
||||
if validator.Retries < 0 {
|
||||
return fmt.Errorf("%s retries must be greater than or equal to zero", context)
|
||||
if validator.Mode != nil || validator.Cache != nil || validator.MaxAdditionalTurns != nil {
|
||||
return fmt.Errorf("%s producer controls are not supported for validators", context)
|
||||
}
|
||||
if validator.LLMProfile != "" && strings.TrimSpace(validator.LLMProfile) == "" {
|
||||
return fmt.Errorf("%s llm_profile must not be empty when set", context)
|
||||
|
||||
Reference in New Issue
Block a user