Skip to content

Add settings retrieval through properties file and env vars#1176

Closed
milderhc wants to merge 7 commits intomicrosoft:experimental-javafrom
milderhc:settings
Closed

Add settings retrieval through properties file and env vars#1176
milderhc wants to merge 7 commits intomicrosoft:experimental-javafrom
milderhc:settings

Conversation

@milderhc
Copy link
Contributor

@milderhc milderhc commented May 23, 2023

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 lemillermicrosoft added feature branch PR targeting a feature branch java Issue or PR regarding Java code labels May 23, 2023
@milderhc milderhc marked this pull request as draft May 23, 2023 17:57
@yoshioterada
Copy link
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
Contributor Author

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

@milderhc
Copy link
Contributor Author

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

@milderhc milderhc marked this pull request as ready for review May 24, 2023 23:28
@karianna
Copy link
Member

karianna commented Jun 5, 2023

@milderhc Can you rebase and see if we can land this PR?

@yoshioterada
Copy link
Member

Dear @milderhc san

Thank you so much for your hard work. I much appreciate.

BTW, from the Developers Point of view,
As you know, especially Spring user may want to use with following @value annotation.
So please confirm, your new implementation is available with the above annotation too.

For Example:

https://github.com/yoshioterada/MS-OpenAI-Java-Lib-Sample/blob/048df7556ef5517aa81551dcdd09179348706be0/src/main/java/com/yoshio3/SSEOpenAIController.java#L40-L50

https://github.com/yoshioterada/MS-OpenAI-Java-Lib-Sample/blob/048df7556ef5517aa81551dcdd09179348706be0/src/main/resources/application.properties#L1-L4

@milderhc
Copy link
Contributor Author

milderhc commented Jun 6, 2023

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