-
Notifications
You must be signed in to change notification settings - Fork 4k
Python: Merge main into preb2 #11094
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
Closed
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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 fixes links that were found unreachable by `linkspector`: https://github.com/microsoft/semantic-kernel/actions/runs/13954045797/job/39063140670?pr=11055 ### 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 😄
### Motivation and Context For quite a while the SYSLIB1222, are present in the solution. This PR suppress them and another new JSON001 warning. 
…ion (#10849) ### Motivation and Context Improve overall unit test coverage. ### Description - adding unit tests for ollama services utils - adding unit tests for dapr_actor_registration ### 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 😄 --------- Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
### Motivation and Context The current AzureAIAgent retrieval sample uses the old `assistant_id` kwarg to retrieve the agent. We need to fix this to use the new `agent_id` kwarg in AzureAIAgent retrieval sample <!-- 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 Fix the kwarg to use `agent_id`. <!-- 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 😄
### 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 😄
### Motivation and Context In creating the `AzureRealtimeWebsocket` object, one can use an api key as part of `AzureOpenAISettings`. This api_key is not getting passed to the `AzureOpenAIConfigBase`. <!-- 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 Pass the api key to the config base. - Closes #11003 <!-- 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 😄
### Motivation and Context When trying to do a model dump for `KernelFunction` models, they are failing with a message related to: ``` pydantic_core._pydantic_core.PydanticSerializationError: Unable to serialize unknown type: <class 'type'> ``` There are some class-level attributes that cannot be properly serialized. <!-- 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 Exclude dumping certain model attributes from the model dump, which allows the main KernelFunction metadata and its underlying parameters to be serialized. - Closes #11078 - Adds unit tests to ensure we have coverage and can dump Pydantic models. <!-- 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 😄
### 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. --> Removed some of the old search samples. ### 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 😄
### 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 😄
### Motivation and Context - Resolves #11071 Minor fixes: - Broken link fix
### Motivation and Context Removing AllowUnsafeBlocks from the project file as this is no more needed in the current code base. This change ensures the project is safer by disallowing the use of unsafe code blocks.
### Motivation and Context The given test was giving a false negative in environments where Bedrock Runtime was property configured and could be retrieved from the DI container. This change ensures this test only executes when the environment has no runtime configured to be recovered from the DI container.
) ### Motivation and Context Adds two new Python demos demonstrating integration with Microsoft Copilot Studio (MCS). ### Description - `copilot_studio_agent` features a new subclass of `Agent` connecting to a Microsoft Copilot Studio agent via DirectLine API - `copilot_studio_skill` showcases how to extend MCS to connect directly to a Semantic Kernel Agent, by defining a _skill_ ### 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 😄 --------- Co-authored-by: Evan Mattson <35585003+moonbox3@users.noreply.github.com>
This PR introduces a new property to OpenAIPromptExecutionSettings to enable OpenAI's web search feature. If specified, the property allows web search to be utilized before generating responses in Semantic Kernel. If set to null, it is ignored during serialization. ### Motivation and Context 1. Why is this change required? OpenAI has released an update that enables web search functionality before generating responses. We want to leverage this feature within Semantic Kernel. 3. What problem does it solve? By adding new property to OpenAIPromptExecutionSettings, the new parameter for web search will be used when calling OpenAI API. ### Description A new property has been added to OpenAIPromptExecutionSettings. I decided to use `object?` instead of strong typed value so it will be easier to adapt with new settings from OpenAI. ``` /// <summary> /// Enables the web search feature when specified. If set to null, the option is ignored during serialization. /// </summary> [Experimental("SKEXP0010")] [JsonPropertyName("web_search_options")] [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] public object? WebSearchOptions { get => this._webSearchOptions; set { this.ThrowIfFrozen(); this._webSearchOptions = value; } } ``` ### Sample code Based on OpenAI documentation: https://platform.openai.com/docs/guides/tools-web-search?api-mode=chat #### Default settings ``` var builder = Kernel.CreateBuilder() .AddOpenAIChatCompletion( modelId: "gpt-4o-mini-search-preview", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY", EnvironmentVariableTarget.User) ); var kernel = builder.Build(); var executionSettings = new OpenAIPromptExecutionSettings { WebSearchOptions = new { } }; var chatClient = kernel.GetRequiredService<IChatCompletionService>(); var response = await chatClient.GetChatMessageContentAsync("What was a positive news story from today?", executionSettings, kernel); ``` #### Web search with user location To refine search results based on geography, you can specify an approximate user location using country, city, region, and/or timezone. The *city* and *region* fields are free text strings, like Minneapolis and Minnesota respectively. The *country* field is a two-letter *[ISO country code]*(https://en.wikipedia.org/wiki/ISO_3166-1), like US. The *timezone* field is an [IANA timezone](https://timeapi.io/documentation/iana-timezones) like America/Chicago. ``` var executionSettings = new OpenAIPromptExecutionSettings { WebSearchOptions = new { user_location = new { type = "approximate", approximate = new { country = "GB", city = "London", region = "London", } }, } }; var chatClient = kernel.GetRequiredService<IChatCompletionService>(); var response = await chatClient.GetChatMessageContentAsync("What are the best restaurants around Granary Square?", executionSettings, kernel); ``` #### Specify context size When using this tool, the *search_context_size* parameter controls how much context is retrieved from the web to help the tool formulate a response. The tokens used by the search tool do not affect the context window of the main model specified in the model parameter in your response creation request. These tokens are also not carried over from one turn to another — they're simply used to formulate the tool response and then discarded. *Choosing a context size impacts:* Cost: Pricing of our search tool varies based on the value of this parameter. Higher context sizes are more expensive. See tool pricing [here](https://platform.openai.com/docs/pricing). Quality: Higher search context sizes generally provide richer context, resulting in more accurate, comprehensive answers. Latency: Higher context sizes require processing more tokens, which can slow down the tool's response time. Available values: - *high*: Most comprehensive context, highest cost, slower response. - *medium* (default): Balanced context, cost, and latency. - *low*: Least context, lowest cost, fastest response, but potentially lower answer quality. ``` var executionSettings = new OpenAIPromptExecutionSettings { WebSearchOptions = new { search_context_size = "low" } }; ``` ### 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: Dat Hoang Quoc <DAT@jsworldmedia.com> Co-authored-by: Roger Barreto <19890735+RogerBarreto@users.noreply.github.com>
dmytrostruk
approved these changes
Mar 20, 2025
Python Test Coverage Report •
Python Unit Test Overview
|
As agreed offline, let's merge #11095 instead |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
documentation
kernel
Issues or pull requests impacting the core kernel
memory
.NET
Issue or Pull requests regarding .NET code
python
Pull requests for the Python Semantic Kernel
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.