-
Notifications
You must be signed in to change notification settings - Fork 5
/
OnnxRuntimeGenAIKernelBuilderExtensions.cs
32 lines (29 loc) · 1.23 KB
/
OnnxRuntimeGenAIKernelBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel.ChatCompletion;
using philabs.SemanticKernel.Connectors.OnnxRuntimeGenAI;
namespace Microsoft.SemanticKernel;
/// <summary>
/// Extension methods for adding OnnxRuntimeGenAI Text Generation service to the kernel builder.
/// </summary>
public static class OnnxRuntimeGenAIKernelBuilderExtensions
{
/// <summary>
/// Add OnnxRuntimeGenAI Chat Completion services to the kernel builder.
/// </summary>
/// <param name="builder">The kernel builder.</param>
/// <param name="modelPath">The generative AI ONNX model path.</param>
/// <param name="serviceId">The optional service ID.</param>
/// <returns>The updated kernel builder.</returns>
public static IKernelBuilder AddOnnxRuntimeGenAIChatCompletion(
this IKernelBuilder builder,
string modelPath,
string? serviceId = null)
{
builder.Services.AddKeyedSingleton<IChatCompletionService>(serviceId, (serviceProvider, _) =>
new OnnxRuntimeGenAIChatCompletionService(
modelPath: modelPath,
loggerFactory: serviceProvider.GetService<ILoggerFactory>()));
return builder;
}
}