Skip to content
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

Python: Refactor environment variable naming for clarity and consistency #5686

Merged
merged 18 commits into from
Apr 16, 2024

Conversation

bx-h
Copy link
Contributor

@bx-h bx-h commented Mar 28, 2024

Summary of Changes

  • Updated environment variable names to use single underscores for better readability and to avoid potential confusion.
  • Modified service_configurator.py to align with the updated environment variable naming convention.
  • Updated .env.example to reflect the new environment variable names, ensuring consistency across the project.
  • Added error handling and improved error messages in service_configurator.py for better debugging and maintainability.

Motivation and Context

The motivation for these changes is to address a bug where the service_configurator.py script is unable to read the GLOBAL_LLM_SERVICE environment variable due to inconsistent naming conventions. Additionally, the Azure service configuration variables were not being utilized, which could potentially lead to misconfigurations in certain deployment scenarios.

  • Why is this change required? To fix existing bugs related to environment variable handling and improve code maintainability and readability.
  • What problem does it solve? Ensures reliable loading of environment variables and correct configuration of AI services, thereby preventing runtime errors.
  • What scenario does it contribute to? Enhances the stability and reliability of the AI service configuration process within the semantic-kernel project.

Description

This PR addresses the issue where the environment variable GLOBAL_LLM_SERVICE was not consistently read due to a mismatch in the expected naming convention. The problem was identified in the service_configurator.py script where the variable was referenced with two underscores instead of one. Additionally, Azure service deployment names were not being used, leading to potential misconfigurations.

  • Modified the naming convention from double to single underscores for all environment variables in service_configurator.py and .env.example.
  • Ensured that Azure service deployment names are correctly utilized in the service configuration logic.
  • Improved error handling in the script to provide clearer and more actionable feedback.

For more context, here's a link to the buggy code: Link to the code, Link to the code

1
2

Contribution Checklist

- Updated environment variable names to use single underscores for better readability and to avoid potential confusion.
- Modified `service_configurator.py` to align with the updated environment variable naming convention.
- Updated `.env.example` to reflect the new environment variable names, ensuring consistency across the project.
- Added error handling and improved error messages in `service_configurator.py` for better debugging and maintainability.
@bx-h bx-h requested a review from a team as a code owner March 28, 2024 07:30
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel documentation labels Mar 28, 2024
@github-actions github-actions bot changed the title Refactor environment variable naming for clarity and consistency Python: Refactor environment variable naming for clarity and consistency Mar 28, 2024
@bx-h
Copy link
Contributor Author

bx-h commented Mar 28, 2024

unit test
Snipaste_2024-03-28_16-34-08

@eavanvalkenburg
Copy link
Member

unit test Snipaste_2024-03-28_16-34-08

Unit test indeed all runs, lint does not, please run the checks!

@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented Apr 1, 2024

Py3.8 Test Coverage

Python 3.8 Test Coverage Report •
FileStmtsMissCoverMissing
TOTAL5571101582% 
report-only-changed-files is enabled. No files were changed during this commit :)

Python 3.8 Unit Test Overview

Tests Skipped Failures Errors Time
1211 11 💤 0 ❌ 0 🔥 21.446s ⏱️

@moonbox3 moonbox3 enabled auto-merge April 3, 2024 13:32
@bx-h
Copy link
Contributor Author

bx-h commented Apr 16, 2024

HI, I've noticed that this PR hasn't been approved yet. Are there any issues, or is there anything else I should add? Please let me know :)

@moonbox3
Copy link
Contributor

HI, I've noticed that this PR hasn't been approved yet. Are there any issues, or is there anything else I should add? Please let me know :)

Thanks for following up. Just need one more approval from @eavanvalkenburg or @juliomenendez.

@moonbox3 moonbox3 added this pull request to the merge queue Apr 16, 2024
Merged via the queue into microsoft:main with commit 8b3203a Apr 16, 2024
30 checks passed
@moonbox3
Copy link
Contributor

Thank you for your contribution, @bx-h.

LudoCorporateShark pushed a commit to LudoCorporateShark/semantic-kernel that referenced this pull request Aug 25, 2024
…ncy (microsoft#5686)

### Summary of Changes

- Updated environment variable names to use single underscores for
better readability and to avoid potential confusion.
- Modified `service_configurator.py` to align with the updated
environment variable naming convention.
- Updated `.env.example` to reflect the new environment variable names,
ensuring consistency across the project.
- Added error handling and improved error messages in
`service_configurator.py` for better debugging and maintainability.

### Motivation and Context

The motivation for these changes is to address a bug where the
`service_configurator.py` script is unable to read the
`GLOBAL_LLM_SERVICE` environment variable due to inconsistent naming
conventions. Additionally, the Azure service configuration variables
were not being utilized, which could potentially lead to
misconfigurations in certain deployment scenarios.

- **Why is this change required?** To fix existing bugs related to
environment variable handling and improve code maintainability and
readability.
- **What problem does it solve?** Ensures reliable loading of
environment variables and correct configuration of AI services, thereby
preventing runtime errors.
- **What scenario does it contribute to?** Enhances the stability and
reliability of the AI service configuration process within the
semantic-kernel project.

### Description

This PR addresses the issue where the environment variable
`GLOBAL_LLM_SERVICE` was not consistently read due to a mismatch in the
expected naming convention. The problem was identified in the
`service_configurator.py` script where the variable was referenced with
two underscores instead of one. Additionally, Azure service deployment
names were not being used, leading to potential misconfigurations.

- Modified the naming convention from double to single underscores for
all environment variables in `service_configurator.py` and
`.env.example`.
- Ensured that Azure service deployment names are correctly utilized in
the service configuration logic.
- Improved error handling in the script to provide clearer and more
actionable feedback.

For more context, here's a link to the buggy code: [Link to the
code](https://github.com/microsoft/semantic-kernel/blob/main/python/samples/documentation_examples/service_configurator.py#L27),
[Link to the
code](https://github.com/microsoft/semantic-kernel/blob/main/python/samples/documentation_examples/.env.example#L1)


![1](https://github.com/microsoft/semantic-kernel/assets/22412942/4bd00119-c2d6-41ee-9bbf-67e6e99e8536)

![2](https://github.com/microsoft/semantic-kernel/assets/22412942/ac6c0f56-c4bd-4383-99da-61f728ae931f)


### Contribution Checklist

- [x] The code builds clean without any errors or warnings.
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations.
- [x] All unit tests pass, and I have added new tests where possible.
- [x] I didn't break anyone 😄

---------

Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants