Skip to content

Commit 457224d

Browse files
committed
Make mypy happy
1 parent a508bae commit 457224d

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

app/backend/prepdocs.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ async def main(strategy: Strategy, setup_index: bool = True):
313313
)
314314
blob_manager = setup_blob_manager(
315315
azure_credential=azd_credential,
316-
storage_account=os.getenv("AZURE_STORAGE_ACCOUNT"),
317-
storage_container=os.getenv("AZURE_STORAGE_CONTAINER"),
318-
storage_resource_group=os.getenv("AZURE_STORAGE_RESOURCE_GROUP"),
319-
subscription_id=os.getenv("AZURE_SUBSCRIPTION_ID"),
316+
storage_account=os.environ["AZURE_STORAGE_ACCOUNT"],
317+
storage_container=os.environ["AZURE_STORAGE_CONTAINER"],
318+
storage_resource_group=os.environ["AZURE_STORAGE_RESOURCE_GROUP"],
319+
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"],
320320
search_images=use_gptvision,
321321
storage_key=clean_key_if_exists(args.storagekey),
322322
)
@@ -336,14 +336,17 @@ async def main(strategy: Strategy, setup_index: bool = True):
336336
elif not openai_host.startswith("azure") and os.getenv("OPENAI_API_KEY"):
337337
openai_key = os.getenv("OPENAI_API_KEY")
338338

339+
openai_dimensions = 1536
340+
if os.getenv("AZURE_OPENAI_EMB_DIMENSIONS"):
341+
openai_dimensions = int(os.environ["AZURE_OPENAI_EMB_DIMENSIONS"])
339342
openai_embeddings_service = setup_embeddings_service(
340343
azure_credential=azd_credential,
341344
openai_host=openai_host,
342-
openai_model_name=os.getenv("AZURE_OPENAI_EMB_MODEL_NAME"),
345+
openai_model_name=os.environ["AZURE_OPENAI_EMB_MODEL_NAME"],
343346
openai_service=os.getenv("AZURE_OPENAI_SERVICE"),
344347
openai_custom_url=os.getenv("AZURE_OPENAI_CUSTOM_URL"),
345348
openai_deployment=os.getenv("AZURE_OPENAI_EMB_DEPLOYMENT"),
346-
openai_dimensions=os.getenv("AZURE_OPENAI_EMB_DIMENSIONS"),
349+
openai_dimensions=openai_dimensions,
347350
openai_key=clean_key_if_exists(openai_key),
348351
openai_org=os.getenv("OPENAI_ORGANIZATION"),
349352
disable_vectors=dont_use_vectors,
@@ -358,7 +361,7 @@ async def main(strategy: Strategy, setup_index: bool = True):
358361
blob_manager=blob_manager,
359362
document_action=document_action,
360363
embeddings=openai_embeddings_service,
361-
subscription_id=os.getenv("AZURE_SUBSCRIPTION_ID"),
364+
subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"],
362365
search_service_user_assigned_id=args.searchserviceassignedid,
363366
search_analyzer_name=os.getenv("AZURE_SEARCH_ANALYZER_NAME"),
364367
use_acls=use_acls,

scripts/adlsgen2setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ async def main(args: Any):
165165
data_access_control_format = json.load(f)
166166
command = AdlsGen2Setup(
167167
data_directory=args.data_directory,
168-
storage_account_name=os.getenv("AZURE_ADLS_GEN2_STORAGE_ACCOUNT"),
168+
storage_account_name=os.environ["AZURE_ADLS_GEN2_STORAGE_ACCOUNT"],
169169
filesystem_name="gptkbcontainer",
170170
security_enabled_groups=args.create_security_enabled_groups,
171171
credentials=credentials,

scripts/auth_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,12 @@ async def main():
172172
print("Not setting up authentication.")
173173
exit(0)
174174

175-
if not os.getenv("AZURE_AUTH_TENANT_ID") and not os.getenv("AZURE_TENANT_ID"):
175+
auth_tenant = os.getenv("AZURE_AUTH_TENANT_ID", os.getenv("AZURE_TENANT_ID"))
176+
if not auth_tenant:
176177
print(
177178
"Error: No tenant ID set for authentication. Run `azd env set AZURE_AUTH_TENANT_ID tenant-id` to set the tenant ID."
178179
)
179180
exit(1)
180-
auth_tenant = os.getenv("AZURE_AUTH_TENANT_ID", os.getenv("AZURE_TENANT_ID"))
181181
print("Setting up authentication for tenant", auth_tenant)
182182
credential = AzureDeveloperCliCredential(tenant_id=auth_tenant)
183183

scripts/load_azd_env.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import logging
3+
import subprocess
4+
5+
from dotenv import load_dotenv
6+
7+
logger = logging.getLogger("scripts")
8+
9+
10+
def load_azd_env():
11+
"""Get path to current azd env file and load file using python-dotenv"""
12+
result = subprocess.run("azd env list -o json", shell=True, capture_output=True, text=True)
13+
if result.returncode != 0:
14+
raise Exception("Error loading azd env")
15+
env_json = json.loads(result.stdout)
16+
env_file_path = None
17+
for entry in env_json:
18+
if entry["IsDefault"]:
19+
env_file_path = entry["DotEnvPath"]
20+
if not env_file_path:
21+
raise Exception("No default azd env file found")
22+
logger.info(f"Loading azd env from {env_file_path}")
23+
load_dotenv(env_file_path, override=True)

0 commit comments

Comments
 (0)