mirror of
https://github.com/mudler/LocalAI.git
synced 2026-04-29 03:24:49 -04:00
fix(backend-monitor): accept model as a query parameter (#9411)
The /backend/monitor endpoint is routed as GET but its handler bound the
model name from a request body, which is invalid per REST and breaks
Swagger UI and OpenAPI codegen tools that refuse to send bodies with GET.
Switch to reading ?model=<name> as a query parameter and update the
Swagger annotation, regenerated spec files, and documentation. The
handler still falls back to body binding when the query parameter is
absent, so existing clients sending {"model": "..."} continue to work.
Fixes #9207
Signed-off-by: Adira Denis Muhando <dennisadira@gmail.com>
This commit is contained in:
@@ -9,19 +9,26 @@ import (
|
||||
// BackendMonitorEndpoint returns the status of the specified backend
|
||||
// @Summary Backend monitor endpoint
|
||||
// @Tags monitoring
|
||||
// @Param request body schema.BackendMonitorRequest true "Backend statistics request"
|
||||
// @Param model query string true "Name of the model to monitor"
|
||||
// @Success 200 {object} proto.StatusResponse "Response"
|
||||
// @Router /backend/monitor [get]
|
||||
func BackendMonitorEndpoint(bm *monitoring.BackendMonitorService) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
|
||||
input := new(schema.BackendMonitorRequest)
|
||||
// Get input data from the request body
|
||||
if err := c.Bind(input); err != nil {
|
||||
return err
|
||||
model := c.QueryParam("model")
|
||||
// Fall back to binding the request body so pre-existing clients that
|
||||
// sent `{"model": "..."}` with GET keep working.
|
||||
if model == "" {
|
||||
input := new(schema.BackendMonitorRequest)
|
||||
if err := c.Bind(input); err != nil {
|
||||
return err
|
||||
}
|
||||
model = input.Model
|
||||
}
|
||||
if model == "" {
|
||||
return echo.NewHTTPError(400, "model query parameter is required")
|
||||
}
|
||||
|
||||
resp, err := bm.CheckAndSample(input.Model)
|
||||
resp, err := bm.CheckAndSample(model)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -14,11 +14,13 @@ LocalAI provides endpoints to monitor and manage running backends. The `/backend
|
||||
|
||||
### Request
|
||||
|
||||
The request body is JSON:
|
||||
The model to monitor is passed as a query parameter:
|
||||
|
||||
| Parameter | Type | Required | Description |
|
||||
|-----------|----------|----------|--------------------------------|
|
||||
| `model` | `string` | Yes | Name of the model to monitor |
|
||||
| Parameter | Type | Required | Location | Description |
|
||||
|-----------|----------|----------|----------|--------------------------------|
|
||||
| `model` | `string` | Yes | query | Name of the model to monitor |
|
||||
|
||||
For backwards compatibility, a JSON body with the same field is still accepted when the `model` query parameter is not set, but new clients should use the query parameter.
|
||||
|
||||
### Response
|
||||
|
||||
@@ -42,9 +44,7 @@ If the gRPC status call fails, the endpoint falls back to local process metrics:
|
||||
### Usage
|
||||
|
||||
```bash
|
||||
curl http://localhost:8080/backend/monitor \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"model": "my-model"}'
|
||||
curl "http://localhost:8080/backend/monitor?model=my-model"
|
||||
```
|
||||
|
||||
### Example response
|
||||
|
||||
@@ -985,13 +985,11 @@ const docTemplate = `{
|
||||
"summary": "Backend monitor endpoint",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Backend statistics request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.BackendMonitorRequest"
|
||||
}
|
||||
"type": "string",
|
||||
"description": "Name of the model to monitor",
|
||||
"name": "model",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
||||
@@ -982,13 +982,11 @@
|
||||
"summary": "Backend monitor endpoint",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Backend statistics request",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/schema.BackendMonitorRequest"
|
||||
}
|
||||
"type": "string",
|
||||
"description": "Name of the model to monitor",
|
||||
"name": "model",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
|
||||
@@ -2382,12 +2382,11 @@ paths:
|
||||
/backend/monitor:
|
||||
get:
|
||||
parameters:
|
||||
- description: Backend statistics request
|
||||
in: body
|
||||
name: request
|
||||
- description: Name of the model to monitor
|
||||
in: query
|
||||
name: model
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/schema.BackendMonitorRequest'
|
||||
type: string
|
||||
responses:
|
||||
"200":
|
||||
description: Response
|
||||
|
||||
Reference in New Issue
Block a user