Use native contexts for execution observation
This commit is contained in:
@@ -291,19 +291,19 @@ func TestNativeProducerPreservesConversationAndExplicitSelections(t *testing.T)
|
||||
}
|
||||
}
|
||||
overrideModel := "override-model"
|
||||
ctx := promptkit.WithExecutionObserver(context.Background(), func(event promptkit.ExecutionEvent) {
|
||||
if event.Kind == promptkit.ExecutionFinished {
|
||||
observed++
|
||||
}
|
||||
})
|
||||
operation := contracts.ProducerOperation[int]{Controls: contracts.ProducerControls{Mode: contracts.ModePermissive, MaxAdditionalTurns: 2}, Assess: rejectedProducerAssessment,
|
||||
Execution: contracts.ExecutionOptions{Execution: &promptkit.ExecutionTargetOverride{Model: overrideModel},
|
||||
Observer: func(event promptkit.ExecutionEvent) {
|
||||
if event.Kind == promptkit.ExecutionFinished {
|
||||
observed++
|
||||
}
|
||||
},
|
||||
OnPrepared: func(_ context.Context, details promptkit.PreparedRun) {
|
||||
profiles = append(profiles, details.SelectedProfileID)
|
||||
},
|
||||
},
|
||||
}
|
||||
_, outcome, err := RunProducer(context.Background(), engine, operation, initial, interpretProducerNumber,
|
||||
_, outcome, err := RunProducer(ctx, engine, operation, initial, interpretProducerNumber,
|
||||
func(ctx context.Context, guidance []string) (promptkit.RunRequest, error) {
|
||||
if !reflect.DeepEqual(guidance, []string{"Return value one."}) {
|
||||
t.Fatalf("unexpected correction guidance: %#v", guidance)
|
||||
@@ -368,15 +368,15 @@ func TestNativeProducerCancellationDoesNotDeliverOrFallback(t *testing.T) {
|
||||
}
|
||||
return rejectedProducerAssessment(ctx, value)
|
||||
},
|
||||
Execution: contracts.ExecutionOptions{Observer: func(event promptkit.ExecutionEvent) {
|
||||
if event.Kind == promptkit.ExecutionFinished {
|
||||
finished++
|
||||
if (moment == "before continuation delivery" && finished == 2) || moment == "after initial execution" {
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
}},
|
||||
}
|
||||
ctx = promptkit.WithExecutionObserver(ctx, func(event promptkit.ExecutionEvent) {
|
||||
if event.Kind == promptkit.ExecutionFinished {
|
||||
finished++
|
||||
if (moment == "before continuation delivery" && finished == 2) || moment == "after initial execution" {
|
||||
cancel()
|
||||
}
|
||||
}
|
||||
})
|
||||
if moment == "before initial" {
|
||||
cancel()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user