Files
semantic-kernel/python/samples
8b3203af52 Python: Refactor environment variable naming for clarity and consistency (#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 <[email protected]>
Co-authored-by: Chris <[email protected]>
2024-04-16 15:33:11 +00:00
..