Skip to content
Closed
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
22 changes: 22 additions & 0 deletions deepeval/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ def login(
help="Use the existing API key stored in the key file if present.",
),
):
def extract_region_from_api_key(key: str) -> Optional[str]:
"""Extract the region from the API key, if it's present (e.g. starts with 'confident_ai_{region}_')."""
if not key:
return None

# Look for pattern: confident_ai_{region}_
parts = key.split('_')
if len(parts) >= 3 and parts[0] == 'confident' and parts[1] == 'ai':
region = parts[2].upper()
# Check if region is supported
try:
Regions(region)
return region
except ValueError:
return None

return None
with capture_login_event() as span:
# Use the confident_api_key if it is provided, otherwise proceed with existing logic
try:
Expand Down Expand Up @@ -114,6 +131,11 @@ def login(
print(
"API Key cannot be empty. Please try again.\n"
)
# Extract region from API key
region = extract_region_from_api_key(api_key)
if region:
# Store region if needed
KEY_FILE_HANDLER.write_key(KeyValues.CONFIDENT_REGION, region.upper())

KEY_FILE_HANDLER.write_key(KeyValues.API_KEY, api_key)
span.set_attribute("completed", False)
Expand Down
Loading