Move scene shape facts into the scene family
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"go.maximumdirect.net/promptkit"
|
||||
@@ -13,8 +14,9 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/pipeline"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd"
|
||||
scenefacts "gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/scenedescriptions"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/validate/scenedescriptions/shape"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/modules/dnd/shared/diagnostics"
|
||||
)
|
||||
|
||||
const Key = "extract/dnd/scene-descriptions/combat_semantics"
|
||||
@@ -108,7 +110,7 @@ func validateRequest(ctx context.Context, req contracts.TypedValidationRequest[d
|
||||
if err := source.NewDocumentIndex(req.Source).ValidateRef(req.Chunk.Ref); err != nil {
|
||||
return contracts.LLMInputMaterial{}, dnd.SceneDescription{}, validatorErrorf("validate current chunk source range: %w", err)
|
||||
}
|
||||
if err := shape.ValidateForStage(req.Value, req.Stage); err != nil {
|
||||
if err := sceneShapeError(req.Value); err != nil {
|
||||
return contracts.LLMInputMaterial{}, dnd.SceneDescription{}, validatorErrorf("validate scene description shape: %w", err)
|
||||
}
|
||||
scene := req.Value.Scenes[0]
|
||||
@@ -121,6 +123,40 @@ func validateRequest(ctx context.Context, req contracts.TypedValidationRequest[d
|
||||
return sourceInput, scene, nil
|
||||
}
|
||||
|
||||
func sceneShapeError(value dnd.SceneDescriptionList) error {
|
||||
var issues []string
|
||||
if len(value.Scenes) > 1 {
|
||||
issues = append(issues, "extraction must contain exactly one scene")
|
||||
}
|
||||
for _, fact := range scenefacts.Check(value) {
|
||||
if fact.Field == scenefacts.ScenesMissing {
|
||||
issues = append(issues, "scenes must be present")
|
||||
continue
|
||||
}
|
||||
if fact.Field == scenefacts.ScenesEmpty {
|
||||
issues = append(issues, "scenes must not be empty")
|
||||
continue
|
||||
}
|
||||
prefix := fmt.Sprintf("scenes[%d]", fact.Index)
|
||||
switch fact.Field {
|
||||
case scenefacts.ID:
|
||||
issues = append(issues, prefix+".id must be non-empty and trimmed")
|
||||
case scenefacts.Kind:
|
||||
issues = append(issues, prefix+".kind is unsupported: "+diagnostics.Quote(string(value.Scenes[fact.Index].Kind)))
|
||||
case scenefacts.Title:
|
||||
issues = append(issues, prefix+".title must be non-empty and trimmed")
|
||||
case scenefacts.Summary:
|
||||
issues = append(issues, prefix+".summary must be non-empty and trimmed")
|
||||
case scenefacts.SourceRef:
|
||||
issues = append(issues, prefix+".source_ref must have a trimmed source ID and positive unit IDs")
|
||||
}
|
||||
}
|
||||
if len(issues) == 0 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("%s", diagnostics.Aggregate("invalid scene description shape", issues))
|
||||
}
|
||||
|
||||
func unavailable(cause error) error {
|
||||
return &contracts.ValidationUnavailableError{Cause: validatorErrorf("native assessment unavailable: %w", cause)}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user