-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor scripts to avoid anti-patterns, redundancy #1986
Changes from all commits
d721099
30f00e5
72e34d2
55a97fd
7edd2db
8fc2d5a
9cadd14
0623e9b
73b2bb3
e362545
24d668a
fbb4b05
4ced7ce
625866f
40287f2
a99a6c5
9dc65ca
7f523a0
9e6e145
4ec32f7
4174fd3
7e49c99
259e7a5
920e979
eb09e46
56025eb
13021cb
8b19702
6550960
d49f60c
11837ba
560076b
5682b67
59e01c8
436ea35
a508bae
457224d
7c385c8
02c280c
a4a4f11
e4a7abf
0ab84da
4fef884
7d57de8
1980845
b378727
697fa01
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import json | ||
import logging | ||
import subprocess | ||
|
||
from dotenv import load_dotenv | ||
|
||
logger = logging.getLogger("scripts") | ||
|
||
|
||
def load_azd_env(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This file actually shows up in two places, both here and in scripts folder, for convenience. |
||
"""Get path to current azd env file and load file using python-dotenv""" | ||
result = subprocess.run("azd env list -o json", shell=True, capture_output=True, text=True) | ||
if result.returncode != 0: | ||
raise Exception("Error loading azd env") | ||
env_json = json.loads(result.stdout) | ||
env_file_path = None | ||
for entry in env_json: | ||
if entry["IsDefault"]: | ||
env_file_path = entry["DotEnvPath"] | ||
if not env_file_path: | ||
raise Exception("No default azd env file found") | ||
logger.info(f"Loading azd env from {env_file_path}") | ||
load_dotenv(env_file_path, override=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
import os | ||
|
||
from app import create_app | ||
from load_azd_env import load_azd_env | ||
|
||
# WEBSITE_HOSTNAME is always set by App Service, RUNNING_IN_PRODUCTION is set in main.bicep | ||
RUNNING_ON_AZURE = os.getenv("WEBSITE_HOSTNAME") is not None or os.getenv("RUNNING_IN_PRODUCTION") is not None | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code also exists in two places-
|
||
|
||
if not RUNNING_ON_AZURE: | ||
load_azd_env() | ||
|
||
app = create_app() |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,4 @@ beautifulsoup4 | |
types-beautifulsoup4 | ||
msgraph-sdk==1.1.0 | ||
openai-messages-token-helper | ||
python-dotenv |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ const Chat = () => { | |
if (event["context"] && event["context"]["data_points"]) { | ||
event["message"] = event["delta"]; | ||
askResponse = event as ChatAppResponse; | ||
} else if (event["delta"]["content"]) { | ||
} else if (event["delta"] && event["delta"]["content"]) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unrelated error that I found while presenting. This error meant we arent currently rendering errors correctly, as {error: } responses dont contain a delta key. |
||
setIsLoading(false); | ||
await updateState(event["delta"]["content"]); | ||
} else if (event["context"]) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since prepdocs uses the "scripts" logger, I wanted to make sure we also see its logs when using user upload feature.
Though I wonder if I should give it a different name, like "ragapp".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think scripts is an acceptable name for now - we can change it later if it's not working