Skip to content

Commit b8f0a74

Browse files
Refactor scripts to avoid anti-patterns, redundancy (#1986)
* Update bicep for ACA * First working version * Support workload profile * Add support for CORS and fix identity for openai * Add aca-host * Make acr unique * Add doc for aca host * Update ACA docs * Remove unneeded bicep files * Revert chanes to infra/main.parameters.json * Fix markdown lint issues * Run frontend build before building docker image * remove symlinks and update scripts with paths relative to its own folder instead of cwd * Merge with main.bicep * output AZURE_CONTAINER_REGISTRY_ENDPOINT * Fix deployment with app service * Improve naming and README * Fix identity name and cost esitmation for aca * Share env vars in bicep and update docs * Revert "remove symlinks and update scripts with paths relative to its own folder instead of cwd" This reverts commit 40287f2. * Add containerapps as a commented out host option * Update app/backend/.dockerignore * Apply suggestions from code review * More steps for deployment guide * Update azure.yaml * Update comment * cleanup bicep files and improve docs * Update condition for running in production for credential * Refactors to scripts * Remove phi changes * Make mypy happy * Add dotenv requirement * Env var tweaks * Fix error handling * Update manageacl.py commands * Doc update * Adding more tests for prepdocs * Fix markdown copy * Fix relative links * Make prepdocs mypy happy * Fix auth_update if check --------- Co-authored-by: yefuwang <[email protected]> Co-authored-by: Yefu Wang <[email protected]>
1 parent 106b52b commit b8f0a74

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+502
-580
lines changed

app/backend/app.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,10 @@ def create_app():
714714
# Log levels should be one of https://docs.python.org/3/library/logging.html#logging-levels
715715
# Set root level to WARNING to avoid seeing overly verbose logs from SDKS
716716
logging.basicConfig(level=logging.WARNING)
717-
# Set the app logger level to INFO by default
718-
default_level = "INFO"
719-
app.logger.setLevel(os.getenv("APP_LOG_LEVEL", default_level))
717+
# Set our own logger levels to INFO by default
718+
app_level = os.getenv("APP_LOG_LEVEL", "INFO")
719+
app.logger.setLevel(os.getenv("APP_LOG_LEVEL", app_level))
720+
logging.getLogger("scripts").setLevel(app_level)
720721

721722
if allowed_origin := os.getenv("ALLOWED_ORIGIN"):
722723
app.logger.info("ALLOWED_ORIGIN is set, enabling CORS for %s", allowed_origin)

app/backend/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)

app/backend/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
import os
2+
13
from app import create_app
4+
from load_azd_env import load_azd_env
5+
6+
# WEBSITE_HOSTNAME is always set by App Service, RUNNING_IN_PRODUCTION is set in main.bicep
7+
RUNNING_ON_AZURE = os.getenv("WEBSITE_HOSTNAME") is not None or os.getenv("RUNNING_IN_PRODUCTION") is not None
8+
9+
if not RUNNING_ON_AZURE:
10+
load_azd_env()
211

312
app = create_app()

app/backend/prepdocs.py

Lines changed: 105 additions & 169 deletions
Large diffs are not rendered by default.

app/backend/prepdocslib/blobmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from .listfilestrategy import File
2020

21-
logger = logging.getLogger("ingester")
21+
logger = logging.getLogger("scripts")
2222

2323

2424
class BlobManager:

app/backend/prepdocslib/embeddings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from typing_extensions import TypedDict
1919

20-
logger = logging.getLogger("ingester")
20+
logger = logging.getLogger("scripts")
2121

2222

2323
class EmbeddingBatch:

app/backend/prepdocslib/filestrategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from .searchmanager import SearchManager, Section
99
from .strategy import DocumentAction, SearchInfo, Strategy
1010

11-
logger = logging.getLogger("ingester")
11+
logger = logging.getLogger("scripts")
1212

1313

1414
async def parse_file(

app/backend/prepdocslib/htmlparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from .page import Page
88
from .parser import Parser
99

10-
logger = logging.getLogger("ingester")
10+
logger = logging.getLogger("scripts")
1111

1212

1313
def cleanup_data(data: str) -> str:

app/backend/prepdocslib/integratedvectorizerstrategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from .searchmanager import SearchManager
2929
from .strategy import DocumentAction, SearchInfo, Strategy
3030

31-
logger = logging.getLogger("ingester")
31+
logger = logging.getLogger("scripts")
3232

3333

3434
class IntegratedVectorizerStrategy(Strategy):

app/backend/prepdocslib/listfilestrategy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
DataLakeServiceClient,
1414
)
1515

16-
logger = logging.getLogger("ingester")
16+
logger = logging.getLogger("scripts")
1717

1818

1919
class File:

0 commit comments

Comments
 (0)