Skip model progress after caller cancellation
This commit is contained in:
@@ -22,8 +22,8 @@ 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 runs outside the engine's timed operation while the caller
|
||||
// context is active. A nil count marks the start.
|
||||
OnProgress func(structuredoutput.DiagnosticContext, *outcomes.ExecutionCounts, error)
|
||||
}
|
||||
|
||||
@@ -71,9 +71,12 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
||||
var record structuredoutput.CallRecord
|
||||
progressContext := req.Context
|
||||
progressContext.Role = c.role
|
||||
if progress := c.hooks.OnProgress; progress != nil {
|
||||
progress(progressContext, nil, nil)
|
||||
emitProgress := func(counts *outcomes.ExecutionCounts, err error) {
|
||||
if progress := c.hooks.OnProgress; progress != nil && parent.Err() == nil {
|
||||
progress(progressContext, counts, err)
|
||||
}
|
||||
}
|
||||
emitProgress(nil, nil)
|
||||
if c.hooks.OnCall != nil || c.hooks.OnEventWithCall != nil {
|
||||
record.CallID = c.runtime.nextCallID.Add(1)
|
||||
record.RequestedPromptID = req.PromptID
|
||||
@@ -123,9 +126,7 @@ func (c *RoleClient) prepareCall(parent context.Context, req structuredoutput.Re
|
||||
}
|
||||
onCall(record)
|
||||
}
|
||||
if progress := c.hooks.OnProgress; progress != nil {
|
||||
progress(progressContext, &response.Execution, err)
|
||||
}
|
||||
emitProgress(&response.Execution, err)
|
||||
return response, err
|
||||
}}
|
||||
fail := func(err error) (*pendingCall, error) {
|
||||
|
||||
Reference in New Issue
Block a user