Skip to content

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
wants to merge 16 commits into from
Closed

Conversation

adamsitnik
Copy link
Member

No description provided.

adamsitnik and others added 16 commits March 19, 2025 12:25
### 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.


![image](https://github.com/user-attachments/assets/4e39833d-6453-4440-9efa-01f561f80743)
…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>
It's a resurrected #10788 built on top of #10944 which I hope will get
merged first.

fixes #10415

---------

Co-authored-by: westey <164392973+westey-m@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>
@adamsitnik adamsitnik requested review from a team as code owners March 20, 2025 16:47
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code python Pull requests for the Python Semantic Kernel kernel Issues or pull requests impacting the core kernel documentation memory labels Mar 20, 2025
@github-actions github-actions bot changed the title Merge main into preb2 .Net: Merge main into preb2 Mar 20, 2025
@github-actions github-actions bot changed the title .Net: Merge main into preb2 Python: Merge main into preb2 Mar 20, 2025
@adamsitnik adamsitnik requested review from roji and westey-m March 20, 2025 16:48
@markwallace-microsoft
Copy link
Member

Python Test Coverage

Python Test Coverage Report •
FileStmtsMissCoverMissing
semantic_kernel/connectors/ai/open_ai/services
   azure_realtime.py29872%90–105, 124
semantic_kernel/functions
   kernel_function_from_method.py96199%153
TOTAL20883233289% 

Python Unit Test Overview

Tests Skipped Failures Errors Time
3334 5 💤 0 ❌ 0 🔥 1m 44s ⏱️

@adamsitnik
Copy link
Member Author

As agreed offline, let's merge #11095 instead

@adamsitnik adamsitnik closed this Mar 20, 2025
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants