Skip to content

Commit

Permalink
.Net: Update samples to use SK 0.18 (microsoft#2255)
Browse files Browse the repository at this point in the history
### Motivation and Context
Time marches on,

### Description
Updated samples to use SK 0.18 and modified code when necessary due to
that upgrade.

### Contribution Checklist
- [ ] 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 😄
  • Loading branch information
glahaye authored Aug 2, 2023
1 parent bfb8b9c commit 738360a
Show file tree
Hide file tree
Showing 20 changed files with 30 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.Planning.Sequential;
using Microsoft.SemanticKernel.Skills.Core;
using RepoUtils;

Expand Down Expand Up @@ -138,8 +137,7 @@ which are not grounded in the original.

kernel.ImportSkill(new TextSkill());

var plannerConfig = new SequentialPlannerConfig { };
var planner = new SequentialPlanner(kernel, plannerConfig);
var planner = new SequentialPlanner(kernel);
var plan = await planner.CreatePlanAsync(ask);
Console.WriteLine(plan.ToPlanWithGoalString());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Memory;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.Planning;
using Microsoft.SemanticKernel.Planning.Sequential;
Expand All @@ -26,18 +25,15 @@ public SequentialPlanParserTests(ITestOutputHelper testOutputHelper)
}

private Mock<IKernel> CreateKernelMock(
out Mock<ISemanticTextMemory> semanticMemoryMock,
out Mock<IReadOnlySkillCollection> mockSkillCollection,
out Mock<ILogger> mockLogger)
{
semanticMemoryMock = new Mock<ISemanticTextMemory>();
mockSkillCollection = new Mock<IReadOnlySkillCollection>();
mockLogger = new Mock<ILogger>();

var kernelMock = new Mock<IKernel>();
kernelMock.SetupGet(k => k.Skills).Returns(mockSkillCollection.Object);
kernelMock.SetupGet(k => k.Logger).Returns(mockLogger.Object);
kernelMock.SetupGet(k => k.Memory).Returns(semanticMemoryMock.Object);

return kernelMock;
}
Expand All @@ -61,7 +57,7 @@ private static Mock<ISKFunction> CreateMockFunction(FunctionView functionView, s
private void CreateKernelAndFunctionCreateMocks(List<(string name, string skillName, string description, bool isSemantic, string result)> functions,
out IKernel kernel)
{
var kernelMock = this.CreateKernelMock(out _, out var skills, out _);
var kernelMock = this.CreateKernelMock(out var skills, out _);
kernel = kernelMock.Object;

// For Create
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ public async Task EmptyGoalThrowsAsync()
{
// Arrange
var kernel = new Mock<IKernel>();
// kernel.Setup(x => x.Logger).Returns(new Mock<ILogger>().Object);

var planner = new Microsoft.SemanticKernel.Planning.SequentialPlanner(kernel.Object);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private static async Task<IEnumerable<FunctionView>> GetRelevantFunctionsAsync(
/// Saves all available functions to memory.
/// </summary>
/// <param name="context">The SKContext to save the functions to.</param>
/// <param name="memory">The memory provide to store the functions to..</param>
/// <param name="memory">The memory provided to store the functions to.</param>
/// <param name="availableFunctions">The available functions to save.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> to monitor for cancellation requests. The default is <see cref="CancellationToken.None"/>.</param>
internal static async Task RememberFunctionsAsync(
Expand Down
2 changes: 1 addition & 1 deletion samples/dotnet/KernelHttpServer/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal static void RegisterNativeGraphSkills(this IKernel kernel, string graph

internal static void RegisterTextMemory(this IKernel kernel)
{
_ = kernel.ImportSkill(new TextMemorySkill(), nameof(TextMemorySkill));
_ = kernel.ImportSkill(new TextMemorySkill(kernel.Memory), nameof(TextMemorySkill));
}

[SuppressMessage("Reliability", "CA2000:Dispose objects before losing scope",
Expand Down
8 changes: 4 additions & 4 deletions samples/dotnet/KernelHttpServer/KernelHttpServer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.13.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.18.0" />
<PackageReference Include="Microsoft.Graph" Version="4.54.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.Document" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.MsGraph" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.Web" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.18.230725.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.Document" Version="0.18.230725.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.MsGraph" Version="0.18.230725.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.Web" Version="0.18.230725.3-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/dotnet/graph-api-skills/MsGraphSkillsExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.MsGraph" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.MsGraph" Version="0.18.230725.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.18.230725.3-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions samples/dotnet/openapi-skills/OpenApiSkillsExample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.OpenAPI" Version="0.17.230704.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.18.230725.3-preview" />
<PackageReference Include="Microsoft.SemanticKernel.Skills.OpenAPI" Version="0.18.230725.3-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions samples/dotnet/openapi-skills/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Open API Skills Example
The chat example below is meant to demonstrate the use of an OpenAPI-based skill (e.g., GitHub), a planner (e.g., ActionPlanner) and chat completions to create a conversational experience with additional information from a skill when needed.
The chat example below is meant to demonstrate the use of an OpenAPI-based skill (e.g., GitHub), a planner (e.g., ActionPlanner)
and chat completions to create a conversational experience with additional information from a skill when needed.

The GitHub OpenAPI specific used is a reduced definition supporting viewing of pull requests.
The specific GitHub OpenAPI used is a reduced definition supporting viewing of pull requests.

## Preparing your environment
Before you get started, make sure you have the following requirements in place:
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/00-getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"outputs": [],
"source": [
"// Import Semantic Kernel\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\""
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\""
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/01-basic-loading-the-kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\""
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\""
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/03-semantic-function-inline.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/04-context-variables-chat.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"#!import config/Settings.cs\n",
"\n",
"using Microsoft.SemanticKernel;\n",
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/05-using-the-planner.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"#!import config/Utils.cs\n",
Expand Down
4 changes: 2 additions & 2 deletions samples/notebooks/dotnet/06-memory-and-embeddings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"#r \"nuget: System.Linq.Async, 6.0.1\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down Expand Up @@ -216,7 +216,7 @@
"using Microsoft.SemanticKernel.Skills.Core;\n",
"\n",
"// TextMemorySkill provides the \"recall\" function\n",
"kernel.ImportSkill(new TextMemorySkill());"
"kernel.ImportSkill(new TextMemorySkill(kernel.Memory));"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/07-DALL-E-2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"source": [
"// Usual setup: importing Semantic Kernel SDK and SkiaSharp, used to display images inline.\n",
"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"#r \"nuget: SkiaSharp, 2.88.3\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down
2 changes: 1 addition & 1 deletion samples/notebooks/dotnet/08-chatGPT-with-DALL-E-2.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"source": [
"// Usual setup: importing Semantic Kernel SDK and SkiaSharp, used to display images inline.\n",
"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"#r \"nuget: SkiaSharp, 2.88.3\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down
6 changes: 3 additions & 3 deletions samples/notebooks/dotnet/09-memory-with-chroma.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
{
"data": {
"text/html": [
"<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.SemanticKernel, 0.17.230629.1-preview</span></li><li><span>Microsoft.SemanticKernel.Connectors.Memory.Chroma, 0.17.230629.1-preview</span></li><li><span>System.Linq.Async, 6.0.1</span></li></ul></div></div>"
"<div><div></div><div></div><div><strong>Installed Packages</strong><ul><li><span>Microsoft.SemanticKernel, 0.18.230725.3-preview</span></li><li><span>Microsoft.SemanticKernel.Connectors.Memory.Chroma, 0.18.230725.3-preview</span></li><li><span>System.Linq.Async, 6.0.1</span></li></ul></div></div>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230629.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Connectors.Memory.Chroma, 0.17.230629.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Connectors.Memory.Chroma, 0.18.230725.3-preview\"\n",
"#r \"nuget: System.Linq.Async, 6.0.1\"\n",
"\n",
"#!import config/Settings.cs\n",
Expand Down
4 changes: 2 additions & 2 deletions samples/notebooks/dotnet/10-BingSearch-using-kernel.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
},
"outputs": [],
"source": [
"#r \"nuget: Microsoft.SemanticKernel, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Skills.Web, 0.17.230626.1-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel, 0.18.230725.3-preview\"\n",
"#r \"nuget: Microsoft.SemanticKernel.Skills.Web, 0.18.230725.3-preview\"\n",
"\n",
"#!import config/Settings.cs\n",
"#!import config/Utils.cs\n",
Expand Down

0 comments on commit 738360a

Please sign in to comment.