-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '10fa20b8bc2c1e35e4776bf7d88fa99701ac66e0'
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
SemanticKernelSamples/BemjawhufawJairkihawyawkerene/BemjawhufawJairkihawyawkerene.csproj
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Microsoft.ML.OnnxRuntimeGenAI.DirectML" Version="0.2.0-rc7" /> | ||
<PackageReference Include="feiyun0112.SemanticKernel.Connectors.OnnxRuntimeGenAI.DirectML" Version="1.0.0" /> | ||
|
||
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.SemanticKernel" Version="1.13.0" /> | ||
</ItemGroup> | ||
</Project> |
25 changes: 25 additions & 0 deletions
25
SemanticKernelSamples/BemjawhufawJairkihawyawkerene/BemjawhufawJairkihawyawkerene.sln
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.9.34607.119 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BemjawhufawJairkihawyawkerene", "BemjawhufawJairkihawyawkerene.csproj", "{106E7417-736B-416C-B158-0F4F0F0EE295}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{106E7417-736B-416C-B158-0F4F0F0EE295}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{106E7417-736B-416C-B158-0F4F0F0EE295}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{106E7417-736B-416C-B158-0F4F0F0EE295}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{106E7417-736B-416C-B158-0F4F0F0EE295}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2215563E-750D-4320-AD33-AACC36E7D05A} | ||
EndGlobalSection | ||
EndGlobal |
69 changes: 69 additions & 0 deletions
69
SemanticKernelSamples/BemjawhufawJairkihawyawkerene/Program.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,69 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.ML.OnnxRuntimeGenAI; | ||
using Microsoft.SemanticKernel; | ||
using Microsoft.SemanticKernel.ChatCompletion; | ||
|
||
var modelPath = @"C:\lindexi\Phi3\directml-int4-awq-block-128"; | ||
|
||
// create kernel | ||
var builder = Kernel.CreateBuilder(); | ||
//builder.Services.AddSingleton<IChatCompletionService>(new Phi3ChatCompletionService(modelPath)); | ||
builder.AddOnnxRuntimeGenAIChatCompletion(modelPath); | ||
var kernel = builder.Build(); | ||
|
||
// create chat | ||
var chat = kernel.GetRequiredService<IChatCompletionService>(); | ||
var history = new ChatHistory(); | ||
|
||
// run chat | ||
while (true) | ||
{ | ||
Console.Write("Q: "); | ||
var userQ = Console.ReadLine(); | ||
if (string.IsNullOrEmpty(userQ)) | ||
{ | ||
break; | ||
} | ||
history.AddUserMessage(userQ); | ||
|
||
Console.Write($"Phi3: "); | ||
var response = ""; | ||
var result = chat.GetStreamingChatMessageContentsAsync(history); | ||
await foreach (var message in result) | ||
{ | ||
Console.Write(message.Content); | ||
response += message.Content; | ||
} | ||
history.AddAssistantMessage(response); | ||
Console.WriteLine(""); | ||
} | ||
|
||
|
||
class Phi3ChatCompletionService : IChatCompletionService | ||
{ | ||
public Phi3ChatCompletionService(string modelPath) | ||
{ | ||
var model = new Model(modelPath); | ||
var tokenizer = new Tokenizer(model); | ||
|
||
Model = model; | ||
Tokenizer = tokenizer; | ||
} | ||
|
||
public IReadOnlyDictionary<string, object?> Attributes { get; set; } = new Dictionary<string, object?>(); | ||
public Model Model { get; } | ||
public Tokenizer Tokenizer { get; } | ||
|
||
public Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync(ChatHistory chatHistory, PromptExecutionSettings? executionSettings = null, | ||
Kernel? kernel = null, CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public IAsyncEnumerable<StreamingChatMessageContent> GetStreamingChatMessageContentsAsync(ChatHistory chatHistory, | ||
PromptExecutionSettings? executionSettings = null, Kernel? kernel = null, | ||
CancellationToken cancellationToken = new CancellationToken()) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} |