Skip to content
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

Update to latest SK and fix issues #155

Merged
merged 9 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 10 additions & 32 deletions .ado/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,29 @@ parameters:
- Name: win_x64
VMImage: windows-latest
TargetRuntime: win-x64
DotNetVersion: 8.0.x
DotNetMoniker: net8.0
UseGlobalJson: true
- Name: win_arm64
VMImage: windows-latest
TargetRuntime: win-arm64
DotNetVersion: 8.0.x
DotNetMoniker: net8.0
UseGlobalJson: true
- Name: osx_x64
VMImage: macos-latest
TargetRuntime: osx-x64
DotNetVersion: 8.0.x
DotNetMoniker: net8.0
UseGlobalJson: true
- Name: osx_arm64
VMImage: macos-latest
TargetRuntime: osx-arm64
DotNetVersion: 8.0.x
DotNetMoniker: net8.0
UseGlobalJson: true
- Name: linux_x64
VMImage: ubuntu-latest
TargetRuntime: linux-x64
DotNetVersion: 8.0.x
DotNetMoniker: net8.0
UseGlobalJson: true

jobs:
# Build Native AOT .Net hosts for Node-API modules.
- ${{ each matrixEntry in parameters.buildMatrix }}:
- job: buildAOTBinary${{ matrixEntry.Name }}
displayName: Build ${{ matrixEntry.TargetRuntime }} AOT binary

variables:
DotNetMoniker: net8.0

pool:
vmImage: ${{ matrixEntry.VMImage }}

Expand All @@ -69,40 +58,32 @@ jobs:
lfs: false

- task: UseDotNet@2
displayName: Install .Net ${{ matrixEntry.DotNetVersion }}
displayName: Install .NET SDK using global.json
inputs:
packageType: sdk
version: ${{ matrixEntry.DotNetVersion }}
includePreviewVersions: ${{ eq(matrixEntry.UseGlobalJson, false) }}
useGlobalJson: ${{ matrixEntry.UseGlobalJson }}
useGlobalJson: true

- script: env
displayName: Print environment

- script: dotnet --info
displayName: Print .Net info

- task: DeleteFiles@1 # To enable net8.0 use for osx-arm64
displayName: Delete global.json
inputs:
Contents: global.json
condition: eq(${{ matrixEntry.UseGlobalJson }}, false)

- script: >
dotnet publish
--configuration Release
--runtime ${{ matrixEntry.TargetRuntime }}
--no-self-contained
--framework ${{ matrixEntry.DotNetMoniker }}
--framework $(DotNetMoniker)
displayName: Build Native AOT binaries
env:
TargetFrameworks: ${{ matrixEntry.DotNetMoniker }}
TargetFrameworks: $(DotNetMoniker)

- task: CopyFiles@2
displayName: Copy Native AOT binaries to staging
inputs:
sourceFolder: "$(Build.SourcesDirectory)/out/bin/Release/NodeApi/\
${{ matrixEntry.DotNetMoniker }}/${{ matrixEntry.TargetRuntime }}/publish"
$(DotNetMoniker)/${{ matrixEntry.TargetRuntime }}/publish"
targetFolder: $(Build.StagingDirectory)/AOT/${{ matrixEntry.TargetRuntime }}
contents: Microsoft.JavaScript.NodeApi.node

Expand All @@ -126,9 +107,7 @@ jobs:
variables:
VMImage: windows-latest
TargetRuntime: win-x64
DotNetVersion: 8.0.x
DotNetMoniker: net8.0
UseGlobalJson: true
TargetRuntimeList:

pool:
Expand All @@ -149,11 +128,10 @@ jobs:
version: 6.0.x

- task: UseDotNet@2
displayName: Install .Net $(DotNetVersion)
displayName: Install .NET SDK using global.json
inputs:
packageType: sdk
version: $(DotNetVersion)
useGlobalJson: $(UseGlobalJson)
useGlobalJson: true

- script: env
displayName: Print environment
Expand Down
10 changes: 0 additions & 10 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,5 @@
<NetFramework>false</NetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" />
<!-- All projects need to be rebuilt if the version changes. -->
<Content Include="$(MSBuildThisFileDirectory)version.json" Link="version.json">
<CopyToOutputDirectory>DoNotCopy</CopyToOutputDirectory>
<Visible>false</Visible><!-- Hide from VS solution explorer -->
<Pack>false</Pack> <!--Exclude from NuGet packages -->
</Content>
</ItemGroup>

<Import Project="./rid.props" />
</Project>
32 changes: 20 additions & 12 deletions examples/semantic-kernel/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,41 @@ import dotnet from 'node-api-dotnet';
import './bin/Microsoft.SemanticKernel.Core.js';
import './bin/Microsoft.SemanticKernel.Connectors.AI.OpenAI.js';

// The PromptTemplateEngine assembly must be explicitly loaded here, because
// SK KernelBuilder uses Assembly.Load() to load it, and that is not detected
// by the JS exporter.
import './bin/Microsoft.SemanticKernel.TemplateEngine.PromptTemplateEngine.js';

const SK = dotnet.Microsoft.SemanticKernel;
const Logging = dotnet.Microsoft.Extensions.Logging;

/** @type {dotnet.Microsoft.Extensions.Logging.ILogger} */
const logger = {
Log(logLevel, eventId, state, exception, formatter) {
console.log(`LOG (${Logging.LogLevel[logLevel]}): ${formatter(state, exception)}`);
console.log(`LOG (${Logging.LogLevel[logLevel || 0]}): ${formatter(state, exception)}`);
},
IsEnabled(logLevel) { return true; },
BeginScope(state) { return { dispose() { } }; },
};

const kernel = SK.Kernel.Builder
.WithLogger(logger)
.Build();
/** @type {dotnet.Microsoft.Extensions.Logging.ILoggerFactory} */
const loggerFactory = {
CreateLogger(categoryName) { return logger; },
AddProvider(provider) { },
dispose() {}
};

// The JS marshaller does not yet support extension methods.
SK.KernelConfigOpenAIExtensions.AddAzureTextCompletionService(
kernel.Config,
const kernelBuilder = SK.OpenAIKernelBuilderExtensions.WithAzureChatCompletionService(
SK.Kernel.Builder.WithLoggerFactory(loggerFactory),
process.env['OPENAI_DEPLOYMENT'] || '',
process.env['OPENAI_ENDPOINT'] || '',
process.env['OPENAI_KEY'] || '',
);
const kernel = kernelBuilder.Build();

const skPrompt = `
{{$input}}
const skPrompt = `{{$input}}

Give me the TLDR in 5 words.
Give me the TLDR in 10 words.
`;

const textToSummarize = `
Expand All @@ -49,8 +56,9 @@ does not conflict with the First or Second Law.
`;

// The JS marshaller does not yet support extension methods.
const tldrFunction = SK.InlineFunctionsDefinitionExtension
const summaryFunction = SK.InlineFunctionsDefinitionExtension
.CreateSemanticFunction(kernel, skPrompt);

const summary = await tldrFunction.InvokeAsync(textToSummarize);
const summary = await SK.SKFunctionExtensions.InvokeAsync(summaryFunction, textToSummarize);

console.log(summary.toString());
2 changes: 1 addition & 1 deletion examples/semantic-kernel/semantic-kernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SemanticKernel" Version="0.14.547.1-preview" />
<PackageReference Include="Microsoft.SemanticKernel" Version="0.24.230918.1-preview" />
<PackageReference Include="Microsoft.JavaScript.NodeApi.Generator" Version="0.4.*-*" />
</ItemGroup>

Expand Down
14 changes: 14 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>
<Import Project="../Directory.Build.props" />

<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="all" />
<!-- All projects need to be rebuilt if the version changes. -->
<Content Include="$(MSBuildThisFileDirectory)version.json" Link="version.json">
<CopyToOutputDirectory>DoNotCopy</CopyToOutputDirectory>
<Visible>false</Visible><!-- Hide from VS solution explorer -->
<Pack>false</Pack> <!--Exclude from NuGet packages -->
</Content>
</ItemGroup>

</Project>
Loading