Expose HTTP transient retry control and preserve shared capacity
This commit is contained in:
@@ -76,6 +76,10 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
writeError(w, http.StatusBadRequest, "invalid_request", "prompt_id is required")
|
||||
return
|
||||
}
|
||||
if req.TransientRetries != nil && *req.TransientRetries < 0 {
|
||||
writeError(w, http.StatusBadRequest, "invalid_request", "transient_retries must be greater than or equal to 0")
|
||||
return
|
||||
}
|
||||
var mappedInputs map[string]promptkit.ArtifactRef
|
||||
if len(req.Inputs) > 0 {
|
||||
mappedInputs = make(map[string]promptkit.ArtifactRef, len(req.Inputs))
|
||||
@@ -94,13 +98,14 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
res, err := h.runner.Run(r.Context(), promptkit.RunRequest{
|
||||
PromptID: req.PromptID,
|
||||
PromptVersion: req.PromptVersion,
|
||||
ProfileID: req.ProfileID,
|
||||
SessionID: req.SessionID,
|
||||
Inputs: mappedInputs,
|
||||
Vars: req.Vars,
|
||||
Execution: model,
|
||||
PromptID: req.PromptID,
|
||||
PromptVersion: req.PromptVersion,
|
||||
ProfileID: req.ProfileID,
|
||||
SessionID: req.SessionID,
|
||||
Inputs: mappedInputs,
|
||||
Vars: req.Vars,
|
||||
Execution: model,
|
||||
TransientRetries: req.TransientRetries,
|
||||
})
|
||||
if err != nil {
|
||||
status, code, message := mapRunError(err)
|
||||
@@ -224,7 +229,7 @@ func mapRunError(err error) (int, string, string) {
|
||||
return http.StatusBadRequest, "prompt_render_failed", "failed to render prompt"
|
||||
case errors.Is(err, promptkit.ErrCapacityExceeded):
|
||||
return http.StatusServiceUnavailable, "capacity_exceeded", "model backend capacity is exhausted"
|
||||
case errors.Is(err, promptkit.ErrLLMGenerate):
|
||||
case errors.Is(err, promptkit.ErrLLMGenerate), errors.Is(err, promptkit.ErrTransport), errors.Is(err, promptkit.ErrMalformedResponse), errors.Is(err, promptkit.ErrRetriesExhausted):
|
||||
return http.StatusBadGateway, "llm_failed", "model generation request failed"
|
||||
case errors.Is(err, promptkit.ErrValidation):
|
||||
return http.StatusInternalServerError, "validation_runtime_failed", "validation runtime failed"
|
||||
|
||||
Reference in New Issue
Block a user