Skip to content

Commit fabc8ae

Browse files
authored
Added version API and test case
- Added version.js - Added versionGet.js - Modified index.js - Modified test_apis.py Signed-off-by: Murkeee <[email protected]>
1 parent ec575b1 commit fabc8ae

File tree

4 files changed

+108
-50
lines changed

4 files changed

+108
-50
lines changed

example/test_apis.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,9 @@ def test_api_key(self):
8989
self.assertEqual(res.status_code, 200)
9090
# api key should not be empty
9191
self.assertTrue(len(res.json().get("api_key"))>0)
92+
93+
def test_version_api(self):
94+
res = requests.get(url=self.base_url+"/v1/version")
95+
self.assertEqual(res.status_code, 200)
96+
data = res.json().get("inference_engine_version")
97+
self.assertEqual('server--b1-2321a5e', data)

routes/index.js

Lines changed: 52 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,53 @@
1-
// coding=utf-8
2-
3-
// Copyright [2024] [SkywardAI]
4-
// Licensed under the Apache License, Version 2.0 (the "License");
5-
// you may not use this file except in compliance with the License.
6-
// You may obtain a copy of the License at
7-
8-
// http://www.apache.org/licenses/LICENSE-2.0
9-
10-
// Unless required by applicable law or agreed to in writing, software
11-
// distributed under the License is distributed on an "AS IS" BASIS,
12-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
// See the License for the specific language governing permissions and
14-
// limitations under the License.
15-
16-
import { Router } from "express";
17-
18-
import inferenceRoute from "./inference.js";
19-
import tokenRoute from "./token.js";
20-
import tracingRoute from "./tracing.js";
21-
import embeddingRoute from "./embedding.js";
22-
import encoderRoute from "./encoder.js";
23-
import decoderRoute from "./decoder.js";
24-
25-
function indexRoute() {
26-
const router = Router();
27-
28-
router.get('/healthy', (_, res)=>{
29-
res.status(200).send('ok')
30-
})
31-
32-
return router;
33-
}
34-
35-
function generateAPIRouters() {
36-
const api_router = Router();
37-
38-
api_router.use('/chat', inferenceRoute());
39-
api_router.use('/token', tokenRoute());
40-
api_router.use('/tracing', tracingRoute());
41-
api_router.use('/embeddings', embeddingRoute());
42-
api_router.use('/encoder', encoderRoute());
43-
api_router.use('/decoder', decoderRoute());
44-
45-
return api_router;
46-
}
47-
48-
export default function buildRoutes(app) {
49-
app.use('/', indexRoute());
50-
app.use('/v1', generateAPIRouters());
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
import { Router } from "express";
17+
18+
import inferenceRoute from "./inference.js";
19+
import tokenRoute from "./token.js";
20+
import tracingRoute from "./tracing.js";
21+
import embeddingRoute from "./embedding.js";
22+
import encoderRoute from "./encoder.js";
23+
import decoderRoute from "./decoder.js";
24+
import versionRoute from "./version.js";
25+
26+
function indexRoute() {
27+
const router = Router();
28+
29+
router.get('/healthy', (_, res)=>{
30+
res.status(200).send('ok')
31+
})
32+
33+
return router;
34+
}
35+
36+
function generateAPIRouters() {
37+
const api_router = Router();
38+
39+
api_router.use('/chat', inferenceRoute());
40+
api_router.use('/token', tokenRoute());
41+
api_router.use('/tracing', tracingRoute());
42+
api_router.use('/embedding', embeddingRoute());
43+
api_router.use('/encoder', encoderRoute());
44+
api_router.use('/decoder', decoderRoute());
45+
api_router.use('/version', versionRoute());
46+
47+
return api_router;
48+
}
49+
50+
export default function buildRoutes(app) {
51+
app.use('/', indexRoute());
52+
app.use('/v1', generateAPIRouters());
5153
}

routes/version.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
import { Router } from "express";
17+
import { fetchVersions } from "../tools/versionGet.js";
18+
19+
export default function versionRoute() {
20+
const router = Router();
21+
22+
router.get('', (_, res)=>{
23+
res.send({inference_engine_version: fetchVersions().inferenceEngVersion})
24+
})
25+
26+
return router;
27+
}

tools/versionGet.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// coding=utf-8
2+
3+
// Copyright [2024] [SkywardAI]
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
export function fetchVersions(){
17+
const versionArray = {}; //Object to store versions
18+
//When a new service version is added just define a new object property and
19+
//call process.env to fetch the value from the environment.
20+
versionArray.inferenceEngVersion = process.env.INFERENCE_ENG_VERSION;
21+
return versionArray;
22+
}
23+

0 commit comments

Comments
 (0)