Keep progress writes outside model deadlines
This commit is contained in:
@@ -13,7 +13,6 @@ import (
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/modules"
|
||||
pk "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func executePipeline(ctx context.Context, loaded *processInputs, prepared *preparedProcess, normalized *schema.Transcript, warn func(error), progress func(string)) (processResult, error) {
|
||||
@@ -28,12 +27,8 @@ func executePipeline(ctx context.Context, loaded *processInputs, prepared *prepa
|
||||
hooks = observer.Hooks()
|
||||
}
|
||||
if progress != nil {
|
||||
observe := hooks.OnEventWithCall
|
||||
hooks.OnEventWithCall = func(callID uint64, coordinates structuredoutput.DiagnosticContext, event pk.ExecutionEvent) {
|
||||
if observe != nil {
|
||||
observe(callID, coordinates, event)
|
||||
}
|
||||
reportModelProgress(progress, coordinates, event)
|
||||
hooks.OnProgress = func(coordinates structuredoutput.DiagnosticContext, counts *outcomes.ExecutionCounts, err error) {
|
||||
reportModelProgress(progress, coordinates, counts, err)
|
||||
}
|
||||
}
|
||||
for i := range specs {
|
||||
|
||||
@@ -5,9 +5,9 @@ import (
|
||||
"strings"
|
||||
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/core/reporting"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/outcomes"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/runner"
|
||||
"gitea.maximumdirect.net/eric/audita/v3/internal/framework/structuredoutput"
|
||||
pk "go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
func runnerProgress(progress func(string)) func(runner.Progress) {
|
||||
@@ -31,8 +31,8 @@ func runnerProgress(progress func(string)) func(runner.Progress) {
|
||||
}
|
||||
}
|
||||
|
||||
func reportModelProgress(progress func(string), coordinates structuredoutput.DiagnosticContext, event pk.ExecutionEvent) {
|
||||
if coordinates.StageIndex == nil || (event.Kind != pk.ExecutionStarted && event.Kind != pk.ExecutionFinished) {
|
||||
func reportModelProgress(progress func(string), coordinates structuredoutput.DiagnosticContext, counts *outcomes.ExecutionCounts, err error) {
|
||||
if coordinates.StageIndex == nil {
|
||||
return
|
||||
}
|
||||
location := progressLocation(*coordinates.StageIndex, coordinates.ModuleKey, coordinates.StageID, coordinates.SectionIndex)
|
||||
@@ -49,11 +49,18 @@ func reportModelProgress(progress func(string), coordinates structuredoutput.Dia
|
||||
}
|
||||
operation += fmt.Sprintf(" turn %d", *coordinates.RepairAttempt)
|
||||
}
|
||||
if event.Kind == pk.ExecutionStarted {
|
||||
if counts == nil {
|
||||
progress(fmt.Sprintf("%s %s started", location, operation))
|
||||
} else {
|
||||
progress(fmt.Sprintf("%s %s finished (%s, %d provider attempts)", location, operation, event.Outcome, event.Attempts))
|
||||
return
|
||||
}
|
||||
outcome := "completed"
|
||||
if err != nil {
|
||||
outcome = "failed"
|
||||
}
|
||||
if counts.Available {
|
||||
outcome += fmt.Sprintf(", %d provider attempts", counts.ProviderAttempts)
|
||||
}
|
||||
progress(fmt.Sprintf("%s %s finished (%s)", location, operation, outcome))
|
||||
}
|
||||
|
||||
func progressLocation(index int, module string, id *string, section *int) string {
|
||||
|
||||
@@ -22,6 +22,9 @@ type CallHooks struct {
|
||||
OnCall func(structuredoutput.CallRecord)
|
||||
OnEvent pk.ExecutionObserver
|
||||
OnEventWithCall func(uint64, structuredoutput.DiagnosticContext, pk.ExecutionEvent)
|
||||
// OnProgress runs before and after the engine's timed operation. A nil
|
||||
// count marks the start. A completion may have unknown execution counts.
|
||||
OnProgress func(structuredoutput.DiagnosticContext, *outcomes.ExecutionCounts, error)
|
||||
}
|
||||
|
||||
type RoleClient struct {
|
||||
@@ -66,6 +69,11 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
||||
var prepared *structuredoutput.PreparedSnapshot
|
||||
var prompt structuredoutput.PromptMetadata
|
||||
var record structuredoutput.CallRecord
|
||||
progressContext := req.Context
|
||||
progressContext.Role = c.role
|
||||
if progress := c.hooks.OnProgress; progress != nil {
|
||||
progress(progressContext, nil, nil)
|
||||
}
|
||||
if c.hooks.OnCall != nil || c.hooks.OnEventWithCall != nil {
|
||||
record.CallID = c.runtime.nextCallID.Add(1)
|
||||
record.RequestedPromptID = req.PromptID
|
||||
@@ -115,6 +123,9 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
||||
}
|
||||
onCall(record)
|
||||
}
|
||||
if progress := c.hooks.OnProgress; progress != nil {
|
||||
progress(progressContext, &response.Execution, err)
|
||||
}
|
||||
return response, err
|
||||
}}
|
||||
fail := func(err error) (*pendingCall, error) {
|
||||
|
||||
Reference in New Issue
Block a user