From 807104e18b5770c512834c13e97c10a3af5f5743 Mon Sep 17 00:00:00 2001 From: lemmi <lemmi@nerd2nerd.org> Date: Sun, 16 Feb 2025 19:51:26 +0100 Subject: [PATCH] dllama-api: /v1/models: return basename of the model Change the /v1/models api endpoint to return the basename of the model path instead of the hardcoded value "dl". --- src/dllama-api.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/dllama-api.cpp b/src/dllama-api.cpp index af4f92e..6bca0f4 100644 --- a/src/dllama-api.cpp +++ b/src/dllama-api.cpp @@ -7,6 +7,7 @@ #include <iostream> #include <algorithm> #include <vector> +#include <string> #ifdef _WIN32 #include <winsock2.h> @@ -492,11 +493,16 @@ void handleCompletionsRequest(HttpRequest& request, ApiServer *api) { api->complete(request); } -void handleModelsRequest(HttpRequest& request) { +void handleModelsRequest(HttpRequest& request, const char* modelPath) { + std::string path(modelPath); + + size_t pos = path.find_last_of("/\\"); + std::string modelName = (pos == std::string::npos) ? path : path.substr(pos+1); + request.writeJson( "{ \"object\": \"list\"," "\"data\": [" - "{ \"id\": \"dl\", \"object\": \"model\", \"created\": 0, \"owned_by\": \"user\" }" + "{ \"id\": \"" + modelName + "\", \"object\": \"model\", \"created\": 0, \"owned_by\": \"user\" }" "] }"); } @@ -519,7 +525,7 @@ static void server(AppInferenceContext *context) { { "/v1/models", HttpMethod::METHOD_GET, - std::bind(&handleModelsRequest, std::placeholders::_1) + std::bind(&handleModelsRequest, std::placeholders::_1, context->args->modelPath) } };