Capture completed conversation exchanges
This commit is contained in:
@@ -77,6 +77,8 @@ type RunRequest struct {
|
||||
|
||||
// RunResult represents the complete result of a prompt execution run.
|
||||
type RunResult struct {
|
||||
Exchange *Exchange
|
||||
ParentRunID string
|
||||
RunID string
|
||||
Artifact Artifact
|
||||
RawOutput string
|
||||
|
||||
@@ -30,6 +30,8 @@ type PreparedExecution struct {
|
||||
|
||||
type preparedExecutionPayload struct {
|
||||
prepared *domain.PreparedRun
|
||||
capture bool
|
||||
parent *domain.Exchange
|
||||
validation validate.PreparedValidation
|
||||
directKey string
|
||||
transientRetries uint64
|
||||
@@ -55,6 +57,8 @@ func (r *Runner) PrepareExecution(ctx context.Context, req domain.RunRequest) (*
|
||||
details: operation.run,
|
||||
payload: &preparedExecutionPayload{
|
||||
prepared: operation.run,
|
||||
capture: operation.capture,
|
||||
parent: operation.parent,
|
||||
validation: operation.validation,
|
||||
directKey: state.effectiveModel.APIKey,
|
||||
transientRetries: state.transientRetries,
|
||||
@@ -139,7 +143,7 @@ func (r *Runner) RunPrepared(ctx context.Context, prepared *PreparedExecution) (
|
||||
}
|
||||
defer release()
|
||||
|
||||
return r.executePreparedRun(ctx, payload.prepared, payload.directKey, payload.transientRetries, runID, start, func(
|
||||
return r.executePreparedRun(ctx, payload.prepared, payload.capture, payload.parent, payload.directKey, payload.transientRetries, runID, start, func(
|
||||
ctx context.Context,
|
||||
artifact *domain.Artifact,
|
||||
attemptsUsed int,
|
||||
@@ -174,6 +178,8 @@ func (p *preparedExecutionPayload) clear() {
|
||||
return
|
||||
}
|
||||
p.prepared = nil
|
||||
p.capture = false
|
||||
p.parent = nil
|
||||
p.validation = nil
|
||||
p.directKey = ""
|
||||
p.transientRetries = 0
|
||||
|
||||
@@ -165,7 +165,7 @@ func (r *Runner) Run(ctx context.Context, req domain.RunRequest) (*domain.RunRes
|
||||
}
|
||||
directAPIKey := state.effectiveModel.APIKey
|
||||
|
||||
return r.executePreparedRun(ctx, operation.run, directAPIKey, state.transientRetries, runID, start, func(
|
||||
return r.executePreparedRun(ctx, operation.run, operation.capture, operation.parent, directAPIKey, state.transientRetries, runID, start, func(
|
||||
ctx context.Context,
|
||||
artifact *domain.Artifact,
|
||||
attemptsUsed int,
|
||||
@@ -185,6 +185,8 @@ type preparedValidationFunc func(
|
||||
func (r *Runner) executePreparedRun(
|
||||
ctx context.Context,
|
||||
prepared *domain.PreparedRun,
|
||||
capture bool,
|
||||
parent *domain.Exchange,
|
||||
directAPIKey string,
|
||||
transientRetries uint64,
|
||||
runID string,
|
||||
@@ -254,8 +256,14 @@ func (r *Runner) executePreparedRun(
|
||||
|
||||
end := time.Now().UTC()
|
||||
executionTarget.APIKey = ""
|
||||
var exchange *domain.Exchange
|
||||
if capture {
|
||||
exchange = domain.CaptureExchange(parent, runID, prepared.Messages[parent.MessageCount():], genResp.Content)
|
||||
}
|
||||
|
||||
return &domain.RunResult{
|
||||
Exchange: exchange,
|
||||
ParentRunID: prepared.ParentRunID,
|
||||
RunID: runID,
|
||||
Artifact: outputArtifact,
|
||||
RawOutput: genResp.Content,
|
||||
|
||||
Reference in New Issue
Block a user