Route spell extraction through core preparation with remaining extractors pending
This commit is contained in:
@@ -31,7 +31,6 @@ func (p *runnerProbe) record(key string, eligible bool) {
|
||||
type runnerNotesProducer struct {
|
||||
name string
|
||||
probe *runnerProbe
|
||||
engine *promptkit.Engine
|
||||
native bool
|
||||
references bool
|
||||
failure error
|
||||
@@ -49,28 +48,32 @@ func (p *runnerNotesProducer) fallback(ctx context.Context, role string) (codecN
|
||||
p.probe.record(p.name+"/"+role+"/fallback", false)
|
||||
return codecNotes{Items: []string{}}, ctx.Err()
|
||||
}
|
||||
func (p *runnerNotesProducer) Extract(ctx context.Context, request contracts.TypedExtractionRequest[codecNotes]) (contracts.TypedExtractionResult[codecNotes], error) {
|
||||
p.probe.record(p.name+"/extract", request.Operation.ReuseEligible)
|
||||
func (p *runnerNotesProducer) PrepareExtraction(ctx context.Context, request contracts.ExtractionInput) (contracts.PreparedOperation[codecNotes], error) {
|
||||
if p.cancel != nil {
|
||||
p.cancel()
|
||||
}
|
||||
if p.failure != nil {
|
||||
return contracts.TypedExtractionResult[codecNotes]{}, p.failure
|
||||
return nil, p.failure
|
||||
}
|
||||
if p.native {
|
||||
initial := nativeProducerInitial()
|
||||
initial.ProfileID, initial.SessionID = request.LLMProfile, request.SessionID
|
||||
value, outcome, err := RunProducer(ctx, p.engine, request.Operation, initial,
|
||||
func(ctx context.Context, result *promptkit.RunResult) (*codecNotes, []string, error) {
|
||||
return contracts.NativeOperation[codecNotes]{Initial: initial,
|
||||
Interpret: func(ctx context.Context, result *promptkit.RunResult) (contracts.Evaluation[codecNotes], error) {
|
||||
number, _, err := interpretProducerNumber(ctx, result)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return nil, err
|
||||
}
|
||||
return &codecNotes{Items: []string{fmt.Sprint(*number)}}, nil, nil
|
||||
}, producerCorrection, func(ctx context.Context, _ *codecNotes) (codecNotes, error) { return p.fallback(ctx, "extract") })
|
||||
return contracts.TypedExtractionResult[codecNotes]{Value: value, Outcome: outcome}, err
|
||||
value := codecNotes{Items: []string{fmt.Sprint(*number)}}
|
||||
return contracts.CandidateEvaluation[codecNotes]{Result: contracts.EvaluationView[codecNotes]{Candidate: &value}}, nil
|
||||
}, Correction: producerCorrection, Fallback: func(ctx context.Context, _ contracts.Evaluation[codecNotes]) (codecNotes, error) {
|
||||
return p.fallback(ctx, "extract")
|
||||
}}, nil
|
||||
}
|
||||
return contracts.TypedExtractionResult[codecNotes]{Value: codecNotes{Items: []string{p.name}}, Fallback: func(ctx context.Context) (codecNotes, error) { return p.fallback(ctx, "extract") }}, nil
|
||||
value := codecNotes{Items: []string{p.name}}
|
||||
return contracts.DeterministicOperation[codecNotes]{Evaluation: contracts.CandidateEvaluation[codecNotes]{Result: contracts.EvaluationView[codecNotes]{Candidate: &value}}, Fallback: func(ctx context.Context, _ contracts.Evaluation[codecNotes]) (codecNotes, error) {
|
||||
return p.fallback(ctx, "extract")
|
||||
}}, nil
|
||||
}
|
||||
func (p *runnerNotesProducer) Merge(ctx context.Context, request contracts.TypedMergeRequest[codecNotes]) (contracts.TypedMergeResult[codecNotes], error) {
|
||||
p.probe.record(p.name+"/merge", request.Operation.ReuseEligible)
|
||||
@@ -101,13 +104,19 @@ func registerRunnerNotes(t *testing.T, catalog ModuleCatalog, producer runnerNot
|
||||
}
|
||||
extractSpec := spec(StageExtract)
|
||||
extractSpec.ExecutionClass = class
|
||||
if err := RegisterExtractorBuilder(catalog.Extractors, extractSpec, rejectUnconfiguredOptions, func(request BuildRequest) (contracts.Extractor[codecNotes], error) {
|
||||
if err := RegisterExtractorBuilder(catalog.Extractors, extractSpec, rejectUnconfiguredOptions, func(BuildRequest) (contracts.Extractor[codecNotes], error) {
|
||||
copy := producer
|
||||
copy.engine = request.Dependencies.Engine
|
||||
return ©, nil
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
entry := catalog.Extractors.typedEntries[extractSpec.Key]
|
||||
extract := entry.extract
|
||||
entry.extract = func(ctx context.Context, module any, input contracts.ExtractionInput, execution ExecutionContext[any]) (erasedTypedResult, error) {
|
||||
producer.probe.record(producer.name+"/extract", execution.ReuseEligible)
|
||||
return extract(ctx, module, input, execution)
|
||||
}
|
||||
catalog.Extractors.typedEntries[extractSpec.Key] = entry
|
||||
if err := RegisterMerger(catalog.Mergers, spec(StageMerge), func() (contracts.Merger[codecNotes], error) { copy := producer; return ©, nil }); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user