diff --git a/.github/workflows/llmsecops-cicd.llm.yml b/.github/workflows/llmsecops-cicd.llm.yml index 29c411e79..be9ece60d 100644 --- a/.github/workflows/llmsecops-cicd.llm.yml +++ b/.github/workflows/llmsecops-cicd.llm.yml @@ -33,9 +33,9 @@ jobs: - name: 'run HTTP server and call REST API' run: | - python -m tests.api.server + python -m src.api.controller sleep 2 - curl -X POST -i localhost:9999/api/conversations -d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' || exit 1 + curl -X POST -i localhost:9998/api/conversations -d '{ "prompt": "describe a random planet in our solar system in 10 words or less" }' -H "Content-Type: application/json" || exit 1 echo garak -v \ diff --git a/.gitignore b/.gitignore index 6c65f4fce..388b28f50 100644 --- a/.gitignore +++ b/.gitignore @@ -175,13 +175,13 @@ cython_debug/ # HuggingFace / Microsoft LLM supporting files # (these are downloaded for local development via bash script, or inside GH Action workflow context) -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/added_tokens.json -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/config.json -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/configuration_phi3.py -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/genai_config.json -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx.data -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/special_tokens_map.json -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer_config.json -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.json -tests/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.model +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/added_tokens.json +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/config.json +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/configuration_phi3.py +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/genai_config.json +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/phi3-mini-4k-instruct-cpu-int4-rtn-block-32-acc-level-4.onnx.data +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/special_tokens_map.json +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer_config.json +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.json +src/llm/cpu_and_mobile/cpu-int4-rtn-block-32-acc-level-4/tokenizer.model diff --git a/tests/__init__.py b/src/__init__.py similarity index 100% rename from tests/__init__.py rename to src/__init__.py diff --git a/tests/api/__init__.py b/src/api/__init__.py similarity index 100% rename from tests/api/__init__.py rename to src/api/__init__.py diff --git a/tests/api/controller.py b/src/api/controller.backup.py similarity index 98% rename from tests/api/controller.py rename to src/api/controller.backup.py index 10d176e5c..c67d16c9f 100644 --- a/tests/api/controller.py +++ b/src/api/controller.backup.py @@ -1,8 +1,8 @@ import json import traceback -from tests.llm.llm import Phi3LanguageModel -from tests.llm.llm_rag import Phi3LanguageModelWithRag +from src.llm.llm import Phi3LanguageModel +from src.llm.llm_rag import Phi3LanguageModelWithRag class ApiController: def __init__(self): diff --git a/src/api/controller.py b/src/api/controller.py new file mode 100644 index 000000000..92091f8e7 --- /dev/null +++ b/src/api/controller.py @@ -0,0 +1,19 @@ +import logging +from flask import Flask, jsonify, request +from src.llm.llm import Phi3LanguageModel +from src.llm.llm_rag import Phi3LanguageModelWithRag + +app = Flask(__name__) + +@app.route('/api/conversations', methods=['POST']) +def get_llm_response(): + prompt = request.json['prompt'] + service = Phi3LanguageModel() + response = service.invoke(user_input=prompt) + return jsonify({'response': response}), 201 + +if __name__ == '__main__': + logger = logging.Logger(name='Flask API', level=logging.DEBUG) + print('test') + logger.debug('running...') + app.run(debug=True, port=9998) \ No newline at end of file diff --git a/tests/api/server.py b/src/api/server.py similarity index 100% rename from tests/api/server.py rename to src/api/server.py diff --git a/tests/llm/__init__.py b/src/llm/__init__.py similarity index 100% rename from tests/llm/__init__.py rename to src/llm/__init__.py diff --git a/tests/llm/embedding_model.py b/src/llm/embedding_model.py similarity index 100% rename from tests/llm/embedding_model.py rename to src/llm/embedding_model.py diff --git a/tests/llm/llm.py b/src/llm/llm.py similarity index 98% rename from tests/llm/llm.py rename to src/llm/llm.py index a07722d5b..0bdf80781 100644 --- a/tests/llm/llm.py +++ b/src/llm/llm.py @@ -32,7 +32,7 @@ class Phi3LanguageModel: return text - def invoke(self, user_input): + def invoke(self, user_input: str) -> str: # Set up paths to the local model 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") diff --git a/tests/llm/llm_rag.py b/src/llm/llm_rag.py similarity index 100% rename from tests/llm/llm_rag.py rename to src/llm/llm_rag.py diff --git a/tests/llm/phi3-qa.py b/src/llm/phi3-qa.py similarity index 100% rename from tests/llm/phi3-qa.py rename to src/llm/phi3-qa.py diff --git a/tests/llm/phi3_language_model.py b/src/llm/phi3_language_model.py similarity index 100% rename from tests/llm/phi3_language_model.py rename to src/llm/phi3_language_model.py diff --git a/tests/llm/rag.py b/src/llm/rag.py similarity index 100% rename from tests/llm/rag.py rename to src/llm/rag.py diff --git a/tests/tools/garak.config.test.yml b/src/tools/garak.config.test.yml similarity index 100% rename from tests/tools/garak.config.test.yml rename to src/tools/garak.config.test.yml diff --git a/tests/tools/garak.config.yml b/src/tools/garak.config.yml similarity index 100% rename from tests/tools/garak.config.yml rename to src/tools/garak.config.yml diff --git a/tests/tools/garak.rest.llm-rag.json b/src/tools/garak.rest.llm-rag.json similarity index 100% rename from tests/tools/garak.rest.llm-rag.json rename to src/tools/garak.rest.llm-rag.json diff --git a/tests/tools/garak.rest.llm.json b/src/tools/garak.rest.llm.json similarity index 100% rename from tests/tools/garak.rest.llm.json rename to src/tools/garak.rest.llm.json diff --git a/tests/test.http_api.py b/tests/test.http_api.py new file mode 100644 index 000000000..e69de29bb