Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pkg/inference/scheduling/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@ type OpenAIInferenceRequest struct {
Model string `json:"model"`
}

// OpenAIErrorResponse is used to format an OpenAI API compatible error response
// (see https://platform.openai.com/docs/api-reference/responses-streaming/error)
type OpenAIErrorResponse struct {
Type string `json:"type"` // always "error"
Code *string `json:"code"`
Message string `json:"message"`
Param *string `json:"param"`
SequenceNumber int `json:"sequence_number"`
}

// BackendStatus represents information about a running backend
type BackendStatus struct {
// BackendName is the name of the backend
Expand Down
6 changes: 5 additions & 1 deletion pkg/inference/scheduling/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,11 @@ func (l *loader) load(ctx context.Context, backendName, model string, mode infer
select {
case <-l.slots[existing].done:
l.log.Warnf("%s runner for %s is defunct. Waiting for it to be evicted.", backendName, model)
goto WaitForChange
if l.references[existing] == 0 {
l.evictRunner(backendName, model, mode)
} else {
goto WaitForChange
}
default:
l.references[existing] += 1
l.timestamps[existing] = time.Time{}
Expand Down
13 changes: 13 additions & 0 deletions pkg/inference/scheduling/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package scheduling

import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
Expand Down Expand Up @@ -143,6 +144,18 @@ func run(
w.WriteHeader(http.StatusInternalServerError)
select {
case <-r.done:
res := OpenAIErrorResponse{
Type: "error",
Code: nil,
Message: r.err.Error(),
Param: nil,
SequenceNumber: 1,
}
errJson, err := json.Marshal(&res)
if err == nil {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
w.Write(errJson)
}
return
case <-time.After(30 * time.Second):
}
Expand Down