From 30e40ecd3086aafb458ed743561f54bf30d94de1 Mon Sep 17 00:00:00 2001 From: LordMathis Date: Tue, 23 Sep 2025 21:27:58 +0200 Subject: [PATCH] Refactor API endpoints to use /backends/llama-cpp path and update related documentation --- apidocs/docs.go | 168 ++++++++++++++++++++--------------------- apidocs/swagger.json | 168 ++++++++++++++++++++--------------------- apidocs/swagger.yaml | 102 ++++++++++++------------- pkg/server/handlers.go | 12 +-- pkg/server/routes.go | 9 +-- 5 files changed, 228 insertions(+), 231 deletions(-) diff --git a/apidocs/docs.go b/apidocs/docs.go index d5108e1..4b521b1 100644 --- a/apidocs/docs.go +++ b/apidocs/docs.go @@ -19,6 +19,62 @@ const docTemplate = `{ "host": "{{.Host}}", "basePath": "{{.BasePath}}", "paths": { + "/backends/llama-cpp/devices": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Returns a list of available devices for the llama server", + "tags": [ + "backends" + ], + "summary": "List available devices for llama server", + "responses": { + "200": { + "description": "List of devices", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, + "/backends/llama-cpp/help": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Returns the help text for the llama server command", + "tags": [ + "backends" + ], + "summary": "Get help for llama server", + "responses": { + "200": { + "description": "Help text", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/backends/llama-cpp/parse-command": { "post": { "security": [ @@ -76,6 +132,34 @@ const docTemplate = `{ } } }, + "/backends/llama-cpp/version": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Returns the version of the llama server command", + "tags": [ + "backends" + ], + "summary": "Get version of llama server", + "responses": { + "200": { + "description": "Version information", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/backends/mlx/parse-command": { "post": { "security": [ @@ -658,90 +742,6 @@ const docTemplate = `{ } } }, - "/server/devices": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Returns a list of available devices for the llama server", - "tags": [ - "server" - ], - "summary": "List available devices for llama server", - "responses": { - "200": { - "description": "List of devices", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, - "/server/help": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Returns the help text for the llama server command", - "tags": [ - "server" - ], - "summary": "Get help for llama server", - "responses": { - "200": { - "description": "Help text", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, - "/server/version": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Returns the version of the llama server command", - "tags": [ - "server" - ], - "summary": "Get version of llama server", - "responses": { - "200": { - "description": "Version information", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, "/v1/": { "post": { "security": [ diff --git a/apidocs/swagger.json b/apidocs/swagger.json index 9648cc0..71471e6 100644 --- a/apidocs/swagger.json +++ b/apidocs/swagger.json @@ -12,6 +12,62 @@ }, "basePath": "/api/v1", "paths": { + "/backends/llama-cpp/devices": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Returns a list of available devices for the llama server", + "tags": [ + "backends" + ], + "summary": "List available devices for llama server", + "responses": { + "200": { + "description": "List of devices", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, + "/backends/llama-cpp/help": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Returns the help text for the llama server command", + "tags": [ + "backends" + ], + "summary": "Get help for llama server", + "responses": { + "200": { + "description": "Help text", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/backends/llama-cpp/parse-command": { "post": { "security": [ @@ -69,6 +125,34 @@ } } }, + "/backends/llama-cpp/version": { + "get": { + "security": [ + { + "ApiKeyAuth": [] + } + ], + "description": "Returns the version of the llama server command", + "tags": [ + "backends" + ], + "summary": "Get version of llama server", + "responses": { + "200": { + "description": "Version information", + "schema": { + "type": "string" + } + }, + "500": { + "description": "Internal Server Error", + "schema": { + "type": "string" + } + } + } + } + }, "/backends/mlx/parse-command": { "post": { "security": [ @@ -651,90 +735,6 @@ } } }, - "/server/devices": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Returns a list of available devices for the llama server", - "tags": [ - "server" - ], - "summary": "List available devices for llama server", - "responses": { - "200": { - "description": "List of devices", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, - "/server/help": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Returns the help text for the llama server command", - "tags": [ - "server" - ], - "summary": "Get help for llama server", - "responses": { - "200": { - "description": "Help text", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, - "/server/version": { - "get": { - "security": [ - { - "ApiKeyAuth": [] - } - ], - "description": "Returns the version of the llama server command", - "tags": [ - "server" - ], - "summary": "Get version of llama server", - "responses": { - "200": { - "description": "Version information", - "schema": { - "type": "string" - } - }, - "500": { - "description": "Internal Server Error", - "schema": { - "type": "string" - } - } - } - } - }, "/v1/": { "post": { "security": [ diff --git a/apidocs/swagger.yaml b/apidocs/swagger.yaml index 4b68861..a5db184 100644 --- a/apidocs/swagger.yaml +++ b/apidocs/swagger.yaml @@ -88,6 +88,40 @@ info: title: llamactl API version: "1.0" paths: + /backends/llama-cpp/devices: + get: + description: Returns a list of available devices for the llama server + responses: + "200": + description: List of devices + schema: + type: string + "500": + description: Internal Server Error + schema: + type: string + security: + - ApiKeyAuth: [] + summary: List available devices for llama server + tags: + - backends + /backends/llama-cpp/help: + get: + description: Returns the help text for the llama server command + responses: + "200": + description: Help text + schema: + type: string + "500": + description: Internal Server Error + schema: + type: string + security: + - ApiKeyAuth: [] + summary: Get help for llama server + tags: + - backends /backends/llama-cpp/parse-command: post: consumes: @@ -124,6 +158,23 @@ paths: summary: Parse llama-server command tags: - backends + /backends/llama-cpp/version: + get: + description: Returns the version of the llama server command + responses: + "200": + description: Version information + schema: + type: string + "500": + description: Internal Server Error + schema: + type: string + security: + - ApiKeyAuth: [] + summary: Get version of llama server + tags: + - backends /backends/mlx/parse-command: post: consumes: @@ -494,57 +545,6 @@ paths: summary: Stop a running instance tags: - instances - /server/devices: - get: - description: Returns a list of available devices for the llama server - responses: - "200": - description: List of devices - schema: - type: string - "500": - description: Internal Server Error - schema: - type: string - security: - - ApiKeyAuth: [] - summary: List available devices for llama server - tags: - - server - /server/help: - get: - description: Returns the help text for the llama server command - responses: - "200": - description: Help text - schema: - type: string - "500": - description: Internal Server Error - schema: - type: string - security: - - ApiKeyAuth: [] - summary: Get help for llama server - tags: - - server - /server/version: - get: - description: Returns the version of the llama server command - responses: - "200": - description: Version information - schema: - type: string - "500": - description: Internal Server Error - schema: - type: string - security: - - ApiKeyAuth: [] - summary: Get version of llama server - tags: - - server /v1/: post: consumes: diff --git a/pkg/server/handlers.go b/pkg/server/handlers.go index d1c4d08..594c273 100644 --- a/pkg/server/handlers.go +++ b/pkg/server/handlers.go @@ -51,12 +51,12 @@ func (h *Handler) VersionHandler() http.HandlerFunc { // LlamaServerHelpHandler godoc // @Summary Get help for llama server // @Description Returns the help text for the llama server command -// @Tags server +// @Tags backends // @Security ApiKeyAuth // @Produces text/plain // @Success 200 {string} string "Help text" // @Failure 500 {string} string "Internal Server Error" -// @Router /server/help [get] +// @Router /backends/llama-cpp/help [get] func (h *Handler) LlamaServerHelpHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { helpCmd := exec.Command("llama-server", "--help") @@ -73,12 +73,12 @@ func (h *Handler) LlamaServerHelpHandler() http.HandlerFunc { // LlamaServerVersionHandler godoc // @Summary Get version of llama server // @Description Returns the version of the llama server command -// @Tags server +// @Tags backends // @Security ApiKeyAuth // @Produces text/plain // @Success 200 {string} string "Version information" // @Failure 500 {string} string "Internal Server Error" -// @Router /server/version [get] +// @Router /backends/llama-cpp/version [get] func (h *Handler) LlamaServerVersionHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { versionCmd := exec.Command("llama-server", "--version") @@ -95,12 +95,12 @@ func (h *Handler) LlamaServerVersionHandler() http.HandlerFunc { // LlamaServerListDevicesHandler godoc // @Summary List available devices for llama server // @Description Returns a list of available devices for the llama server -// @Tags server +// @Tags backends // @Security ApiKeyAuth // @Produces text/plain // @Success 200 {string} string "List of devices" // @Failure 500 {string} string "Internal Server Error" -// @Router /server/devices [get] +// @Router /backends/llama-cpp/devices [get] func (h *Handler) LlamaServerListDevicesHandler() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { listCmd := exec.Command("llama-server", "--list-devices") diff --git a/pkg/server/routes.go b/pkg/server/routes.go index 898b574..6af6a5c 100644 --- a/pkg/server/routes.go +++ b/pkg/server/routes.go @@ -44,15 +44,12 @@ func SetupRouter(handler *Handler) *chi.Mux { r.Get("/version", handler.VersionHandler()) // Get server version - r.Route("/server", func(r chi.Router) { - r.Get("/help", handler.LlamaServerHelpHandler()) - r.Get("/version", handler.LlamaServerVersionHandler()) - r.Get("/devices", handler.LlamaServerListDevicesHandler()) - }) - // Backend-specific endpoints r.Route("/backends", func(r chi.Router) { r.Route("/llama-cpp", func(r chi.Router) { + r.Get("/help", handler.LlamaServerHelpHandler()) + r.Get("/version", handler.LlamaServerVersionHandler()) + r.Get("/devices", handler.LlamaServerListDevicesHandler()) r.Post("/parse-command", handler.ParseLlamaCommand()) }) r.Route("/mlx", func(r chi.Router) {