Skip to content

Build AI methods with your coding agent, then run them anywhere: as an MCP for chatbots, as a webapp for people, or via API for your software.

Fix/vertex ai factory without credentials 2 (#281)

Louis Choquelc87b0778f5cf
diff --git a/pipelex/cogt/model_backends/backend_library.py b/pipelex/cogt/model_backends/backend_library.py
index 33cebeac3..dfdea0c6b 100644
--- a/pipelex/cogt/model_backends/backend_library.py
+++ b/pipelex/cogt/model_backends/backend_library.py
@@ -18,6 +18,7 @@ from pipelex.cogt.model_backends.prompting_target import PromptingTarget
from pipelex.config import get_config
from pipelex.tools.misc.dict_utils import apply_to_strings_recursive
from pipelex.tools.misc.toml_utils import load_toml_from_path
+from pipelex.tools.runtime_manager import runtime_manager
from pipelex.tools.secrets.secrets_utils import UnknownVarPrefixError, VarFallbackPatternError, VarNotFoundError, substitute_vars
InferenceBackendLibraryRoot = Dict[str, InferenceBackend]
@@ -46,6 +47,8 @@ class InferenceBackendLibrary(RootModel[InferenceBackendLibraryRoot]):
inference_backend_blueprint_dict_raw = backend_dict.copy()
if not inference_backend_blueprint_dict_raw.get("enabled", True):
continue
+ if runtime_manager.is_gha_testing and backend_name == "vertexai":
+ continue
try:
inference_backend_blueprint_dict = apply_to_strings_recursive(inference_backend_blueprint_dict_raw, substitute_vars)
except VarFallbackPatternError as var_fallback_pattern_exc:
diff --git a/pipelex/plugins/openai/vertexai_factory.py b/pipelex/plugins/openai/vertexai_factory.py
index d721ffc08..083951f85 100644
--- a/pipelex/plugins/openai/vertexai_factory.py
+++ b/pipelex/plugins/openai/vertexai_factory.py
@@ -2,6 +2,7 @@ from typing import Any, Dict, Tuple
from pipelex.cogt.exceptions import CogtError, MissingDependencyError
from pipelex.tools.config.config_model import ConfigModel
+from pipelex.tools.environment import ENV_DUMMY_PLACEHOLDER_VALUE
from pipelex.tools.exceptions import CredentialsError
from pipelex.tools.misc.json_utils import load_json_dict_from_path
from pipelex.types import StrEnum
@@ -39,8 +40,8 @@ class VertexAIFactory(ConfigModel):
endpoint = cls._make_endpoint(gcp_project_id=gcp_project_id, gcp_location=gcp_location)
gcp_credentials_file_path = extra_config.get(VertexAIExtraField.GCP_CREDENTIALS_FILE_PATH)
- if not gcp_credentials_file_path:
- raise VertexAIConfigError("GCP credentials file path is not set in VertexAI config")
+ if not gcp_credentials_file_path or gcp_credentials_file_path == ENV_DUMMY_PLACEHOLDER_VALUE:
+ raise VertexAIConfigError("GCP credentials file path is not properly set for VertexAI.")
api_key = cls._make_api_key(gcp_credentials_file_path=gcp_credentials_file_path)
@@ -70,7 +71,9 @@ class VertexAIFactory(ConfigModel):
try:
credentials_dict: Dict[str, Any] = load_json_dict_from_path(path=gcp_credentials_file_path)
except FileNotFoundError as exc:
- raise VertexAICredentialsError(f"File not found: {gcp_credentials_file_path}") from exc
+ raise VertexAICredentialsError(
+ f"Could not get VertexAI credentials from GCP credentials file: File not found: {gcp_credentials_file_path}"
+ ) from exc
credentials = Credentials.from_service_account_info( # pyright: ignore[reportUnknownMemberType]
credentials_dict, scopes=["https://www.googleapis.com/auth/cloud-platform"]
diff --git a/pipelex/test_extras/shared_pytest_plugins.py b/pipelex/test_extras/shared_pytest_plugins.py
index 84cc0af95..7ff461bbf 100644
--- a/pipelex/test_extras/shared_pytest_plugins.py
+++ b/pipelex/test_extras/shared_pytest_plugins.py
@@ -9,7 +9,10 @@ from pipelex.tools.runtime_manager import RunMode, runtime_manager
@pytest.fixture(scope="session", autouse=True)
def set_run_mode():
- runtime_manager.set_run_mode(run_mode=RunMode.UNIT_TEST)
+ if is_env_set("GITHUB_ACTIONS") or is_env_set("CI"):
+ runtime_manager.set_run_mode(run_mode=RunMode.CI_TEST)
+ else:
+ runtime_manager.set_run_mode(run_mode=RunMode.UNIT_TEST)
def pytest_addoption(parser: Parser):
diff --git a/pipelex/tools/runtime_manager.py b/pipelex/tools/runtime_manager.py
index 4a151d6c9..8faf4e727 100644
--- a/pipelex/tools/runtime_manager.py
+++ b/pipelex/tools/runtime_manager.py
@@ -11,6 +11,7 @@ RUN_MODE_ENV_VAR_KEY = "RUN_MODE"
class RunMode(StrEnum):
NORMAL = "normal"
UNIT_TEST = "unit_test"
+ CI_TEST = "ci_test"
@classmethod
def get_from_env_var(cls) -> "RunMode":
@@ -83,7 +84,23 @@ class RuntimeManager(BaseModel):
@property
def is_unit_testing(self) -> bool:
- return self.run_mode == RunMode.UNIT_TEST
+ match self.run_mode:
+ case RunMode.NORMAL:
+ return False
+ case RunMode.UNIT_TEST:
+ return True
+ case RunMode.CI_TEST:
+ return True
+
+ @property
+ def is_gha_testing(self) -> bool:
+ match self.run_mode:
+ case RunMode.NORMAL:
+ return False
+ case RunMode.UNIT_TEST:
+ return False
+ case RunMode.CI_TEST:
+ return True
@property
def should_check_intermediate_configs(self) -> bool:
diff --git a/tests/unit/pipelex/tools/test_testing.py b/tests/unit/pipelex/tools/test_testing.py
index 71de983f1..e69d5331b 100644
--- a/tests/unit/pipelex/tools/test_testing.py
+++ b/tests/unit/pipelex/tools/test_testing.py
@@ -1,5 +1,12 @@
-from pipelex.tools.runtime_manager import runtime_manager
+from pipelex.tools.environment import is_env_set
+from pipelex.tools.runtime_manager import RunMode, runtime_manager
def test_testing():
- assert runtime_manager.run_mode == "unit_test"
+ match runtime_manager.run_mode:
+ case RunMode.CI_TEST:
+ assert is_env_set("GITHUB_ACTIONS") or is_env_set("CI")
+ case RunMode.UNIT_TEST:
+ assert not is_env_set("GITHUB_ACTIONS") and not is_env_set("CI")
+ case _:
+ raise RuntimeError(f"Invalid run mode: {runtime_manager.run_mode}")