Skip to content

Commit b69342a

Browse files
Merge branch 'microsoft:main' into update-modelid
2 parents 79627be + e0ccee0 commit b69342a

9 files changed

Lines changed: 382 additions & 72 deletions

File tree

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
---
2+
# Strategy for Community Driven Connectors and Features
3+
4+
status: approved
5+
contact: rogerbarreto
6+
date: 2024-01-24
7+
deciders: rogerbarreto, markwallace-microsoft, dmytrostruk, sergeymenshik
8+
consulted:
9+
informed:
10+
---
11+
12+
# Strategy for Community Driven Connectors and Features
13+
14+
## Context and Problem Statement
15+
16+
Normally Connectors are Middle to Complex new Features that can be developed by a single person or a team. In order to avoid conflicts and to have a better control of the development process, we strongly suggest the usage of a Feature Branch Strategy in our repositories.
17+
18+
In our current software development process, managing changes in the main branch has become increasingly complex, leading to potential conflicts and delays in release cycles.
19+
20+
## Standards and Guidelines Principles
21+
22+
- **Pattern**: The Feature Branch Strategy is a well-known pattern for managing changes in a codebase. It is widely used in the industry and is supported by most version control systems, including GitHub, this also gives further clear picture on how the community can meaningfully contribute to the development of connectors or any other bigger feature for SK.
23+
- **Isolated Development Environments**: By using feature branches, each developer can work on different aspects of the project without interfering with others' work. This isolation reduces conflicts and ensures that the main branch remains stable.
24+
- **Streamlined Integration**: Feature branches simplify the process of integrating new code into the main branch. By dealing with smaller, more manageable changes, the risk of major conflicts during integration is minimized.
25+
- **Efficiency in Code Review**: Smaller, more focused changes in feature branches lead to quicker and more efficient code reviews. This efficiency is not just about the ease of reviewing less code at a time but also about the time saved in understanding the context and impact of the changes.
26+
- **Reduced Risk of Bugs**: Isolating development in feature branches reduces the likelihood of introducing bugs into the main branch. It's easier to identify and fix issues within the confined context of a single feature.
27+
- **Timely Feature Integration**: Small, incremental pull requests allow for quicker reviews and faster integration of features into the feature branch and make it easier to merge down into main as the code was already previously reviewed. This timeliness ensures that features are merged and ready for deployment sooner, improving the responsiveness to changes.
28+
- **Code Testing, Coverage and Quality**: To keep a good code quality is imperative that any new code or feature introduced to the codebase is properly tested and validated. Any new feature or code should be covered by unit tests and integration tests. The code should also be validated by our CI/CD pipeline and follow our code quality standards and guidelines.
29+
- **Examples**: Any new feature or code should be accompanied by examples that demonstrate how to use the new feature or code. This is important to ensure that the new feature or code is properly documented and that the community can easily understand and use it.
30+
31+
### Community Feature Branch Strategy
32+
33+
As soon we identify that contributors are willing to take/create a Feature Issue as a potential connector implementation, we will create a new branch for that feature.
34+
35+
Once we have agreed to take a new connector we will work with the contributors to make sure the implementation progresses and is supported if needed.
36+
37+
The contributor(s) will then be one of the responsibles to incrementally add the majority of changes through small Pull Requests to the feature branch under our supervision and review process.
38+
39+
This strategy involves creating a separate branch in the repository for each new big feature, like connectors. This isolation means that changes are made in a controlled environment without affecting the main branch.
40+
41+
We may also engage in the development and changes to the feature branch when needed, the changes and full or co-authorship on the PRs will be tracked and properly referred into the Release Notes.
42+
43+
#### Pros and Cons
44+
45+
- Good, because it allows for focused development on one feature at a time.
46+
- Good, because it promotes smaller, incremental Pull Requests (PRs), simplifying review processes.
47+
- Good, because it reduces the risk of major bugs being merged into the main branch.
48+
- Good, because it makes the process of integrating features into the main branch easier and faster.
49+
- Bad, potentially, if not managed properly, as it can lead to outdated branches if not regularly synchronized with the main branch.
50+
51+
## Local Deployment Platforms / Offline
52+
53+
### LM Studio
54+
55+
LM Studio has a local deployment option, which can be used to deploy models locally. This option is available for Windows, Linux, and MacOS.
56+
57+
Pros:
58+
59+
- API is very similar to OpenAI API
60+
- Many models are already supported
61+
- Easy to use
62+
- Easy to deploy
63+
- GPU support
64+
65+
Cons:
66+
67+
- May require a license to use in a work environment
68+
69+
### Ollama
70+
71+
Ollama has a local deployment option, which can be used to deploy models locally. This option is available for Linux and MacOS only for now.
72+
73+
Pros:
74+
75+
- Easy to use
76+
- Easy to deploy
77+
- Supports Docker deployment
78+
- GPU support
79+
80+
Cons:
81+
82+
- API is not similar to OpenAI API (Needs a dedicated connector)
83+
- Dont have Windows support
84+
85+
### Comparison
86+
87+
| Feature | Ollama | LM Studio |
88+
| --------------------- | --------------------------------------------------- | --------------------------------------------------------------------------------------- |
89+
| Local LLM | Yes | Yes |
90+
| OpenAI API Similarity | Yes | Yes |
91+
| Windows Support | No | Yes |
92+
| Linux Support | Yes | Yes |
93+
| MacOS Support | Yes | Yes |
94+
| Number of Models | [61](https://ollama.ai/library) +Any GGUF converted | [25](https://github.com/lmstudio-ai/model-catalog/tree/main/models) +Any GGUF Converted |
95+
96+
| Model Support | Ollama | LM Studio |
97+
| --------------- | ------ | --------- |
98+
| Phi-2 Support | Yes | Yes |
99+
| Llama-2 Support | Yes | Yes |
100+
| Mistral Support | Yes | Yes |
101+
102+
## Connector/Model Priorities
103+
104+
Currently we are looking for community support on the following models
105+
106+
The support on the below can be either achieved creating a practical example using one of the existing Connectors against one of this models or providing a new Connector that supports a deployment platform that hosts one of the models below:
107+
108+
| Model Name | Local Support | Deployment | Connectors |
109+
| ---------- | ------------- | -------------------------------------- | ------------------------------------------------------ |
110+
| Gpt-4 | No | OpenAI, Azure | Azure+OpenAI |
111+
| Phi-2 | Yes | Azure, Hugging Face, LM Studio, Ollama | OpenAI, HuggingFace, LM Studio\*\*\*, Ollama\*\* |
112+
| Gemini | No | Google AI Platform | GoogleAI\*\* |
113+
| Llama-2 | Yes | Azure, LM Studio, HuggingFace, Ollama | HuggingFace, Azure+OpenAI, LM Studio\*\*\*, Ollama\*\* |
114+
| Mistral | Yes | Azure, LM Studio, HuggingFace, Ollama | HuggingFace, Azure+OpenAI, LM Studio\*\*\*, Ollama\*\* |
115+
| Claude | No | Anthropic, Amazon Bedrock | Anthropic**, Amazon** |
116+
| Titan | No | Amazon Bedrock | Amazon\*\* |
117+
118+
_\*\* Connectors not yet available_
119+
120+
_\*\*\* May not be needed as an OpenAI Connector can be used_
121+
122+
Connectors may be needed not per Model basis but rather per deployment platform.
123+
For example, using OpenAI or HuggingFace connector you may be able to call a Phi-2 Model.
124+
125+
## Expected Connectors to be implemented
126+
127+
The following deployment platforms are not yet supported by any Connectors and we strongly encourage the community to engage and support on those:
128+
129+
Currently the priorities are ordered but not necessarily needs to be implemented sequentially, an
130+
131+
| Deployment Platform | Local Model Support |
132+
| ------------------- | ------------------- |
133+
| Ollama | Yes |
134+
| GoogleAI | No |
135+
| Anthropic | No |
136+
| Amazon | No |
137+
138+
## Decision Outcome
139+
140+
Chosen option: "Feature Branch Strategy", because it allows individual features to be developed in isolation, minimizing conflicts with the main branch and facilitating easier code reviews.
141+
142+
## Fequent Asked Questions
143+
144+
### Is there a migration strategy for initiatives that followed the old contribution way with forks, and now have to switch to branches in microsoft/semantic-kernel?
145+
146+
You proceed normally with the fork and PR targeting `main`, as soon we identify that your contribution PR to main is a big and desirable feature (Look at the ones we described as expected in this ADR) we will create a dedicated feature branch (`feature-yourfeature`) where you can retarget our forks PR to target it.
147+
All further incremental changes and contributions will follow as normal, but instead of `main` you will be targeting the `feature-*` branch.
148+
149+
### How do you want to solve the "up to date with main branch" problem?
150+
151+
This will happen when we all agreed that the current feature implementation is complete and ready to merge in `main`.
152+
153+
As soon the feature is finished, a merge from main will be pushed into the feature branch.
154+
This will normally trigger the conflicts that need to be sorted.
155+
That normally will be the last PR targeting the feature branch which will be followed right away by another PR from the `feature` branch targeting `main` with minimal conflicts if any.
156+
The merging to main might be fast (as all the intermediate feature PRs were all agreed and approved before)
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
3+
using System.Threading.Tasks;
4+
using Examples;
5+
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.SemanticKernel;
7+
using Xunit;
8+
using Xunit.Abstractions;
9+
10+
public class Example76_Filters : BaseTest
11+
{
12+
/// <summary>
13+
/// Shows how to use function and prompt filters in Kernel.
14+
/// </summary>
15+
[Fact]
16+
public async Task FunctionAndPromptFiltersAsync()
17+
{
18+
var builder = Kernel.CreateBuilder();
19+
20+
builder.AddAzureOpenAIChatCompletion(
21+
deploymentName: TestConfiguration.AzureOpenAI.ChatDeploymentName,
22+
endpoint: TestConfiguration.AzureOpenAI.Endpoint,
23+
apiKey: TestConfiguration.AzureOpenAI.ApiKey);
24+
25+
builder.Services.AddSingleton<ITestOutputHelper>(this.Output);
26+
27+
// Add filters with DI
28+
builder.Services.AddSingleton<IFunctionFilter, FirstFunctionFilter>();
29+
builder.Services.AddSingleton<IFunctionFilter, SecondFunctionFilter>();
30+
31+
var kernel = builder.Build();
32+
33+
// Add filter without DI
34+
kernel.PromptFilters.Add(new FirstPromptFilter(this.Output));
35+
36+
var function = kernel.CreateFunctionFromPrompt("What is Seattle", functionName: "MyFunction");
37+
var result = await kernel.InvokeAsync(function);
38+
39+
WriteLine(result);
40+
}
41+
42+
public Example76_Filters(ITestOutputHelper output) : base(output)
43+
{
44+
}
45+
46+
#region Filters
47+
48+
private sealed class FirstFunctionFilter : IFunctionFilter
49+
{
50+
private readonly ITestOutputHelper _output;
51+
52+
public FirstFunctionFilter(ITestOutputHelper output)
53+
{
54+
this._output = output;
55+
}
56+
57+
public void OnFunctionInvoking(FunctionInvokingContext context) =>
58+
this._output.WriteLine($"{nameof(FirstFunctionFilter)}.{nameof(OnFunctionInvoking)} - {context.Function.Name}");
59+
60+
public void OnFunctionInvoked(FunctionInvokedContext context) =>
61+
this._output.WriteLine($"{nameof(FirstFunctionFilter)}.{nameof(OnFunctionInvoked)} - {context.Function.Name}");
62+
}
63+
64+
private sealed class SecondFunctionFilter : IFunctionFilter
65+
{
66+
private readonly ITestOutputHelper _output;
67+
68+
public SecondFunctionFilter(ITestOutputHelper output)
69+
{
70+
this._output = output;
71+
}
72+
73+
public void OnFunctionInvoking(FunctionInvokingContext context) =>
74+
this._output.WriteLine($"{nameof(SecondFunctionFilter)}.{nameof(OnFunctionInvoking)} - {context.Function.Name}");
75+
76+
public void OnFunctionInvoked(FunctionInvokedContext context) =>
77+
this._output.WriteLine($"{nameof(SecondFunctionFilter)}.{nameof(OnFunctionInvoked)} - {context.Function.Name}");
78+
}
79+
80+
private sealed class FirstPromptFilter : IPromptFilter
81+
{
82+
private readonly ITestOutputHelper _output;
83+
84+
public FirstPromptFilter(ITestOutputHelper output)
85+
{
86+
this._output = output;
87+
}
88+
89+
public void OnPromptRendering(PromptRenderingContext context) =>
90+
this._output.WriteLine($"{nameof(FirstPromptFilter)}.{nameof(OnPromptRendering)} - {context.Function.Name}");
91+
92+
public void OnPromptRendered(PromptRenderedContext context) =>
93+
this._output.WriteLine($"{nameof(FirstPromptFilter)}.{nameof(OnPromptRendered)} - {context.Function.Name}");
94+
}
95+
96+
#endregion
97+
98+
#region Filter capabilities
99+
100+
private sealed class FunctionFilterExample : IFunctionFilter
101+
{
102+
public void OnFunctionInvoked(FunctionInvokedContext context)
103+
{
104+
// Example: get function result value
105+
var value = context.Result.GetValue<object>();
106+
107+
// Example: override function result value
108+
context.SetResultValue("new result value");
109+
110+
// Example: get token usage from metadata
111+
var usage = context.Result.Metadata?["Usage"];
112+
}
113+
114+
public void OnFunctionInvoking(FunctionInvokingContext context)
115+
{
116+
// Example: override kernel arguments
117+
context.Arguments["input"] = "new input";
118+
119+
// Example: cancel function execution
120+
context.Cancel = true;
121+
}
122+
}
123+
124+
private sealed class PromptFilterExample : IPromptFilter
125+
{
126+
public void OnPromptRendered(PromptRenderedContext context)
127+
{
128+
// Example: override rendered prompt before sending it to AI
129+
context.RenderedPrompt = "Safe prompt";
130+
}
131+
132+
public void OnPromptRendering(PromptRenderingContext context)
133+
{
134+
// Example: get function information
135+
var functionName = context.Function.Name;
136+
}
137+
}
138+
139+
#endregion
140+
}

‎dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ private static CompletionsOptions CreateCompletionsOptions(string text, OpenAIPr
714714
ChoicesPerPrompt = executionSettings.ResultsPerPrompt,
715715
GenerationSampleCount = executionSettings.ResultsPerPrompt,
716716
LogProbabilityCount = null,
717-
User = null,
717+
User = executionSettings.User,
718718
DeploymentName = deploymentOrModelName
719719
};
720720

@@ -758,6 +758,7 @@ private static ChatCompletionsOptions CreateChatCompletionsOptions(
758758
ChoiceCount = executionSettings.ResultsPerPrompt,
759759
DeploymentName = deploymentOrModelName,
760760
Seed = executionSettings.Seed,
761+
User = executionSettings.User
761762
};
762763

763764
switch (executionSettings.ResponseFormat)

‎dotnet/src/Connectors/Connectors.OpenAI/OpenAIPromptExecutionSettings.cs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ public string ChatSystemPrompt
139139
/// </remarks>
140140
public ToolCallBehavior? ToolCallBehavior { get; set; }
141141

142+
/// <summary>
143+
/// A unique identifier representing your end-user, which can help OpenAI to monitor and detect abuse
144+
/// </summary>
145+
public string? User { get; set; }
146+
142147
/// <summary>
143148
/// Default value for chat system property.
144149
/// </summary>

‎python/semantic_kernel/connectors/ai/open_ai/request_settings/open_ai_request_settings.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from pydantic import Field, field_validator, model_validator
55

66
from semantic_kernel.connectors.ai.ai_request_settings import AIRequestSettings
7-
from semantic_kernel.connectors.ai.open_ai.const import DEFAULT_CHAT_SYSTEM_PROMPT
87

98
logger = logging.getLogger(__name__)
109

@@ -59,7 +58,7 @@ class OpenAIChatRequestSettings(OpenAIRequestSettings):
5958
tool_choice: Optional[str] = None
6059
function_call: Optional[str] = None
6160
functions: Optional[List[Dict[str, Any]]] = None
62-
messages: Optional[List[Dict[str, Any]]] = [{"role": "system", "content": DEFAULT_CHAT_SYSTEM_PROMPT}]
61+
messages: Optional[List[Dict[str, Any]]] = None
6362

6463
@field_validator("functions", "function_call", mode="after")
6564
@classmethod

0 commit comments

Comments
 (0)