SIGN IN SIGN UP

Integrate cutting-edge LLM technology quickly and easily into your apps

0 0 11 C#
# Copyright (c) Microsoft. All rights reserved.
Python: Enable core skills, retry mechanisms and template engine protocols to be used as pydantic fields (#2287) ### Summary This is part 1 of the Serialization work for semantic kernel. Corresponding issue: https://github.com/microsoft/semantic-kernel/issues/131 ### Motivation and Context This PR allows core skills (all except 2), retry mechanisms and template engine protocols to be used as valid pydantic fields. This allows me to convert the classes that depend on these classes to pydantic models, and thus be able to serialize them. No user facing code changes are expected from this PR. <!-- 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. --> ### Description <!-- 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 :smile: --------- Co-authored-by: Abby Harrison <abharris@microsoft.com>
2023-08-03 10:53:01 -07:00
import logging
Python: Pydantic settings config (#6392) ### 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 :smile:
2024-05-30 11:38:28 +02:00
from typing import Annotated, Any, ClassVar, TypeVar
Python: Enable core skills, retry mechanisms and template engine protocols to be used as pydantic fields (#2287) ### Summary This is part 1 of the Serialization work for semantic kernel. Corresponding issue: https://github.com/microsoft/semantic-kernel/issues/131 ### Motivation and Context This PR allows core skills (all except 2), retry mechanisms and template engine protocols to be used as valid pydantic fields. This allows me to convert the classes that depend on these classes to pydantic models, and thus be able to serialize them. No user facing code changes are expected from this PR. <!-- 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. --> ### Description <!-- 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 :smile: --------- Co-authored-by: Abby Harrison <abharris@microsoft.com>
2023-08-03 10:53:01 -07:00
Python: Feature new memory stores and collections (#7614) ### 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. --> This PR adds new vector store and vector store record collections as well as implementations for: - Azure AI Search - Redis - Qdrant - Volatile (in-memory) It also adds samples, tests, and unit-tests for these. Next it adds the vector store record fields, definition and decorator, with tests and samples. All marked experimental. Existing Redis, Azure AI Search, Qdrant and Volatile will be marked as deprecated in the future, once the new collections are feature complete. ### Description <!-- 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 :smile:
2024-08-06 22:30:26 +02:00
from pydantic import BaseModel, ConfigDict, Field, UrlConstraints
from pydantic.networks import AnyUrl
Python: Pydantic settings config (#6392) ### 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 :smile:
2024-05-30 11:38:28 +02:00
from pydantic_settings import BaseSettings, SettingsConfigDict
Python: Enable core skills, retry mechanisms and template engine protocols to be used as pydantic fields (#2287) ### Summary This is part 1 of the Serialization work for semantic kernel. Corresponding issue: https://github.com/microsoft/semantic-kernel/issues/131 ### Motivation and Context This PR allows core skills (all except 2), retry mechanisms and template engine protocols to be used as valid pydantic fields. This allows me to convert the classes that depend on these classes to pydantic models, and thus be able to serialize them. No user facing code changes are expected from this PR. <!-- 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. --> ### Description <!-- 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 :smile: --------- Co-authored-by: Abby Harrison <abharris@microsoft.com>
2023-08-03 10:53:01 -07:00
HttpsUrl = Annotated[AnyUrl, UrlConstraints(max_length=2083, allowed_schemes=["https"])]
Python: Make SK compatible with OpenAI 1.0 (#3555) Need to update SK Python to integrate the breaking changes from openai-python 1.0 https://github.com/microsoft/semantic-kernel/issues/3330 This PR replaces the old one that was merging to main https://github.com/microsoft/semantic-kernel/pull/3417 --------- ### 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. --> ### Description <!-- 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: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone :smile: --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Joowon <joowon.kim@dm.snu.ac.kr> Co-authored-by: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com> Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> Co-authored-by: Ben Thomas <ben.thomas@microsoft.com> Co-authored-by: Ben Thomas <bentho@microsoft.com> Co-authored-by: Devis Lucato <dluc@users.noreply.github.com> Co-authored-by: Aayush Kataria <aayushkataria3011@gmail.com> Co-authored-by: Abby Harrison <abby.harrison@microsoft.com> Co-authored-by: Abby Harrison <54643756+awharrison-28@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Teresa Hoang <125500434+teresaqhoang@users.noreply.github.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> Co-authored-by: Gil LaHaye <gillahaye@microsoft.com> Co-authored-by: Gina Triolo <51341242+gitri-ms@users.noreply.github.com> Co-authored-by: Tao Chen <TaoChenOSU@users.noreply.github.com> Co-authored-by: Lee Miller <lemiller@microsoft.com> Co-authored-by: Jennifer Marsman <jennifermarsman@users.noreply.github.com> Co-authored-by: Weihan Li <weihanli@outlook.com> Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Co-authored-by: Diego Colombo <dicolomb@microsoft.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Chao <achao@achao> Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com> Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com> Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
2023-11-28 22:44:10 -08:00
logger = logging.getLogger("semantic_kernel")
Python: Make SK compatible with OpenAI 1.0 (#3555) Need to update SK Python to integrate the breaking changes from openai-python 1.0 https://github.com/microsoft/semantic-kernel/issues/3330 This PR replaces the old one that was merging to main https://github.com/microsoft/semantic-kernel/pull/3417 --------- ### 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. --> ### Description <!-- 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: --> - [ ] The code builds clean without any errors or warnings - [ ] 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 - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone :smile: --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Joowon <joowon.kim@dm.snu.ac.kr> Co-authored-by: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com> Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com> Co-authored-by: Mark Wallace <127216156+markwallace-microsoft@users.noreply.github.com> Co-authored-by: Ben Thomas <ben.thomas@microsoft.com> Co-authored-by: Ben Thomas <bentho@microsoft.com> Co-authored-by: Devis Lucato <dluc@users.noreply.github.com> Co-authored-by: Aayush Kataria <aayushkataria3011@gmail.com> Co-authored-by: Abby Harrison <abby.harrison@microsoft.com> Co-authored-by: Abby Harrison <54643756+awharrison-28@users.noreply.github.com> Co-authored-by: Stephen Toub <stoub@microsoft.com> Co-authored-by: Teresa Hoang <125500434+teresaqhoang@users.noreply.github.com> Co-authored-by: Chris <66376200+crickman@users.noreply.github.com> Co-authored-by: Gil LaHaye <gillahaye@microsoft.com> Co-authored-by: Gina Triolo <51341242+gitri-ms@users.noreply.github.com> Co-authored-by: Tao Chen <TaoChenOSU@users.noreply.github.com> Co-authored-by: Lee Miller <lemiller@microsoft.com> Co-authored-by: Jennifer Marsman <jennifermarsman@users.noreply.github.com> Co-authored-by: Weihan Li <weihanli@outlook.com> Co-authored-by: SergeyMenshykh <68852919+SergeyMenshykh@users.noreply.github.com> Co-authored-by: Diego Colombo <dicolomb@microsoft.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alex Chao <achao@achao> Co-authored-by: Eduard van Valkenburg <eavanvalkenburg@users.noreply.github.com> Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com> Co-authored-by: Evan Mattson <evan.mattson@microsoft.com>
2023-11-28 22:44:10 -08:00
class KernelBaseModel(BaseModel):
Python: Enable core skills, retry mechanisms and template engine protocols to be used as pydantic fields (#2287) ### Summary This is part 1 of the Serialization work for semantic kernel. Corresponding issue: https://github.com/microsoft/semantic-kernel/issues/131 ### Motivation and Context This PR allows core skills (all except 2), retry mechanisms and template engine protocols to be used as valid pydantic fields. This allows me to convert the classes that depend on these classes to pydantic models, and thus be able to serialize them. No user facing code changes are expected from this PR. <!-- 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. --> ### Description <!-- 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 :smile: --------- Co-authored-by: Abby Harrison <abharris@microsoft.com>
2023-08-03 10:53:01 -07:00
"""Base class for all pydantic models in the SK."""
model_config = ConfigDict(populate_by_name=True, arbitrary_types_allowed=True, validate_assignment=True)
Python: Pydantic settings config (#6392) ### 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 :smile:
2024-05-30 11:38:28 +02:00
T = TypeVar("T", bound="KernelBaseSettings")
class KernelBaseSettings(BaseSettings):
"""Base class for all settings classes in the SK.
A subclass creates it's fields and overrides the env_prefix class variable
with the prefix for the environment variables.
In the case where a value is specified for the same Settings field in multiple ways,
the selected value is determined as follows (in descending order of priority):
- Arguments passed to the Settings class initializer.
Python: Pydantic settings config (#6392) ### 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 :smile:
2024-05-30 11:38:28 +02:00
- Environment variables, e.g. my_prefix_special_function as described above.
- Variables loaded from a dotenv (.env) file.
- Variables loaded from the secrets directory.
- The default field values for the Settings model.
"""
env_prefix: ClassVar[str] = ""
Python: improved content inits, added ndarray support for binary content and small fixes to defaults (#10469) ### 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. --> This PR adds support for ndarray's as the content carrier for all binary content types (binary, image, audio) as that is more optimized for larger content. It also does some fixes to the initialization of those content types and the underlying data uri type. Also some fixes for unspecified default param in pydantic Field, language servers do not recognize `Field("default value")` as having a default, so changed those occurances to `Field(default="default value")` ### Description <!-- 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 :smile:
2025-02-12 17:59:08 +01:00
env_file_path: str | None = Field(default=None, exclude=True)
env_file_encoding: str | None = Field(default="utf-8", exclude=True)
Python: Pydantic settings config (#6392) ### 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 :smile:
2024-05-30 11:38:28 +02:00
model_config = SettingsConfigDict(
extra="ignore",
case_sensitive=False,
)
def __init__(
self,
**kwargs: Any,
) -> None:
"""Initialize the settings class."""
# Remove any None values from the kwargs so that defaults are used.
kwargs = {k: v for k, v in kwargs.items() if v is not None}
super().__init__(**kwargs)
def __new__(cls: type["T"], *args: Any, **kwargs: Any) -> "T":
"""Override the __new__ method to set the env_prefix."""
# for both, if supplied but None, set to default
if "env_file_encoding" in kwargs and kwargs["env_file_encoding"] is not None:
env_file_encoding = kwargs["env_file_encoding"]
else:
env_file_encoding = "utf-8"
if "env_file_path" in kwargs and kwargs["env_file_path"] is not None:
env_file_path = kwargs["env_file_path"]
else:
env_file_path = ".env"
cls.model_config.update( # type: ignore
env_prefix=cls.env_prefix,
env_file=env_file_path,
env_file_encoding=env_file_encoding,
)
cls.model_rebuild()
return super().__new__(cls)
Python: Pydantic settings config (#6392) ### 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 :smile:
2024-05-30 11:38:28 +02:00
@classmethod
def create(cls: type["T"], **data: Any) -> "T":
"""Update the model_config with the prefix."""
logger.warning(
"The create method is deprecated. Use the __new__ method instead.",
)
Python: Pydantic settings config (#6392) ### 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 :smile:
2024-05-30 11:38:28 +02:00
return cls(**data)