Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ def __init__(
if not client:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
if not google_ai_settings.api_key:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:
raise ServiceInitializationError("Region must be provided when use_vertexai is True.")
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
raise ServiceInitializationError("The API key is required when use_vertexai is False.")

super().__init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ def __init__(
if not client:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
if not google_ai_settings.api_key:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:
raise ServiceInitializationError("Region must be provided when use_vertexai is True.")
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
raise ServiceInitializationError("The API key is required when use_vertexai is False.")

super().__init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ def __init__(
if not client:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_project_id:
raise ServiceInitializationError("Project ID must be provided when use_vertexai is True.")
if not google_ai_settings.api_key:
if google_ai_settings.use_vertexai and not google_ai_settings.cloud_region:
raise ServiceInitializationError("Region must be provided when use_vertexai is True.")
if not google_ai_settings.use_vertexai and not google_ai_settings.api_key:
raise ServiceInitializationError("The API key is required when use_vertexai is False.")

super().__init__(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ def test_google_ai_chat_completion_init_with_use_vertexai_missing_project_id(goo
GoogleAIChatCompletion(use_vertexai=True, env_file_path="fake_env_file_path.env")


@pytest.mark.parametrize("exclude_list", [["GOOGLE_AI_CLOUD_REGION"]], indirect=True)
def test_google_ai_chat_completion_init_with_use_vertexai_missing_region(google_ai_unit_test_env) -> None:
"""Test initialization of GoogleAIChatCompletion with use_vertexai true but missing region"""
with pytest.raises(ServiceInitializationError, match="Region must be provided when use_vertexai is True."):
GoogleAIChatCompletion(use_vertexai=True, env_file_path="fake_env_file_path.env")


@pytest.mark.parametrize("exclude_list", [["GOOGLE_AI_API_KEY"]], indirect=True)
def test_google_ai_chat_completion_init_with_use_vertexai_no_api_key(google_ai_unit_test_env) -> None:
"""Test initialization of GoogleAIChatCompletion succeeds with use_vertexai=True and no api_key"""
chat_completion = GoogleAIChatCompletion(use_vertexai=True)
assert chat_completion.service_settings.use_vertexai is True


def test_prompt_execution_settings_class(google_ai_unit_test_env) -> None:
google_ai_chat_completion = GoogleAIChatCompletion()
assert google_ai_chat_completion.get_prompt_execution_settings_class() == GoogleAIChatPromptExecutionSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ def test_google_ai_text_completion_init_with_use_vertexai_missing_project_id(goo
GoogleAITextCompletion(use_vertexai=True, env_file_path="fake_env_file_path.env")


@pytest.mark.parametrize("exclude_list", [["GOOGLE_AI_CLOUD_REGION"]], indirect=True)
def test_google_ai_text_completion_init_with_use_vertexai_missing_region(google_ai_unit_test_env) -> None:
"""Test initialization of GoogleAITextCompletion with use_vertexai true but missing region"""
with pytest.raises(ServiceInitializationError, match="Region must be provided when use_vertexai is True."):
GoogleAITextCompletion(use_vertexai=True, env_file_path="fake_env_file_path.env")


@pytest.mark.parametrize("exclude_list", [["GOOGLE_AI_API_KEY"]], indirect=True)
def test_google_ai_text_completion_init_with_use_vertexai_no_api_key(google_ai_unit_test_env) -> None:
"""Test initialization of GoogleAITextCompletion succeeds with use_vertexai=True and no api_key"""
text_completion = GoogleAITextCompletion(use_vertexai=True)
assert text_completion.service_settings.use_vertexai is True


def test_prompt_execution_settings_class(google_ai_unit_test_env) -> None:
google_ai_text_completion = GoogleAITextCompletion()
assert google_ai_text_completion.get_prompt_execution_settings_class() == GoogleAITextPromptExecutionSettings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ def test_google_ai_text_embedding_init_with_empty_model_id(google_ai_unit_test_e
def test_google_ai_text_embedding_init_with_empty_api_key(google_ai_unit_test_env) -> None:
"""Test initialization of GoogleAITextEmbedding with an empty api_key"""
with pytest.raises(ServiceInitializationError, match="The API key is required when use_vertexai is False."):
GoogleAITextEmbedding(use_vertexai=True, env_file_path="fake_env_file_path.env")
GoogleAITextEmbedding(env_file_path="fake_env_file_path.env")


@pytest.mark.parametrize("exclude_list", [["GOOGLE_AI_API_KEY"]], indirect=True)
def test_google_ai_text_embedding_init_with_use_vertexai_no_api_key(google_ai_unit_test_env) -> None:
"""Test initialization of GoogleAITextEmbedding succeeds with use_vertexai=True and no api_key"""
embedding = GoogleAITextEmbedding(use_vertexai=True)
assert embedding.service_settings.use_vertexai is True


@pytest.mark.parametrize("exclude_list", [["GOOGLE_AI_CLOUD_PROJECT_ID"]], indirect=True)
Expand All @@ -67,6 +74,13 @@ def test_google_ai_text_embedding_init_with_use_vertexai_missing_project_id(goog
GoogleAITextEmbedding(use_vertexai=True, env_file_path="fake_env_file_path.env")


@pytest.mark.parametrize("exclude_list", [["GOOGLE_AI_CLOUD_REGION"]], indirect=True)
def test_google_ai_text_embedding_init_with_use_vertexai_missing_region(google_ai_unit_test_env) -> None:
"""Test initialization of GoogleAITextEmbedding with use_vertexai true but missing region"""
with pytest.raises(ServiceInitializationError, match="Region must be provided when use_vertexai is True."):
GoogleAITextEmbedding(use_vertexai=True, env_file_path="fake_env_file_path.env")


def test_prompt_execution_settings_class(google_ai_unit_test_env) -> None:
google_ai_text_embedding = GoogleAITextEmbedding()
assert google_ai_text_embedding.get_prompt_execution_settings_class() == GoogleAIEmbeddingPromptExecutionSettings
Expand Down
Loading