Add request validation API
This commit is contained in:
25
engine.go
25
engine.go
@@ -346,6 +346,29 @@ func (e *Engine) InspectProfile(ctx context.Context, profileID string) (*Profile
|
||||
// relationship to ctx.Err is promised. Prepare returns no partial result on
|
||||
// error. It validates RunRequest.TransientRetries but makes no model attempts.
|
||||
func (e *Engine) Prepare(ctx context.Context, req RunRequest) (*PreparedRun, error) {
|
||||
prepared, err := e.prepareRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return fromDomainPreparedRun(prepared), nil
|
||||
}
|
||||
|
||||
// ValidateRequest reports whether req passes the same preparation path used by
|
||||
// [Engine.Prepare] at the time of this call. A nil error means this concrete
|
||||
// request passed preparation. The method returns no prepared snapshot or
|
||||
// executable handle. It does not call an LLM, but preparation may still perform
|
||||
// resource I/O, including loading supplied inputs and schemas.
|
||||
//
|
||||
// Its errors and context handling follow [Engine.Prepare], including an error
|
||||
// matching ErrInvalidConfig when the Engine is nil. Success does not guarantee
|
||||
// that a provider will accept a later request. Use [Engine.PrepareExecution]
|
||||
// when execution must use the snapshot produced by preparation.
|
||||
func (e *Engine) ValidateRequest(ctx context.Context, req RunRequest) error {
|
||||
_, err := e.prepareRequest(ctx, req)
|
||||
return err
|
||||
}
|
||||
|
||||
func (e *Engine) prepareRequest(ctx context.Context, req RunRequest) (*domain.PreparedRun, error) {
|
||||
ctx = observation.WithoutExecutionState(ctx)
|
||||
if e == nil || e.internal == nil {
|
||||
return nil, fmt.Errorf("%w: engine is nil", ErrInvalidConfig)
|
||||
@@ -360,7 +383,7 @@ func (e *Engine) Prepare(ctx context.Context, req RunRequest) (*PreparedRun, err
|
||||
if err != nil {
|
||||
return nil, mapPublicError(err)
|
||||
}
|
||||
return fromDomainPreparedRun(prepared), nil
|
||||
return prepared, nil
|
||||
}
|
||||
|
||||
// PrepareExecution completely prepares a prompt request without calling the
|
||||
|
||||
Reference in New Issue
Block a user