Skip to content

Commit a4bd7aa

Browse files
authored
feat: add model name to api output. (#170)
1 parent 6e147d6 commit a4bd7aa

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/dllama-api.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <iostream>
88
#include <algorithm>
99
#include <vector>
10+
#include <string>
1011

1112
#ifdef _WIN32
1213
#include <winsock2.h>
@@ -492,11 +493,16 @@ void handleCompletionsRequest(HttpRequest& request, ApiServer *api) {
492493
api->complete(request);
493494
}
494495

495-
void handleModelsRequest(HttpRequest& request) {
496+
void handleModelsRequest(HttpRequest& request, const char* modelPath) {
497+
std::string path(modelPath);
498+
499+
size_t pos = path.find_last_of("/\\");
500+
std::string modelName = (pos == std::string::npos) ? path : path.substr(pos+1);
501+
496502
request.writeJson(
497503
"{ \"object\": \"list\","
498504
"\"data\": ["
499-
"{ \"id\": \"dl\", \"object\": \"model\", \"created\": 0, \"owned_by\": \"user\" }"
505+
"{ \"id\": \"" + modelName + "\", \"object\": \"model\", \"created\": 0, \"owned_by\": \"user\" }"
500506
"] }");
501507
}
502508

@@ -519,7 +525,7 @@ static void server(AppInferenceContext *context) {
519525
{
520526
"/v1/models",
521527
HttpMethod::METHOD_GET,
522-
std::bind(&handleModelsRequest, std::placeholders::_1)
528+
std::bind(&handleModelsRequest, std::placeholders::_1, context->args->modelPath)
523529
}
524530
};
525531

0 commit comments

Comments
 (0)