Complete the core operation execution cutover
This commit is contained in:
@@ -65,16 +65,16 @@ func (invalidEnemyEventExtractor) Key() string { return invalidEnemyEventExtract
|
||||
|
||||
func (invalidEnemyEventExtractor) ReferenceSlots() []contracts.ReferenceSlot { return nil }
|
||||
|
||||
func (invalidEnemyEventExtractor) Extract(ctx context.Context, req contracts.TypedExtractionRequest[dnd.EnemyEventList]) (contracts.TypedExtractionResult[dnd.EnemyEventList], error) {
|
||||
func (invalidEnemyEventExtractor) PrepareExtraction(ctx context.Context, req contracts.ExtractionInput) (contracts.PreparedOperation[dnd.EnemyEventList], error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return contracts.TypedExtractionResult[dnd.EnemyEventList]{}, err
|
||||
return nil, err
|
||||
}
|
||||
if req.Source == nil {
|
||||
return contracts.TypedExtractionResult[dnd.EnemyEventList]{}, errors.New("assembled extractor requires source")
|
||||
return nil, errors.New("assembled extractor requires source")
|
||||
}
|
||||
return contracts.TypedExtractionResult[dnd.EnemyEventList]{Value: dnd.EnemyEventList{Events: []dnd.EnemyEvent{{
|
||||
return preparedValue(dnd.EnemyEventList{Events: []dnd.EnemyEvent{{
|
||||
Name: "Ashfang",
|
||||
Kind: dnd.EnemyEventKindEngaged,
|
||||
SourceRefs: []source.SourceRef{{SourceID: req.Source.ID, StartUnitID: 2, EndUnitID: 1}},
|
||||
}}}}, nil
|
||||
}}}), nil
|
||||
}
|
||||
|
||||
@@ -307,12 +307,12 @@ func (e *assembledSpellExtractor) Key() string { return assembledSpellExtractorK
|
||||
|
||||
func (*assembledSpellExtractor) ReferenceSlots() []contracts.ReferenceSlot { return nil }
|
||||
|
||||
func (e *assembledSpellExtractor) Extract(ctx context.Context, req contracts.TypedExtractionRequest[dnd.SpellList]) (contracts.TypedExtractionResult[dnd.SpellList], error) {
|
||||
func (e *assembledSpellExtractor) PrepareExtraction(ctx context.Context, req contracts.ExtractionInput) (contracts.PreparedOperation[dnd.SpellList], error) {
|
||||
if err := ctx.Err(); err != nil {
|
||||
return contracts.TypedExtractionResult[dnd.SpellList]{}, err
|
||||
return nil, err
|
||||
}
|
||||
if req.Chunk == nil || req.Source == nil {
|
||||
return contracts.TypedExtractionResult[dnd.SpellList]{}, fmt.Errorf("assembled extractor requires source and chunk")
|
||||
return nil, fmt.Errorf("assembled extractor requires source and chunk")
|
||||
}
|
||||
e.mu.Lock()
|
||||
e.chunkIndexes = append(e.chunkIndexes, req.Chunk.Index)
|
||||
@@ -321,24 +321,24 @@ func (e *assembledSpellExtractor) Extract(ctx context.Context, req contracts.Typ
|
||||
refTwo := source.SourceRef{SourceID: req.Source.ID, StartUnitID: 2, EndUnitID: 2}
|
||||
if e.unknownSpell {
|
||||
if req.Chunk.Index == 0 {
|
||||
return contracts.TypedExtractionResult[dnd.SpellList]{Value: dnd.SpellList{SpellCasts: []dnd.SpellCast{{
|
||||
return preparedValue(dnd.SpellList{SpellCasts: []dnd.SpellCast{{
|
||||
Caster: "Aria", Spell: "Mysterious Burst", SourceRefs: []source.SourceRef{refOne},
|
||||
}}}}, nil
|
||||
}}}), nil
|
||||
}
|
||||
return contracts.TypedExtractionResult[dnd.SpellList]{Value: dnd.SpellList{SpellCasts: []dnd.SpellCast{}}}, nil
|
||||
return preparedValue(dnd.SpellList{SpellCasts: []dnd.SpellCast{}}), nil
|
||||
}
|
||||
switch req.Chunk.Index {
|
||||
case 0:
|
||||
return contracts.TypedExtractionResult[dnd.SpellList]{Value: dnd.SpellList{SpellCasts: []dnd.SpellCast{{
|
||||
return preparedValue(dnd.SpellList{SpellCasts: []dnd.SpellCast{{
|
||||
Caster: " Aria \t", Spell: " cure wounds ", SourceRefs: []source.SourceRef{refTwo, refOne},
|
||||
}}}}, nil
|
||||
}}}), nil
|
||||
case 1:
|
||||
return contracts.TypedExtractionResult[dnd.SpellList]{Value: dnd.SpellList{SpellCasts: []dnd.SpellCast{
|
||||
return preparedValue(dnd.SpellList{SpellCasts: []dnd.SpellCast{
|
||||
{Caster: "aria", Spell: "Cure Wounds", SourceRefs: []source.SourceRef{refOne, refTwo}},
|
||||
{Caster: "aria", Spell: "Cure Wounds", SourceRefs: []source.SourceRef{refTwo}},
|
||||
}}}, nil
|
||||
}}), nil
|
||||
default:
|
||||
return contracts.TypedExtractionResult[dnd.SpellList]{}, fmt.Errorf("unexpected assembled chunk index %d", req.Chunk.Index)
|
||||
return nil, fmt.Errorf("unexpected assembled chunk index %d", req.Chunk.Index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ func runReferenceSlots() []contracts.ReferenceSlot {
|
||||
{Name: "secondary", AcceptedMediaTypes: []string{"text/plain"}},
|
||||
}
|
||||
}
|
||||
func (producer *runProducer) Extract(ctx context.Context, request contracts.TypedExtractionRequest[inspectionArtifact]) (contracts.TypedExtractionResult[inspectionArtifact], error) {
|
||||
func (producer *runProducer) PrepareExtraction(ctx context.Context, request contracts.ExtractionInput) (contracts.PreparedOperation[inspectionArtifact], error) {
|
||||
content := string(request.SourceInput.Content)
|
||||
for _, slot := range request.References.Slots {
|
||||
for _, item := range slot.Items {
|
||||
@@ -102,22 +102,28 @@ func (producer *runProducer) Extract(ctx context.Context, request contracts.Type
|
||||
}
|
||||
}
|
||||
initial := promptkit.RunRequest{PromptID: "inspect-initial", ProfileID: request.LLMProfile, SessionID: request.SessionID, Inputs: map[string]promptkit.ArtifactRef{"source": promptkit.Inline(content)}, OnPrepared: producer.probe.onPrepared}
|
||||
value, outcome, err := pipeline.RunProducer(ctx, producer.engine, request.Operation, initial, func(_ context.Context, result *promptkit.RunResult) (*inspectionArtifact, []string, error) {
|
||||
return contracts.NativeOperation[inspectionArtifact]{Initial: initial, Interpret: func(_ context.Context, result *promptkit.RunResult) (contracts.Evaluation[inspectionArtifact], error) {
|
||||
var value inspectionArtifact
|
||||
err := json.Unmarshal([]byte(result.RawOutput), &value)
|
||||
return &value, nil, err
|
||||
}, func(context.Context, []string) (promptkit.RunRequest, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return contracts.CandidateEvaluation[inspectionArtifact]{Result: contracts.EvaluationView[inspectionArtifact]{Candidate: &value}}, nil
|
||||
}, Correction: func(context.Context, []string) (promptkit.RunRequest, error) {
|
||||
return promptkit.RunRequest{PromptID: "inspect-correction", ProfileID: request.LLMProfile, SessionID: request.SessionID, OnPrepared: producer.probe.onPrepared}, nil
|
||||
}, func(context.Context, *inspectionArtifact) (inspectionArtifact, error) {
|
||||
}, Fallback: func(context.Context, contracts.Evaluation[inspectionArtifact]) (inspectionArtifact, error) {
|
||||
return inspectionArtifact{Value: "fallback"}, nil
|
||||
})
|
||||
return contracts.TypedExtractionResult[inspectionArtifact]{Value: value, Outcome: outcome}, err
|
||||
}}, nil
|
||||
}
|
||||
func (producer *runProducer) Merge(_ context.Context, request contracts.TypedMergeRequest[inspectionArtifact]) (contracts.TypedMergeResult[inspectionArtifact], error) {
|
||||
return contracts.TypedMergeResult[inspectionArtifact]{Value: request.ExtractOutputs[0].Value}, nil
|
||||
func (producer *runProducer) PrepareMerge(_ context.Context, request contracts.MergeInput[inspectionArtifact]) (contracts.PreparedOperation[inspectionArtifact], error) {
|
||||
return preparedValue(request.ExtractOutputs[0].Value), nil
|
||||
}
|
||||
func (producer *runProducer) Normalize(_ context.Context, request contracts.TypedNormalizeRequest[inspectionArtifact]) (contracts.TypedNormalizeResult[inspectionArtifact], error) {
|
||||
return contracts.TypedNormalizeResult[inspectionArtifact]{Value: request.MergeOutput.Value}, nil
|
||||
func (producer *runProducer) PrepareNormalize(_ context.Context, request contracts.NormalizeInput[inspectionArtifact]) (contracts.PreparedOperation[inspectionArtifact], error) {
|
||||
return preparedValue(request.MergeOutput.Value), nil
|
||||
}
|
||||
|
||||
func preparedValue[T any](value T) contracts.PreparedOperation[T] {
|
||||
return contracts.DeterministicOperation[T]{Evaluation: contracts.CandidateEvaluation[T]{Result: contracts.EvaluationView[T]{Candidate: &value}}}
|
||||
}
|
||||
|
||||
type runValidator struct {
|
||||
|
||||
Reference in New Issue
Block a user