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,7 @@ 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 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
@@ -0,0 +1,22 @@
import pytest

from semantic_kernel.connectors.ai.google.google_ai.google_ai_settings import GoogleAISettings
from semantic_kernel.connectors.ai.google.google_ai.services.google_ai_chat_completion import (
GoogleAIChatCompletion,
)
from semantic_kernel.exceptions.service_exceptions import ServiceInitializationError


def test_vertexai_does_not_require_api_key_when_adc_is_used():
"""
When use_vertexai=True, GoogleAIChatCompletion should NOT require an API key,
because authentication is handled via Application Default Credentials (ADC).
"""

GoogleAIChatCompletion(
gemini_model_id="models/gemini-1.5-pro",
api_key=None,
use_vertexai=True,
project_id="test-project",
region="us-central1",
)