Closed bowenliang123 closed 3 months ago
Hello, Bowen! We need to know which packages need to read our configurations from the system environment variables. Could you give us a more specific example?
Hi, @laipz8200 thanks for your attention to this PR, which is raised for :
config.py
in #5507, there's one line to populate all the configs from the .env file to system env vars. see https://github.com/langgenius/dify/pull/5507/files#diff-0e3026d2737181f937735ba5e2023ce7f39a7762c8c2594670f4a944a7e48eafL33
dotenv.load_dotenv()
(method comment: "Parse a .env file and then load all the variables found as environment variables...." )
This PR helps to leverage the same efforts to the original behaviours.
.env
file to set some env vars for the package. eg. setting CO_API_URL
as the base URL for cohere
package, which is not directly used in Dify.@bowenliang123 Since DifyConfig
is read from the .env
file, I think we can just use dotenv.load_dotenv()
here like we did before.
I would prefer not to reverse couple with the raw dotenv again. For the following reasons,
dotenv.load_dotenv
method has a implicit file path for .env
, if we want to change it in future, it's better to make sure it's aligned with pydantic-settings
.pydantic-settings
provides various features for arranging the proper order and choices for config sources, like pyproject.toml
, JSON files, env files and etc.dotenv.load_dotenv
, it does replicate the configs into system env vars in set_as_environment_variables
method by using os.environ[k] = v
Thanks.
Description
.env
to system env variables, for the packages relies on env variables rather than reading configs from flask app's config.Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Suggested Checklist:
dev/reformat
(backend) andcd web && npx lint-staged
(frontend) to appease the lint godsoptional
I have made corresponding changes to the documentationoptional
I have added tests that prove my fix is effective or that my feature worksoptional
New and existing unit tests pass locally with my changes