mirror of
https://github.com/microsoft/semantic-kernel.git
synced 2026-10-12 02:19:06 +00:00
### Motivation and Context This PR adds MVP functionality for gRPC skills by introducing a set of classes for importing, parsing and executing gRPC operations defined in the .proto files. This functionality may be useful in scenarios when skills are represented as methods that are hosted on a different machine and need to be called remotely. ### Description The PR adds the following classes: - ProtoDocumentParser - iterates over a all methods of all services declared in .proto file and creates an instance of GrpcOperation model class for each of them. - GrpcOperation - model class representing gRPC operation. - GrpcOperationRunner - accepts an instance of the GrpcOperation class and a collection of arguments. Dynamically creates an instance of gRPC method request and calls the method. Receives, transforms and returns the method call result. - GrpcOperationExtensions - extension methods for GrpcOperation to extend the class with SK SDK domain related functionality. - KernelGrpcExtensions - declares a few register and import methods for importing the gRPC skills from a folder or a file and registering them in SK Kernel. Co-authored-by: Shawn Callegari <[email protected]> Co-authored-by: Govind Kamtamneni <[email protected]>
36 lines
1.2 KiB
C#
36 lines
1.2 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
|
|
using System;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.SemanticKernel;
|
|
using Microsoft.SemanticKernel.Orchestration;
|
|
using Microsoft.SemanticKernel.Skills.Grpc.Extensions;
|
|
using RepoUtils;
|
|
|
|
/**
|
|
* This example shows how to use gRPC skills.
|
|
*/
|
|
|
|
public static class Example35_GrpcSkills
|
|
{
|
|
public static async Task RunAsync()
|
|
{
|
|
var kernel = new KernelBuilder().WithLogger(ConsoleLogger.Log).Build();
|
|
|
|
// Import a gRPC skill using one of the following Kernel extension methods
|
|
// kernel.RegisterGrpcSkill
|
|
// kernel.ImportGrpcSkillFromDirectory
|
|
var skill = kernel.ImportGrpcSkillFromFile("<skill-name>", "<path-to-.proto-file>");
|
|
|
|
// Add arguments for required parameters, arguments for optional ones can be skipped.
|
|
var contextVariables = new ContextVariables();
|
|
contextVariables.Set("address", "<gRPC-server-address>");
|
|
contextVariables.Set("payload", "<gRPC-request-message-as-json>");
|
|
|
|
// Run
|
|
var result = await kernel.RunAsync(contextVariables, skill["<operation-name>"]);
|
|
|
|
Console.WriteLine("Skill response: {0}", result);
|
|
}
|
|
}
|