-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into remove-system-memory-data
- Loading branch information
Showing
195 changed files
with
10,362 additions
and
2,861 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
69 changes: 0 additions & 69 deletions
69
dotnet/samples/Concepts/Agents/OpenAIAssistant_FileService.cs
This file was deleted.
Oops, something went wrong.
This file contains 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
89 changes: 89 additions & 0 deletions
89
dotnet/samples/Concepts/FunctionCalling/AzureAIInference_FunctionCalling.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Connectors.AzureAIInference; | ||
|
||
namespace FunctionCalling; | ||
public class AzureAIInference_FunctionCalling : BaseTest | ||
{ | ||
private readonly LoggingHandler _handler; | ||
private readonly HttpClient _httpClient; | ||
private bool _isDisposed; | ||
|
||
public AzureAIInference_FunctionCalling(ITestOutputHelper output) : base(output) | ||
{ | ||
// Create a logging handler to output HTTP requests and responses | ||
this._handler = new LoggingHandler(new HttpClientHandler(), this.Output); | ||
this._httpClient = new(this._handler); | ||
} | ||
|
||
/// <summary> | ||
/// This example demonstrates usage of <see cref="FunctionChoiceBehavior.Auto"/> that advertises all kernel functions to the AI model. | ||
/// </summary> | ||
[Fact] | ||
public async Task FunctionCallingAsync() | ||
{ | ||
var kernel = CreateKernel(); | ||
AzureAIInferencePromptExecutionSettings settings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }; | ||
Console.WriteLine(await kernel.InvokePromptAsync("Given the current time of day and weather, what is the likely color of the sky in Boston?", new(settings))); | ||
} | ||
|
||
/// <summary> | ||
/// This example demonstrates usage of <see cref="FunctionChoiceBehavior.Auto"/> that advertises all kernel functions to the AI model. | ||
/// </summary> | ||
[Fact] | ||
public async Task FunctionCallingWithPromptExecutionSettingsAsync() | ||
{ | ||
var kernel = CreateKernel(); | ||
PromptExecutionSettings settings = new() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }; | ||
Console.WriteLine(await kernel.InvokePromptAsync("Given the current time of day and weather, what is the likely color of the sky in Boston?", new(settings))); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (!this._isDisposed) | ||
{ | ||
if (disposing) | ||
{ | ||
this._handler.Dispose(); | ||
this._httpClient.Dispose(); | ||
} | ||
|
||
this._isDisposed = true; | ||
} | ||
base.Dispose(disposing); | ||
} | ||
|
||
private Kernel CreateKernel() | ||
{ | ||
// Create kernel | ||
var kernel = Kernel.CreateBuilder() | ||
.AddAzureAIInferenceChatCompletion( | ||
modelId: TestConfiguration.AzureAIInference.ChatModelId, | ||
endpoint: new Uri(TestConfiguration.AzureAIInference.Endpoint), | ||
apiKey: TestConfiguration.AzureAIInference.ApiKey, | ||
httpClient: this._httpClient) | ||
.Build(); | ||
|
||
// Add a plugin with some helper functions we want to allow the model to call. | ||
kernel.ImportPluginFromFunctions("HelperFunctions", | ||
[ | ||
kernel.CreateFunctionFromMethod(() => new List<string> { "Squirrel Steals Show", "Dog Wins Lottery" }, "GetLatestNewsTitles", "Retrieves latest news titles."), | ||
kernel.CreateFunctionFromMethod(() => DateTime.UtcNow.ToString("R"), "GetCurrentUtcDateTime", "Retrieves the current date time in UTC."), | ||
kernel.CreateFunctionFromMethod((string cityName, string currentDateTime) => | ||
cityName switch | ||
{ | ||
"Boston" => "61 and rainy", | ||
"London" => "55 and cloudy", | ||
"Miami" => "80 and sunny", | ||
"Paris" => "60 and rainy", | ||
"Tokyo" => "50 and sunny", | ||
"Sydney" => "75 and sunny", | ||
"Tel Aviv" => "80 and sunny", | ||
_ => "31 and snowing", | ||
}, "GetWeatherForCity", "Gets the current weather for the specified city"), | ||
]); | ||
|
||
return kernel; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
dotnet/samples/Concepts/Memory/OpenAI_EmbeddingGeneration.cs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.Embeddings; | ||
using xRetry; | ||
|
||
#pragma warning disable format // Format item can be simplified | ||
#pragma warning disable CA1861 // Avoid constant arrays as arguments | ||
|
||
namespace Memory; | ||
|
||
// The following example shows how to use Semantic Kernel with OpenAI. | ||
public class OpenAI_EmbeddingGeneration(ITestOutputHelper output) : BaseTest(output) | ||
{ | ||
[RetryFact(typeof(HttpOperationException))] | ||
public async Task RunEmbeddingAsync() | ||
{ | ||
Assert.NotNull(TestConfiguration.OpenAI.EmbeddingModelId); | ||
Assert.NotNull(TestConfiguration.OpenAI.ApiKey); | ||
|
||
IKernelBuilder kernelBuilder = Kernel.CreateBuilder(); | ||
kernelBuilder.AddOpenAITextEmbeddingGeneration( | ||
modelId: TestConfiguration.OpenAI.EmbeddingModelId!, | ||
apiKey: TestConfiguration.OpenAI.ApiKey!); | ||
Kernel kernel = kernelBuilder.Build(); | ||
|
||
var embeddingGenerator = kernel.GetRequiredService<ITextEmbeddingGenerationService>(); | ||
|
||
// Generate embeddings for the specified text. | ||
var embeddings = await embeddingGenerator.GenerateEmbeddingsAsync(["Semantic Kernel is a lightweight, open-source development kit that lets you easily build AI agents and integrate the latest AI models into your C#, Python, or Java codebase."]); | ||
|
||
Console.WriteLine($"Generated {embeddings.Count} embeddings for the provided text"); | ||
} | ||
} |
Oops, something went wrong.