Skip to content

Commit

Permalink
updated config module and .env.example notes (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkrabach authored Aug 24, 2024
1 parent 4f32472 commit 2017bcf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
4 changes: 4 additions & 0 deletions examples/python-example01/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Description: Example of .env file
# Usage: Copy this file to .env and set the values

# NOTE: Changes to this file will not take effect until the project service is 'stopped' and 'started'
# It is not enough to just use the VS Code 'restart' button

# Assistant Service
# The ASSISTANT__ prefix is used to group all the environment variables related to the assistant service.
ASSISTANT__ENABLE_DEBUG_OUTPUT=True
16 changes: 8 additions & 8 deletions semantic-workbench/v1/service/.env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Workflow Service
WORKFLOW__AZURE_OPENAI_ENDPOINT=https://<YOUR-RESOURCE-NAME>.openai.azure.com/
WORKFLOW__AZURE_OPENAI_API_KEY=...
# This file contains the environment variables for the project

# NOTE: Changes to this file will not take effect until the project service is 'stopped' and 'started'
# It is not enough to just use the VS Code 'restart' button

# Assistant Service
ASSISTANT__AZURE_OPENAI_EMBEDDINGS_ENDPOINT=https://<YOUR-RESOURCE-NAME>.openai.azure.com/
ASSISTANT__AZURE_OPENAI_EMBEDDINGS_KEY=...
ASSISTANT__AZURE_OPENAI_ENDPOINT=https://<YOUR-RESOURCE-NAME>.openai.azure.com/
ASSISTANT__AZURE_OPENAI_API_KEY=...
# Workflow Service
# NOTE: This feature is currently disabled, so no environment variables are needed
# WORKFLOW__AZURE_OPENAI_ENDPOINT=https://<YOUR-RESOURCE-NAME>.openai.azure.com/
# WORKFLOW__AZURE_OPENAI_API_KEY=...
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,39 @@ def callback_url(self) -> str:

ModelT = TypeVar("ModelT", bound=BaseModel)

_dotenv_values = dotenv.dotenv_values()


def first_env_var(*env_vars: str, include_dotenv: bool = True, include_upper_and_lower: bool = True) -> str | None:
def first_not_none(*vals: str | None) -> str | None:
for val in vals:
if val is not None:
return val
return None

"""
Get the first environment variable that is set. If include_dotenv is True, then
the dotenv values will be checked as well. If include_upper_and_lower is True,
then the upper and lower case versions of the env vars will also be checked.
.. warning::
The dotenv values may be cached in the environment, so if you have loaded
a .env file into the environment, you may need to 'stop' and then 'start' the
service to get the new values from the .env file. Using the 'restart' command
does not seem to work.
"""
if include_upper_and_lower:
env_vars = (*env_vars, *[env_var.upper() for env_var in env_vars], *[env_var.lower() for env_var in env_vars])

env_values = [os.environ.get(env_var) for env_var in env_vars]
dotenv_values = {}
# load dotenv values if requested
if include_dotenv:
env_values = [*[_dotenv_values.get(env_var) for env_var in env_vars], *env_values]
dotenv_values = dotenv.dotenv_values()

# check for the first env var that is set
# prioritize the environment over dotenv values
for env_var in env_vars:
# check for the env var in the environment
if env_var in os.environ:
return os.environ[env_var]

# check for the env var in the dotenv values
if env_var in dotenv_values:
return dotenv_values[env_var]

return first_not_none(*env_values)
return None


def overwrite_defaults_from_env(model: ModelT, prefix="", separator="__") -> ModelT:
Expand Down

0 comments on commit 2017bcf

Please sign in to comment.