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

gRPC skills functionality #814

Merged
merged 10 commits into from May 8, 2023
Merged

gRPC skills functionality #814

merged 10 commits into from May 8, 2023

Conversation

SergeyMenshykh
Copy link
Member

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.

Contribution Checklist

SergeyMenshykh and others added 5 commits April 26, 2023 18:10
### Motivation and Context

This PR adds a few building blocks for gRPC skills support. The rest of
the functionality - gRPC skills import, support for complex data
contract, retries, etc. will/might be added later.

### Description
This PR add the following classes/components:
- Skills.Grpc - project/package added to keep gRPC related
functionality.
- ProtoDocumentParser - class responsible for parsing .ptoto files and
extract them into a list of operations represented by GrpcOperation
class.
- GrpcOperation - model class that describes a gRPC operation.
- GrpcOperationRunner - class responsible for running a gRPC operation.

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

---------

Co-authored-by: Shawn Callegari <36091529+shawncal@users.noreply.github.com>
### Motivation and Context

This change adds functionality required for gRPC skills import to Kernel
allowing SK SDK client code to register and use gRPC skills in SK SDK.

### Description
This change adds a few ImportGrpc* Kernel extension methods that can
import gRPC skills from a folder or a file. Additionality,
GrpcOperationRunner is changed to accept gRPC request message as JSON
and return the gRPC method result as JSON as well.

### Contribution Checklist
<!-- Before submitting this PR, please make sure: -->
- [x] The code builds clean without any errors or warnings
- [x] The PR follows SK Contribution Guidelines
(https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
- [x] The code follows the .NET coding conventions
(https://learn.microsoft.com/dotnet/csharp/fundamentals/coding-style/coding-conventions)
verified with `dotnet format`
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄
…) with a sample proto file (#768)

### Motivation and Context
This is related to #451,
craigomatic#13, and
craigomatic#16, where we want to
demonstrate how Native skills can be invoked via gRPC and implemented
across various languages. In this case, we are specifically implementing
this polyglot Native skill in Java due to customer inquiries.


### Description
This change introduces a sample Java application that functions as a
gRPC server. The `GrpcOperationRunner` can invoke Java code using the
[activity.proto file in this
PR](https://github.com/thegovind/semantic-kernel/blob/feature-grpc/samples/java/JavaReferenceSkill/src/main/proto/activity.proto)
and its operation `GetRandomActivity`, as shown in
[`Example27_GrpcSkills` in
`kernel-syntax-examples`](https://github.com/microsoft/semantic-kernel/pull/730/files#diff-29f0ad84e48c3fe28f2ad26603940927306a57aaf76f6c01fc19e7ac82e33da0).
@github-actions github-actions bot added .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel kernel.core labels May 4, 2023
@SergeyMenshykh SergeyMenshykh added PR: ready for review All feedback addressed, ready for reviews .NET Issue or Pull requests regarding .NET code and removed .NET Issue or Pull requests regarding .NET code kernel Issues or pull requests impacting the core kernel samples labels May 4, 2023
…h with the main one. (#816)

### Motivation and Context

Fix for the latest, partially successful, merge of gRPC feature branch
with the main one.
@github-actions github-actions bot added kernel Issues or pull requests impacting the core kernel kernel.core labels May 4, 2023
Copy link
Member

@lemillermicrosoft lemillermicrosoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick pass

dotnet/Directory.Packages.props Outdated Show resolved Hide resolved
dotnet/src/SemanticKernel/SemanticKernel.csproj Outdated Show resolved Hide resolved
SergeyMenshykh and others added 3 commits May 5, 2023 19:49
### Description

This PR addresses comments made in another PR to merge feature-grpc
branch to the main one. It also contains a small improvement that
prevents creation of HttpClient per each gRPC operation run and use only
one HttpClient instance per set of skills imported together. Later, in
scope of a different task, another improvement will be done to allow
hosting apps to provide their instances of HttpClient, if needed.
@shawncal shawncal merged commit 972d878 into main May 8, 2023
16 checks passed
@@ -38,8 +34,10 @@
<PackageVersion Include="Microsoft.Identity.Client.Extensions.Msal" Version="[2.28.0, )" />
<PackageVersion Include="Microsoft.OpenApi" Version="[1.6.3, )" />
<PackageVersion Include="Microsoft.OpenApi.Readers" Version="[1.6.3, )" />
<PackageVersion Include="Newtonsoft.Json" Version="[13.0.3, )" />

<PackageVersion Include="Newtonsoft.Json" Version="[11.0.1, )" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️

@shawncal shawncal deleted the feature-grpc branch May 17, 2023 22:04
dehoward pushed a commit to lemillermicrosoft/semantic-kernel that referenced this pull request Jun 1, 2023
### 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 <36091529+shawncal@users.noreply.github.com>
Co-authored-by: Govind Kamtamneni <gok@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kernel Issues or pull requests impacting the core kernel .NET Issue or Pull requests regarding .NET code PR: ready for review All feedback addressed, ready for reviews
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants