Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 8630779

Browse files
committed
add base class for inference provider
1 parent 7da4bd2 commit 8630779

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

common/base.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "base.h"
2+
3+
void BaseProvider::handlePrelight(
4+
const HttpRequestPtr &req,
5+
std::function<void(const HttpResponsePtr &)> &&callback) {
6+
auto resp = drogon::HttpResponse::newHttpResponse();
7+
resp->setStatusCode(drogon::HttpStatusCode::k200OK);
8+
resp->addHeader("Access-Control-Allow-Origin", "*");
9+
resp->addHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
10+
resp->addHeader("Access-Control-Allow-Headers", "*");
11+
callback(resp);
12+
}

common/base.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#pragma once
2+
#include <drogon/HttpController.h>
3+
4+
using namespace drogon;
5+
6+
#pragma once
7+
#include <drogon/HttpController.h>
8+
9+
using namespace drogon;
10+
11+
class BaseProvider {
12+
public:
13+
virtual ~BaseProvider() {}
14+
15+
// General inference method
16+
virtual void
17+
inference(const HttpRequestPtr &req,
18+
std::function<void(const HttpResponsePtr &)> &&callback) = 0;
19+
20+
// Model management
21+
virtual void
22+
loadModel(const HttpRequestPtr &req,
23+
std::function<void(const HttpResponsePtr &)> &&callback) = 0;
24+
virtual void
25+
unloadModel(const HttpRequestPtr &req,
26+
std::function<void(const HttpResponsePtr &)> &&callback) = 0;
27+
virtual void
28+
modelStatus(const HttpRequestPtr &req,
29+
std::function<void(const HttpResponsePtr &)> &&callback) = 0;
30+
31+
// Additional methods
32+
void handlePrelight(const HttpRequestPtr &req,
33+
std::function<void(const HttpResponsePtr &)> &&callback);
34+
};
35+
36+
class ChatProvider : public BaseProvider {
37+
public:
38+
virtual ~ChatProvider() {}
39+
40+
// Implement embedding functionality specific to chat
41+
virtual void
42+
embedding(const HttpRequestPtr &req,
43+
std::function<void(const HttpResponsePtr &)> &&callback) = 0;
44+
45+
// The derived class can also override other methods if needed
46+
};

0 commit comments

Comments
 (0)