-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathconfig.py
More file actions
66 lines (53 loc) · 2.84 KB
/
config.py
File metadata and controls
66 lines (53 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""Configuration class for the application.
This class loads configuration values from environment variables and provides
methods to access them. It also initializes an Azure AI client using the
provided credentials.
It uses the `azure.identity` library to handle authentication and
authorization with Azure services.
Access to .env variables requires adding the `python-dotenv` package to, or
configuration of the env python path through the IDE. For example, in VSCode, the
settings.json file in the .vscode folder should include the following:
{
"python.envFile": "${workspaceFolder}/.env"
}
"""
import os
from azure.identity.aio import ClientSecretCredential, DefaultAzureCredential
class Config:
"""Configuration class for the application."""
def __init__(self):
self.azure_tenant_id = os.getenv("AZURE_TENANT_ID", "")
self.azure_client_id = os.getenv("AZURE_CLIENT_ID", "")
self.azure_client_secret = os.getenv("AZURE_CLIENT_SECRET", "")
self.cosmosdb_endpoint = os.getenv("COSMOSDB_ENDPOINT")
self.cosmosdb_database = os.getenv("COSMOSDB_DATABASE")
self.cosmosdb_batch_container = os.getenv("COSMOSDB_BATCH_CONTAINER")
self.cosmosdb_file_container = os.getenv("COSMOSDB_FILE_CONTAINER")
self.cosmosdb_log_container = os.getenv("COSMOSDB_LOG_CONTAINER")
self.azure_blob_container_name = os.getenv("AZURE_BLOB_CONTAINER_NAME")
self.azure_blob_account_name = os.getenv("AZURE_BLOB_ACCOUNT_NAME")
self.azure_service_bus_namespace = os.getenv("AZURE_SERVICE_BUS_NAMESPACE")
self.azure_queue_name = os.getenv("AZURE_QUEUE_NAME")
self.azure_openai_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")
self.ai_project_endpoint = os.getenv("AI_PROJECT_ENDPOINT")
self.migrator_agent_model_deploy = os.getenv("MIGRATOR_AGENT_MODEL_DEPLOY")
self.picker_agent_model_deploy = os.getenv("PICKER_AGENT_MODEL_DEPLOY")
self.fixer_agent_model_deploy = os.getenv("FIXER_AGENT_MODEL_DEPLOY")
self.semantic_verifier_agent_model_deploy = os.getenv(
"SEMANTIC_VERIFIER_AGENT_MODEL_DEPLOY"
)
self.syntax_checker_agent_model_deploy = os.getenv(
"SYNTAX_CHECKER_AGENT_MODEL_DEPLOY"
)
self.__azure_credentials = DefaultAzureCredential()
def get_azure_credentials(self):
"""Retrieve Azure credentials, either from environment variables or managed identity."""
if all([self.azure_tenant_id, self.azure_client_id, self.azure_client_secret]):
return ClientSecretCredential(
tenant_id=self.azure_tenant_id,
client_id=self.azure_client_id,
client_secret=self.azure_client_secret,
)
return self.__azure_credentials
app_config = Config()
print(f"[DEBUG] AI_PROJECT_ENDPOINT: '{os.getenv('AI_PROJECT_ENDPOINT')}'")