From c9c5b8b0a7a022ede2ede2dafb599733bd3cb1fe Mon Sep 17 00:00:00 2001 From: Adam Wilson Date: Thu, 24 Apr 2025 11:27:03 -0600 Subject: [PATCH] use Python package approach to project structure --- .github/workflows/llmsecops-cicd.yml | 3 ++- tests/__init__.py | 0 tests/api/__init__.py | 0 tests/api/controller.py | 7 +------ tests/api/server.py | 2 +- tests/llm/__init__.py | 0 tests/llm/phi3_language_model.py | 8 ++++---- 7 files changed, 8 insertions(+), 12 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/api/__init__.py create mode 100644 tests/llm/__init__.py diff --git a/.github/workflows/llmsecops-cicd.yml b/.github/workflows/llmsecops-cicd.yml index cc2877a22..c9130131d 100644 --- a/.github/workflows/llmsecops-cicd.yml +++ b/.github/workflows/llmsecops-cicd.yml @@ -36,7 +36,8 @@ jobs: - name: Run REST API server run: | - python ${{ github.workspace }}/tests/api/server.py & + # python ${{ github.workspace }}/tests/api/server.py & + python -m tests.api.server - name: Test API call run: | diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/api/__init__.py b/tests/api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/api/controller.py b/tests/api/controller.py index 20612ed99..2dc1a7676 100644 --- a/tests/api/controller.py +++ b/tests/api/controller.py @@ -1,11 +1,6 @@ import json -import os -import sys -# Add the parent folder (or any relative path) -sys.path.append(os.path.abspath('./../llm')) - -from phi3_language_model import Phi3LanguageModel +from tests.llm.phi3_language_model import Phi3LanguageModel class ApiController: diff --git a/tests/api/server.py b/tests/api/server.py index 2c08107c5..503cb5069 100644 --- a/tests/api/server.py +++ b/tests/api/server.py @@ -1,6 +1,6 @@ import json -from controller import ApiController +from tests.api.controller import ApiController from wsgiref.simple_server import make_server diff --git a/tests/llm/__init__.py b/tests/llm/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/llm/phi3_language_model.py b/tests/llm/phi3_language_model.py index 2e4721376..8c4eed47e 100644 --- a/tests/llm/phi3_language_model.py +++ b/tests/llm/phi3_language_model.py @@ -1,16 +1,16 @@ # TODO: business logic for REST API interaction w/ LLM via prompt input -import onnxruntime_genai as og import argparse +import onnxruntime_genai as og +import os -default_model_path = './cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4' - class Phi3LanguageModel: def __init__(self, model_path=None): # configure ONNX runtime - model_path = default_model_path if model_path == None else model_path + base_dir = os.path.dirname(os.path.abspath(__file__)) + model_path = os.path.join(base_dir, "cpu_and_mobile", "cpu-int4-rtn-block-32-acc-level-4") config = og.Config(model_path) config.clear_providers() self.model = og.Model(config)