Skip to content

Add settings retrieval through properties file and env vars - #1176

Closed
Milder Hernandez (milderhc) wants to merge 7 commits into
microsoft:experimental-javafrom
milderhc:settings
Closed

Milder Hernandez (milderhc) wants to merge 7 commits into
microsoft:experimental-javafrom
milderhc:settings

Conversation

@milderhc

@milderhc Milder Hernandez (milderhc) commented May 23, 2023 •

Copy link
Copy Markdown
Contributor

Motivation and Context

Add settings retrieval through properties file and env vars

Description

Adds util.Settings to load settings values from a properties file or from the environment.

Also, the ability to have different client settings in the properties file and load them by their specific schema Id:

client.azureopenai.key: "AZURE_OPEN_AI_KEY"
client.azureopenai.endpoint: "AZURE_OPEN_AI_ENDPOINT"
client.azureopenai.deploymentname: "AZURE_OPEN_AI_DEPLOYMENT_NAME"

client.myazureopenai.key: "AZURE_OPEN_AI_KEY"
client.myazureopenai.endpoint: "AZURE_OPEN_AI_ENDPOINT"
client.myazureopenai.deploymentname: "AZURE_OPEN_AI_DEPLOYMENT_NAME"

By calling Settings.getAzureOpenAISettingsFromFile(CONF_PROPERTIES) the user would be able to load the Azure settings using the default schema id, as shown in the block at the top.

By calling Settings.getAzureOpenAISettingsFromFile(CONF_PROPERTIES, "myazureopenai") the user would be able to load a different Azure configuration by just adding the second block to the properties file.

Contribution Checklist

@lemillermicrosoft Lee Miller (lemillermicrosoft) added feature branch PR targeting a feature branch java Issue or PR regarding Java code labels May 23, 2023
@milderhc
Milder Hernandez (milderhc) marked this pull request as draft May 23, 2023 17:57
@yoshioterada

Copy link
Copy Markdown
Member

At the the Java coding point of view, it may be useful for developers can read the properties file from some options like follows.

  1. Read properties from under the class pass, For example
    src/main/java/resources/openaiconf.properties
    String resourcePath = Thread.currentThread().getContextClassLoader().getResource("").getPath();

  2. Environment variable
    It seems that .NET is also using the environment variable
    https://github.com/microsoft/semantic-kernel/tree/main/samples/dotnet/kernel-syntax-examples

  3. Finally, like this implementation, user can specify the directory and file name out side of the class path.
    (This coding)

@milderhc

Copy link
Copy Markdown
Contributor Author

The second point is already supported using Settings.getOpenAISettingsFromEnv and Settings.getAzureOpenAISettingsFromEnv.

@milderhc

Copy link
Copy Markdown
Contributor Author

Added some changes to support multiple client configuration (description updated).

@milderhc
Milder Hernandez (milderhc) marked this pull request as ready for review May 24, 2023 23:28
@karianna

Copy link
Copy Markdown
Member

Milder Hernandez (@milderhc) Can you rebase and see if we can land this PR?

@yoshioterada

Copy link
Copy Markdown
Member

@milderhc

Copy link
Copy Markdown
Contributor Author

Thanks! I like that option, but I would prefer it for a specific Spring settings implementation, if something like that is added later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature branch PR targeting a feature branch java Issue or PR regarding Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants