From dda976d60b40eea77078fabf822325d36b90727a Mon Sep 17 00:00:00 2001 From: Tyson Dai <100662199+Murkeee@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:28:38 +1000 Subject: [PATCH] Added version API and test case (#37) - Added version.js - Added versionGet.js - Modified index.js - Modified test_apis.py Signed-off-by: Murkeee <100662199+Murkeee@users.noreply.github.com> --- example/test_apis.py | 6 +++ routes/index.js | 102 ++++++++++++++++++++++--------------------- routes/version.js | 27 ++++++++++++ tools/versionGet.js | 23 ++++++++++ 4 files changed, 108 insertions(+), 50 deletions(-) create mode 100644 routes/version.js create mode 100644 tools/versionGet.js diff --git a/example/test_apis.py b/example/test_apis.py index a0b21c8..45cd092 100644 --- a/example/test_apis.py +++ b/example/test_apis.py @@ -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) \ No newline at end of file diff --git a/routes/index.js b/routes/index.js index 6e1fc0c..f090644 100644 --- a/routes/index.js +++ b/routes/index.js @@ -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()); } \ No newline at end of file diff --git a/routes/version.js b/routes/version.js new file mode 100644 index 0000000..4ce184b --- /dev/null +++ b/routes/version.js @@ -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; +} \ No newline at end of file diff --git a/tools/versionGet.js b/tools/versionGet.js new file mode 100644 index 0000000..afd715b --- /dev/null +++ b/tools/versionGet.js @@ -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; +} +