Skip to content

Commit

Permalink
Added version API and test case (#37)
Browse files Browse the repository at this point in the history
- Added version.js
- Added versionGet.js
- Modified index.js
- Modified test_apis.py

Signed-off-by: Murkeee <[email protected]>
  • Loading branch information
Murkeee authored Aug 7, 2024
1 parent ec575b1 commit dda976d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 50 deletions.
6 changes: 6 additions & 0 deletions example/test_apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ def test_api_key(self):
self.assertEqual(res.status_code, 200)
# api key should not be empty
self.assertTrue(len(res.json().get("api_key"))>0)

def test_version_api(self):
res = requests.get(url=self.base_url+"/v1/version")
self.assertEqual(res.status_code, 200)
data = res.json().get("inference_engine_version")
self.assertEqual('server--b1-2321a5e', data)
102 changes: 52 additions & 50 deletions routes/index.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
// coding=utf-8

// Copyright [2024] [SkywardAI]
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Router } from "express";

import inferenceRoute from "./inference.js";
import tokenRoute from "./token.js";
import tracingRoute from "./tracing.js";
import embeddingRoute from "./embedding.js";
import encoderRoute from "./encoder.js";
import decoderRoute from "./decoder.js";

function indexRoute() {
const router = Router();

router.get('/healthy', (_, res)=>{
res.status(200).send('ok')
})

return router;
}

function generateAPIRouters() {
const api_router = Router();

api_router.use('/chat', inferenceRoute());
api_router.use('/token', tokenRoute());
api_router.use('/tracing', tracingRoute());
api_router.use('/embeddings', embeddingRoute());
api_router.use('/encoder', encoderRoute());
api_router.use('/decoder', decoderRoute());

return api_router;
}

export default function buildRoutes(app) {
app.use('/', indexRoute());
app.use('/v1', generateAPIRouters());
// coding=utf-8

// Copyright [2024] [SkywardAI]
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Router } from "express";

import inferenceRoute from "./inference.js";
import tokenRoute from "./token.js";
import tracingRoute from "./tracing.js";
import embeddingRoute from "./embedding.js";
import encoderRoute from "./encoder.js";
import decoderRoute from "./decoder.js";
import versionRoute from "./version.js";

function indexRoute() {
const router = Router();

router.get('/healthy', (_, res)=>{
res.status(200).send('ok')
})

return router;
}

function generateAPIRouters() {
const api_router = Router();

api_router.use('/chat', inferenceRoute());
api_router.use('/token', tokenRoute());
api_router.use('/tracing', tracingRoute());
api_router.use('/embedding', embeddingRoute());
api_router.use('/encoder', encoderRoute());
api_router.use('/decoder', decoderRoute());
api_router.use('/version', versionRoute());

return api_router;
}

export default function buildRoutes(app) {
app.use('/', indexRoute());
app.use('/v1', generateAPIRouters());
}
27 changes: 27 additions & 0 deletions routes/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// coding=utf-8

// Copyright [2024] [SkywardAI]
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import { Router } from "express";
import { fetchVersions } from "../tools/versionGet.js";

export default function versionRoute() {
const router = Router();

router.get('', (_, res)=>{
res.send({inference_engine_version: fetchVersions().inferenceEngVersion})
})

return router;
}
23 changes: 23 additions & 0 deletions tools/versionGet.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// coding=utf-8

// Copyright [2024] [SkywardAI]
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

export function fetchVersions(){
const versionArray = {}; //Object to store versions
//When a new service version is added just define a new object property and
//call process.env to fetch the value from the environment.
versionArray.inferenceEngVersion = process.env.INFERENCE_ENG_VERSION;
return versionArray;
}

0 comments on commit dda976d

Please sign in to comment.