From 397ad6fb9185b07469d1f4af6248656f533ad052 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Mon, 7 Oct 2024 10:21:23 +0700 Subject: [PATCH 01/12] fix: add HF token to header --- engine/services/model_service.cc | 3 ++- engine/utils/curl_utils.h | 14 +++++++----- engine/utils/huggingface_utils.h | 38 ++++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 10 deletions(-) diff --git a/engine/services/model_service.cc b/engine/services/model_service.cc index d9c2aa48f..27e64aa77 100644 --- a/engine/services/model_service.cc +++ b/engine/services/model_service.cc @@ -67,7 +67,8 @@ cpp::result GetDownloadTask( .pathParams = {"api", "models", "cortexso", modelId, "tree", branch}}; httplib::Client cli(url.GetProtocolAndHost()); - auto res = cli.Get(url.GetPathAndQuery()); + auto res = + cli.Get(url.GetPathAndQuery(), huggingface_utils::CreateHttpHfHeaders()); if (res->status != httplib::StatusCode::OK_200) { return cpp::fail("Model " + modelId + " not found"); } diff --git a/engine/utils/curl_utils.h b/engine/utils/curl_utils.h index 2640bdc9b..b52030726 100644 --- a/engine/utils/curl_utils.h +++ b/engine/utils/curl_utils.h @@ -14,7 +14,8 @@ size_t WriteCallback(void* contents, size_t size, size_t nmemb, } } // namespace -inline cpp::result SimpleGet(const std::string& url) { +inline cpp::result SimpleGet( + const std::string& url, curl_slist* headers = nullptr) { CURL* curl; CURLcode res; std::string readBuffer; @@ -27,6 +28,9 @@ inline cpp::result SimpleGet(const std::string& url) { return cpp::fail("Failed to init CURL"); } curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + if(headers) { + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + } // Set write function callback and data buffer curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); @@ -45,8 +49,8 @@ inline cpp::result SimpleGet(const std::string& url) { } inline cpp::result ReadRemoteYaml( - const std::string& url) { - auto result = SimpleGet(url); + const std::string& url, curl_slist* headers = nullptr) { + auto result = SimpleGet(url, headers); if (result.has_error()) { return cpp::fail(result.error()); } @@ -60,8 +64,8 @@ inline cpp::result ReadRemoteYaml( } inline cpp::result SimpleGetJson( - const std::string& url) { - auto result = SimpleGet(url); + const std::string& url, curl_slist* headers = nullptr) { + auto result = SimpleGet(url, headers); if (result.has_error()) { return cpp::fail(result.error()); } diff --git a/engine/utils/huggingface_utils.h b/engine/utils/huggingface_utils.h index 2c06afc2c..71482502c 100644 --- a/engine/utils/huggingface_utils.h +++ b/engine/utils/huggingface_utils.h @@ -47,6 +47,34 @@ struct HuggingFaceModelRepoInfo { std::string createdAt; }; +inline std::optional GetHuggingFaceToken() { + const char* token = std::getenv("HF_TOKEN"); + if (token != nullptr) { + return std::string(token); + } + return std::nullopt; +} + +inline curl_slist* CreateCurlHfHeaders() { + struct curl_slist* headers = nullptr; + auto hf_token = GetHuggingFaceToken(); + if (hf_token) { + std::string auth_header = "Authorization: Bearer " + hf_token.value(); + headers = curl_slist_append(headers, auth_header.c_str()); + headers = curl_slist_append(headers, "Content-Type: application/json"); + } + return headers; +} + +inline httplib::Headers CreateHttpHfHeaders() { + httplib::Headers headers; + auto token = GetHuggingFaceToken(); + if (token) { + headers.emplace("Authorization", "Bearer " + token.value()); + } + return headers; +} + inline cpp::result, std::string> GetModelRepositoryBranches(const std::string& author, @@ -59,7 +87,8 @@ GetModelRepositoryBranches(const std::string& author, .host = kHuggingfaceHost, .pathParams = {"api", "models", author, modelName, "refs"}}; - auto result = curl_utils::SimpleGetJson(url_obj.ToFullPath()); + auto result = + curl_utils::SimpleGetJson(url_obj.ToFullPath(), CreateCurlHfHeaders()); if (result.has_error()) { return cpp::fail("Failed to get model repository branches: " + author + "/" + modelName); @@ -91,7 +120,8 @@ GetHuggingFaceModelRepoInfo(const std::string& author, .host = kHuggingfaceHost, .pathParams = {"api", "models", author, modelName}}; - auto result = curl_utils::SimpleGetJson(url_obj.ToFullPath()); + auto result = + curl_utils::SimpleGetJson(url_obj.ToFullPath(), CreateCurlHfHeaders()); if (result.has_error()) { return cpp::fail("Failed to get model repository info: " + author + "/" + modelName); @@ -163,8 +193,8 @@ inline std::string GetDownloadableUrl(const std::string& author, inline std::optional GetDefaultBranch( const std::string& model_name) { - auto default_model_branch = - curl_utils::ReadRemoteYaml(GetMetadataUrl(model_name)); + auto default_model_branch = curl_utils::ReadRemoteYaml( + GetMetadataUrl(model_name), CreateCurlHfHeaders()); if (default_model_branch.has_error()) { return std::nullopt; From ad334bb5e7909d4c61280dc29ca11d01d9ea8c61 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Mon, 7 Oct 2024 10:28:50 +0700 Subject: [PATCH 02/12] fix: build --- engine/utils/huggingface_utils.h | 1 + 1 file changed, 1 insertion(+) diff --git a/engine/utils/huggingface_utils.h b/engine/utils/huggingface_utils.h index 71482502c..13ecc1bd1 100644 --- a/engine/utils/huggingface_utils.h +++ b/engine/utils/huggingface_utils.h @@ -3,6 +3,7 @@ #include #include #include +#include "httplib.h" #include "utils/curl_utils.h" #include "utils/json.hpp" #include "utils/result.hpp" From 60641086f17375fdd7b6560f7fab7aa8daa19e84 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Mon, 7 Oct 2024 10:47:40 +0700 Subject: [PATCH 03/12] fix: add header to model download if host is HF --- engine/services/download_service.cc | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/engine/services/download_service.cc b/engine/services/download_service.cc index ba7948477..e8f47d839 100644 --- a/engine/services/download_service.cc +++ b/engine/services/download_service.cc @@ -9,8 +9,10 @@ #include #include "download_service.h" #include "utils/format_utils.h" +#include "utils/huggingface_utils.h" #include "utils/logging_utils.h" #include "utils/result.hpp" +#include "utils/url_parser.h" #ifdef _WIN32 #define ftell64(f) _ftelli64(f) @@ -25,6 +27,20 @@ size_t WriteCallback(void* ptr, size_t size, size_t nmemb, FILE* stream) { size_t written = fwrite(ptr, size, nmemb, stream); return written; } + +inline curl_slist* CreateHeaders(const std::string& url) { + try { + auto url_obj = url_parser::FromUrlString(url); + if (url_obj.host == huggingface_utils::kHuggingfaceHost) { + return huggingface_utils::CreateCurlHfHeaders(); + } else { + return nullptr; + } + } catch (const std::exception& e) { + CTL_WRN(e.what()); + return nullptr; + } +} } // namespace cpp::result DownloadService::VerifyDownloadTask( @@ -99,6 +115,9 @@ cpp::result DownloadService::GetFileSize( curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_NOBODY, 1L); curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); + if (auto headers = CreateHeaders(url); headers) { + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + } CURLcode res = curl_easy_perform(curl); if (res != CURLE_OK) { @@ -173,7 +192,7 @@ cpp::result DownloadService::Download( CTL_INF("Existing file size: " << download_item.downloadUrl << " - " << download_item.localPath.string() << " - " << existing_file_size); - CTL_INF("Download item size: " << download_item.bytes.value()); + CTL_INF("Download item size: " << download_item.bytes.value()); auto missing_bytes = download_item.bytes.value() - existing_file_size; if (missing_bytes > 0 && download_item.localPath.extension().string() != ".yaml" && @@ -213,6 +232,9 @@ cpp::result DownloadService::Download( } curl_easy_setopt(curl, CURLOPT_URL, download_item.downloadUrl.c_str()); + if (auto headers = CreateHeaders(download_item.downloadUrl); headers) { + curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); + } curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, file); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); From 73ab81587f315964355e33bfeacbbb36c7c5ba0b Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Mon, 7 Oct 2024 10:49:00 +0700 Subject: [PATCH 04/12] fix: enable e2e tests --- .github/workflows/cortex-cpp-quality-gate.yml | 62 ++++++++++--------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 45c7235c7..2716ffe7e 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -106,36 +106,38 @@ jobs: cd engine make run-unit-tests - # - name: Run e2e tests - # if: runner.os != 'Windows' && github.event.pull_request.draft == false - # run: | - # cd engine - # cp build/cortex build/cortex-nightly - # cp build/cortex build/cortex-beta - # python -m pip install --upgrade pip - # python -m pip install pytest - # python -m pip install requests - # python e2e-test/main.py - # rm build/cortex-nightly - # rm build/cortex-beta - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - # - name: Run e2e tests - # if: runner.os == 'Windows' && github.event.pull_request.draft == false - # run: | - # cd engine - # cp build/cortex.exe build/cortex-nightly.exe - # cp build/cortex.exe build/cortex-beta.exe - # python -m pip install --upgrade pip - # python -m pip install pytest - # python -m pip install requests - # python e2e-test/main.py - # rm build/cortex-nightly.exe - # rm build/cortex-beta.exe - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Run e2e tests + if: runner.os != 'Windows' && github.event.pull_request.draft == false + run: | + cd engine + cp build/cortex build/cortex-nightly + cp build/cortex build/cortex-beta + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install requests + python e2e-test/main.py + rm build/cortex-nightly + rm build/cortex-beta + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN_READ }} + + + - name: Run e2e tests + if: runner.os == 'Windows' && github.event.pull_request.draft == false + run: | + cd engine + cp build/cortex.exe build/cortex-nightly.exe + cp build/cortex.exe build/cortex-beta.exe + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install requests + python e2e-test/main.py + rm build/cortex-nightly.exe + rm build/cortex-beta.exe + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN_READ }} - name: Pre-package run: | From 15cddfc361a3e6b170ab7eb8123b134488027430 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Mon, 7 Oct 2024 11:08:18 +0700 Subject: [PATCH 05/12] fix: e2e tests --- engine/e2e-test/test_api_model_start.py | 2 +- engine/e2e-test/test_cli_model_delete.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/engine/e2e-test/test_api_model_start.py b/engine/e2e-test/test_api_model_start.py index fe2a80ceb..906d4b0cf 100644 --- a/engine/e2e-test/test_api_model_start.py +++ b/engine/e2e-test/test_api_model_start.py @@ -15,7 +15,7 @@ def setup_and_teardown(self): # TODO: using pull with branch for easy testing tinyllama:gguf for example run("Delete model", ["models", "delete", "tinyllama:gguf"]) - popen(["pull", "tinyllama"], "1\n") + run("Pull model", ["pull", "tinyllama:gguf"], timeout=None,) yield diff --git a/engine/e2e-test/test_cli_model_delete.py b/engine/e2e-test/test_cli_model_delete.py index 3ff7ef61d..4993bc5f9 100644 --- a/engine/e2e-test/test_cli_model_delete.py +++ b/engine/e2e-test/test_cli_model_delete.py @@ -9,8 +9,7 @@ def setup_and_teardown(self): # Setup # Pull model - # TODO: using pull with branch for easy testing tinyllama:gguf for example - popen(["pull", "tinyllama"], "1\n") + run("Pull model", ["pull", "tinyllama:gguf"], timeout=None,) yield From cb421b67157f486983be4820b69163449b174397 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 16 Oct 2024 12:52:04 +0700 Subject: [PATCH 06/12] fix: more --- engine/services/download_service.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/engine/services/download_service.cc b/engine/services/download_service.cc index 5a367983c..4e8ca502d 100644 --- a/engine/services/download_service.cc +++ b/engine/services/download_service.cc @@ -284,6 +284,9 @@ void DownloadService::ProcessTask(DownloadTask& task) { return; } downloading_data_->item_id = item.id; + if (auto headers = CreateHeaders(item.downloadUrl); headers) { + curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); + } curl_easy_setopt(handle, CURLOPT_URL, item.downloadUrl.c_str()); curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(handle, CURLOPT_WRITEDATA, file); From 99e8bbd686be866b75422255730aa427a937647c Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 16 Oct 2024 13:26:55 +0700 Subject: [PATCH 07/12] f:m --- engine/e2e-test/test_api_model_update.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/e2e-test/test_api_model_update.py b/engine/e2e-test/test_api_model_update.py index 8d28d412a..cf35f44f9 100644 --- a/engine/e2e-test/test_api_model_update.py +++ b/engine/e2e-test/test_api_model_update.py @@ -19,5 +19,5 @@ def setup_and_teardown(self): def test_models_update_should_be_successful(self): body_json = {'model': 'tinyllama:gguf'} - response = requests.post("http://localhost:3928/models/tinyllama:gguf", json = body_json) + response = requests.patch("http://localhost:3928/models/tinyllama:gguf", json = body_json) assert response.status_code == 200 From 542397c746994b8742620d6930c899823bf39996 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Thu, 17 Oct 2024 13:54:14 +0700 Subject: [PATCH 08/12] fix: add hfToken to cortexrc --- engine/utils/config_yaml_utils.h | 6 +++++- engine/utils/huggingface_utils.h | 10 +++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/engine/utils/config_yaml_utils.h b/engine/utils/config_yaml_utils.h index e0e893f42..27e7fa809 100644 --- a/engine/utils/config_yaml_utils.h +++ b/engine/utils/config_yaml_utils.h @@ -18,6 +18,7 @@ struct CortexConfig { std::string apiServerPort; uint64_t checkedForUpdateAt; std::string latestRelease; + std::string hfToken; }; const std::string kCortexFolderName = "cortexcpp"; @@ -47,6 +48,7 @@ inline void DumpYamlConfig(const CortexConfig& config, node["apiServerPort"] = config.apiServerPort; node["checkedForUpdateAt"] = config.checkedForUpdateAt; node["latestRelease"] = config.latestRelease; + node["hfToken"] = config.hfToken; out_file << node; out_file.close(); @@ -70,7 +72,8 @@ inline CortexConfig FromYaml(const std::string& path, !node["maxLogLines"] || !node["apiServerHost"] || !node["apiServerPort"] || !node["checkedForUpdateAt"] || !node["latestRelease"] || !node["logLlamaCppPath"] || - !node["logOnnxPath"] || !node["logTensorrtLLMPath"]); + !node["logOnnxPath"] || !node["logTensorrtLLMPath"] || + !node["hfToken"]); CortexConfig config = { .logFolderPath = node["logFolderPath"] @@ -102,6 +105,7 @@ inline CortexConfig FromYaml(const std::string& path, .latestRelease = node["latestRelease"] ? node["latestRelease"].as() : default_cfg.latestRelease, + .hfToken = node["hfToken"] ? node["hfToken"].as() : "", }; if (should_update_config) { DumpYamlConfig(config, path); diff --git a/engine/utils/huggingface_utils.h b/engine/utils/huggingface_utils.h index b2655f5ba..e57b5256d 100644 --- a/engine/utils/huggingface_utils.h +++ b/engine/utils/huggingface_utils.h @@ -5,6 +5,7 @@ #include #include "httplib.h" #include "utils/curl_utils.h" +#include "utils/file_manager_utils.h" #include "utils/result.hpp" #include "utils/url_parser.h" @@ -48,11 +49,10 @@ struct HuggingFaceModelRepoInfo { }; inline std::optional GetHuggingFaceToken() { - const char* token = std::getenv("HF_TOKEN"); - if (token != nullptr) { - return std::string(token); - } - return std::nullopt; + auto const& token = file_manager_utils::GetCortexConfig().hfToken; + if (token.empty()) + return std::nullopt; + return token; } inline curl_slist* CreateCurlHfHeaders() { From d7c8793c9fcef7592daca29378f944b526f37f75 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Thu, 17 Oct 2024 13:56:45 +0700 Subject: [PATCH 09/12] fix: rename --- engine/utils/config_yaml_utils.h | 8 ++++---- engine/utils/huggingface_utils.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/engine/utils/config_yaml_utils.h b/engine/utils/config_yaml_utils.h index 27e7fa809..f61640db3 100644 --- a/engine/utils/config_yaml_utils.h +++ b/engine/utils/config_yaml_utils.h @@ -18,7 +18,7 @@ struct CortexConfig { std::string apiServerPort; uint64_t checkedForUpdateAt; std::string latestRelease; - std::string hfToken; + std::string huggingFaceToken; }; const std::string kCortexFolderName = "cortexcpp"; @@ -48,7 +48,7 @@ inline void DumpYamlConfig(const CortexConfig& config, node["apiServerPort"] = config.apiServerPort; node["checkedForUpdateAt"] = config.checkedForUpdateAt; node["latestRelease"] = config.latestRelease; - node["hfToken"] = config.hfToken; + node["huggingFaceToken"] = config.huggingFaceToken; out_file << node; out_file.close(); @@ -73,7 +73,7 @@ inline CortexConfig FromYaml(const std::string& path, !node["apiServerPort"] || !node["checkedForUpdateAt"] || !node["latestRelease"] || !node["logLlamaCppPath"] || !node["logOnnxPath"] || !node["logTensorrtLLMPath"] || - !node["hfToken"]); + !node["huggingFaceToken"]); CortexConfig config = { .logFolderPath = node["logFolderPath"] @@ -105,7 +105,7 @@ inline CortexConfig FromYaml(const std::string& path, .latestRelease = node["latestRelease"] ? node["latestRelease"].as() : default_cfg.latestRelease, - .hfToken = node["hfToken"] ? node["hfToken"].as() : "", + .huggingFaceToken = node["huggingFaceToken"] ? node["huggingFaceToken"].as() : "", }; if (should_update_config) { DumpYamlConfig(config, path); diff --git a/engine/utils/huggingface_utils.h b/engine/utils/huggingface_utils.h index e57b5256d..ab85948e7 100644 --- a/engine/utils/huggingface_utils.h +++ b/engine/utils/huggingface_utils.h @@ -49,7 +49,7 @@ struct HuggingFaceModelRepoInfo { }; inline std::optional GetHuggingFaceToken() { - auto const& token = file_manager_utils::GetCortexConfig().hfToken; + auto const& token = file_manager_utils::GetCortexConfig().huggingFaceToken; if (token.empty()) return std::nullopt; return token; From 239f07292fe77d786dcafce0720f82b148f10f33 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Thu, 17 Oct 2024 14:27:49 +0700 Subject: [PATCH 10/12] fix: e2e tests --- engine/commands/engine_uninstall_cmd.cc | 2 +- engine/e2e-test/test_api_model_pull_direct_url.py | 2 +- engine/e2e-test/test_cli_engine_get.py | 14 +++++++++++++- engine/e2e-test/test_cli_engine_list.py | 15 ++++++++++++++- engine/e2e-test/test_cli_engine_uninstall.py | 7 ++++++- engine/e2e-test/test_cli_model_delete.py | 7 ++++++- engine/e2e-test/test_cli_model_import.py | 13 +++++++++++++ 7 files changed, 54 insertions(+), 6 deletions(-) diff --git a/engine/commands/engine_uninstall_cmd.cc b/engine/commands/engine_uninstall_cmd.cc index 6953e2dea..ebd9eb869 100644 --- a/engine/commands/engine_uninstall_cmd.cc +++ b/engine/commands/engine_uninstall_cmd.cc @@ -21,7 +21,7 @@ void EngineUninstallCmd::Exec(const std::string& host, int port, auto res = cli.Delete("/v1/engines/" + engine); if (res) { if (res->status == httplib::StatusCode::OK_200) { - CLI_LOG("Engine " + engine + " uninstalled successfully"); + CLI_LOG("Engine " + engine + " uninstalled successfully!"); } else { CTL_ERR("Engine failed to uninstall with status code: " << res->status); } diff --git a/engine/e2e-test/test_api_model_pull_direct_url.py b/engine/e2e-test/test_api_model_pull_direct_url.py index aa78f4026..7f13f6b18 100644 --- a/engine/e2e-test/test_api_model_pull_direct_url.py +++ b/engine/e2e-test/test_api_model_pull_direct_url.py @@ -22,7 +22,6 @@ def setup_and_teardown(self): yield # Teardown - stop_server() run( "Delete model", [ @@ -31,6 +30,7 @@ def setup_and_teardown(self): "TheBloke:TinyLlama-1.1B-Chat-v0.3-GGUF:tinyllama-1.1b-chat-v0.3.Q2_K.gguf", ], ) + stop_server() def test_model_pull_with_direct_url_should_be_success(self): myobj = { diff --git a/engine/e2e-test/test_cli_engine_get.py b/engine/e2e-test/test_cli_engine_get.py index dd3dffbde..d783c3421 100644 --- a/engine/e2e-test/test_cli_engine_get.py +++ b/engine/e2e-test/test_cli_engine_get.py @@ -2,9 +2,21 @@ import pytest from test_runner import run - +from test_runner import start_server, stop_server class TestCliEngineGet: + + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + + yield + + # Teardown + stop_server() @pytest.mark.skipif(platform.system() != "Windows", reason="Windows-specific test") def test_engines_get_tensorrt_llm_should_not_be_incompatible(self): diff --git a/engine/e2e-test/test_cli_engine_list.py b/engine/e2e-test/test_cli_engine_list.py index 10f7470be..ede2879d9 100644 --- a/engine/e2e-test/test_cli_engine_list.py +++ b/engine/e2e-test/test_cli_engine_list.py @@ -2,9 +2,22 @@ import pytest from test_runner import run - +from test_runner import start_server, stop_server class TestCliEngineList: + + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + + yield + + # Teardown + stop_server() + @pytest.mark.skipif(platform.system() != "Windows", reason="Windows-specific test") def test_engines_list_run_successfully_on_windows(self): exit_code, output, error = run("List engines", ["engines", "list"]) diff --git a/engine/e2e-test/test_cli_engine_uninstall.py b/engine/e2e-test/test_cli_engine_uninstall.py index c53b6f922..5190cee7a 100644 --- a/engine/e2e-test/test_cli_engine_uninstall.py +++ b/engine/e2e-test/test_cli_engine_uninstall.py @@ -1,12 +1,16 @@ import pytest from test_runner import run - +from test_runner import start_server, stop_server class TestCliEngineUninstall: @pytest.fixture(autouse=True) def setup_and_teardown(self): # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + # Preinstall llamacpp engine run("Install Engine", ["engines", "install", "llama-cpp"],timeout = None) @@ -15,6 +19,7 @@ def setup_and_teardown(self): # Teardown # Clean up, removing installed engine run("Uninstall Engine", ["engines", "uninstall", "llama-cpp"]) + stop_server() def test_engines_uninstall_llamacpp_should_be_successfully(self): exit_code, output, error = run( diff --git a/engine/e2e-test/test_cli_model_delete.py b/engine/e2e-test/test_cli_model_delete.py index 4993bc5f9..f7ab53058 100644 --- a/engine/e2e-test/test_cli_model_delete.py +++ b/engine/e2e-test/test_cli_model_delete.py @@ -1,12 +1,16 @@ import pytest from test_runner import popen, run - +from test_runner import start_server, stop_server class TestCliModelDelete: @pytest.fixture(autouse=True) def setup_and_teardown(self): # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + # Pull model run("Pull model", ["pull", "tinyllama:gguf"], timeout=None,) @@ -16,6 +20,7 @@ def setup_and_teardown(self): # Teardown # Clean up run("Delete model", ["models", "delete", "tinyllama:gguf"]) + stop_server() def test_models_delete_should_be_successful(self): exit_code, output, error = run( diff --git a/engine/e2e-test/test_cli_model_import.py b/engine/e2e-test/test_cli_model_import.py index 1f54ae511..cf94d1a2a 100644 --- a/engine/e2e-test/test_cli_model_import.py +++ b/engine/e2e-test/test_cli_model_import.py @@ -1,7 +1,20 @@ import pytest from test_runner import run +from test_runner import start_server, stop_server class TestCliModelImport: + + @pytest.fixture(autouse=True) + def setup_and_teardown(self): + # Setup + success = start_server() + if not success: + raise Exception("Failed to start server") + + yield + + # Teardown + stop_server() @pytest.mark.skipif(True, reason="Expensive test. Only test when you have local gguf file.") def test_model_import_should_be_success(self): From c3cf19a4e6a0ca72b32676b23e13a4a16b0ab3e6 Mon Sep 17 00:00:00 2001 From: Hien To Date: Fri, 18 Oct 2024 11:20:35 +0700 Subject: [PATCH 11/12] ci: add huggingface token to run e2e testing --- .github/workflows/cortex-cpp-quality-gate.yml | 19 +++++++++++++++++-- .../workflows/template-build-linux-x64.yml | 14 -------------- .github/workflows/template-build-macos.yml | 14 -------------- .../workflows/template-build-windows-x64.yml | 14 -------------- 4 files changed, 17 insertions(+), 44 deletions(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 2716ffe7e..52f63a931 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -106,6 +106,21 @@ jobs: cd engine make run-unit-tests + - name: Run setup config for macos + if: runner.os == 'macOS' + run: | + cd engine + ./build/cortex --version + sed -i '' 's/huggingFaceToken: ""/huggingFaceToken: "${{ secrets.HUGGINGFACE_TOKEN_READ }}"/' ~/.cortexrc + + - name: Run setup config for linux + if: runner.os != 'macOS' + shell: bash + run: | + cd engine + ./build/cortex --version + sed -i 's/huggingFaceToken: ""/huggingFaceToken: "${{ secrets.HUGGINGFACE_TOKEN_READ }}"/' ~/.cortexrc + - name: Run e2e tests if: runner.os != 'Windows' && github.event.pull_request.draft == false run: | @@ -114,7 +129,7 @@ jobs: cp build/cortex build/cortex-beta python -m pip install --upgrade pip python -m pip install pytest - python -m pip install requests + python -m pip install requests python e2e-test/main.py rm build/cortex-nightly rm build/cortex-beta @@ -131,7 +146,7 @@ jobs: cp build/cortex.exe build/cortex-beta.exe python -m pip install --upgrade pip python -m pip install pytest - python -m pip install requests + python -m pip install requests python e2e-test/main.py rm build/cortex-nightly.exe rm build/cortex-beta.exe diff --git a/.github/workflows/template-build-linux-x64.yml b/.github/workflows/template-build-linux-x64.yml index 0cbde59af..d1ca73844 100644 --- a/.github/workflows/template-build-linux-x64.yml +++ b/.github/workflows/template-build-linux-x64.yml @@ -135,20 +135,6 @@ jobs: uses: actions/setup-python@v4 with: python-version: '3.10' - - # - name: Run e2e tests - # run: | - # cd engine - # cp build/cortex build/cortex-nightly - # cp build/cortex build/cortex-beta - # python -m pip install --upgrade pip - # python -m pip install pytest - # python -m pip install requests - # python e2e-test/main.py - # rm build/cortex-nightly - # rm build/cortex-beta - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Pre-package run: | diff --git a/.github/workflows/template-build-macos.yml b/.github/workflows/template-build-macos.yml index b8a02aec9..371468dfb 100644 --- a/.github/workflows/template-build-macos.yml +++ b/.github/workflows/template-build-macos.yml @@ -149,20 +149,6 @@ jobs: run: | cd engine make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }} ${{ matrix.extra-cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}" - - # - name: Run e2e tests - # run: | - # cd engine - # cp build/cortex build/cortex-nightly - # cp build/cortex build/cortex-beta - # python -m pip install --upgrade pip - # python -m pip install pytest - # python -m pip install requests - # python e2e-test/main.py - # rm build/cortex-nightly - # rm build/cortex-beta - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Pre-package run: | diff --git a/.github/workflows/template-build-windows-x64.yml b/.github/workflows/template-build-windows-x64.yml index 98576bd0b..d1f6f1333 100644 --- a/.github/workflows/template-build-windows-x64.yml +++ b/.github/workflows/template-build-windows-x64.yml @@ -172,20 +172,6 @@ jobs: with: python-version: '3.10' - # - name: Run e2e tests - # run: | - # cd engine - # cp build/cortex.exe build/cortex-nightly.exe - # cp build/cortex.exe build/cortex-beta.exe - # python -m pip install --upgrade pip - # python -m pip install pytest - # python -m pip install requests - # python e2e-test/main.py - # rm build/cortex-nightly.exe - # rm build/cortex-beta.exe - # env: - # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - name: Pre-package run: | cd engine From 764b59069e919121af48c88000e677554aa7a2f2 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Fri, 18 Oct 2024 13:40:41 +0700 Subject: [PATCH 12/12] chore: remove HUGGINGFACE_TOKEN_READ --- .github/workflows/cortex-cpp-quality-gate.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 2716ffe7e..8659f396e 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -120,8 +120,6 @@ jobs: rm build/cortex-beta env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN_READ }} - - name: Run e2e tests if: runner.os == 'Windows' && github.event.pull_request.draft == false @@ -137,7 +135,6 @@ jobs: rm build/cortex-beta.exe env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - HF_TOKEN: ${{ secrets.HUGGINGFACE_TOKEN_READ }} - name: Pre-package run: |