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: Pydantic settings config #6392

Merged

Conversation

eavanvalkenburg
Copy link
Member

Motivation and Context

The initial implementation of Pydantic Settings was not optimal yet, more optimized now.

Description

Added a KernelBaseSettings class in kernel_pydantic
Rebased all settings off that
Added single create method to KernelBaseSettings:

  • sets model_config.env_prefix to cls.end_prefix allowing us to set the env_prefix as a classvar on each subclass and it works
  • if env_file_path is set, set that in model_config
  • strip all None values out of inputted values, then instantiate

This also allows us to pass the settings that are supplied to the settings class, for overriding env settings.

Contribution Checklist

@eavanvalkenburg eavanvalkenburg requested a review from a team as a code owner May 24, 2024 21:08
@markwallace-microsoft markwallace-microsoft added python Pull requests for the Python Semantic Kernel memory labels May 24, 2024
@markwallace-microsoft
Copy link
Member

markwallace-microsoft commented May 24, 2024

Py3.10 Test Coverage

Python 3.10 Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel
   kernel_pydantic.py21195%51
semantic_kernel/connectors/ai/google_palm/services
   gp_chat_completion.py691677%68, 155–160, 172–173, 212, 215, 218–219, 227, 231–232, 240
   gp_text_completion.py41685%55, 79–80, 86–87, 122
   gp_text_embedding.py34585%54, 65–66, 75–76
semantic_kernel/connectors/ai/open_ai/prompt_execution_settings
   azure_chat_prompt_execution_settings.py66395%89–96, 109
semantic_kernel/connectors/ai/open_ai/services
   azure_chat_completion.py873461%141, 147–148, 157–158, 163–180, 184–191, 203–214
   open_ai_chat_completion.py23196%61
   open_ai_text_completion.py25292%61, 80
   open_ai_text_embedding.py24483%59–60, 62, 80
semantic_kernel/connectors/search_engine
   bing_connector.py33330%3–74
   bing_connector_settings.py660%3–25
semantic_kernel/core_plugins/sessions_python_tool
   sessions_python_plugin.py1031486%59–61, 81, 84, 89–95, 135, 182, 186
TOTAL605885886% 

Python 3.10 Unit Test Overview

Tests Skipped Failures Errors Time
1396 1 💤 0 ❌ 0 🔥 16.558s ⏱️

@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 29, 2024
@moonbox3 moonbox3 removed this pull request from the merge queue due to a manual request May 29, 2024
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 29, 2024
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 29, 2024
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 30, 2024
@eavanvalkenburg eavanvalkenburg removed this pull request from the merge queue due to a manual request May 30, 2024
@eavanvalkenburg eavanvalkenburg removed this pull request from the merge queue due to a manual request May 30, 2024
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 30, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 30, 2024
@eavanvalkenburg eavanvalkenburg added this pull request to the merge queue May 30, 2024
Merged via the queue into microsoft:main with commit 7ce352b May 30, 2024
23 checks passed
@eavanvalkenburg eavanvalkenburg deleted the pydantic_settings_config branch May 30, 2024 09:45
LudoCorporateShark pushed a commit to LudoCorporateShark/semantic-kernel that referenced this pull request Aug 25, 2024
### Motivation and Context

<!-- Thank you for your contribution to the semantic-kernel repo!
Please help reviewers and future users, providing the following
information:
  1. Why is this change required?
  2. What problem does it solve?
  3. What scenario does it contribute to?
  4. If it fixes an open issue, please link to the issue here.
-->
The initial implementation of Pydantic Settings was not optimal yet,
more optimized now.

### Description

Added a KernelBaseSettings class in kernel_pydantic
Rebased all settings off that
Added single create method to KernelBaseSettings:
- sets model_config.env_prefix to cls.end_prefix allowing us to set the
env_prefix as a classvar on each subclass and it works
- if env_file_path is set, set that in model_config
- strip all None values out of inputted values, then instantiate

This also allows us to pass the settings that are supplied to the
settings class, for overriding env settings.

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [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 😄
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
memory python Pull requests for the Python Semantic Kernel
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants