From 8f15f3a81c3bbbfa2f3fe65f4a9034e76425e693 Mon Sep 17 00:00:00 2001 From: John Oliver <1615532+johnoliver@users.noreply.github.com> Date: Fri, 3 May 2024 18:07:02 +0100 Subject: [PATCH] Java: Removing java samples as we are relocating samples (#6101) ### Motivation and Context ### Description ### Contribution Checklist - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone :smile: --- samples/java/JavaReferenceSkill/.gitignore | 39 ------- samples/java/JavaReferenceSkill/README.md | 23 ---- samples/java/JavaReferenceSkill/pom.xml | 109 ------------------ .../semantickernel/skills/random/Main.java | 28 ----- .../skills/random/RandomActivitySkill.java | 42 ------- .../src/main/proto/activity.proto | 30 ----- .../random/RandomActivitySkillTest.java | 51 -------- 7 files changed, 322 deletions(-) delete mode 100644 samples/java/JavaReferenceSkill/.gitignore delete mode 100644 samples/java/JavaReferenceSkill/README.md delete mode 100644 samples/java/JavaReferenceSkill/pom.xml delete mode 100644 samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/Main.java delete mode 100644 samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/RandomActivitySkill.java delete mode 100644 samples/java/JavaReferenceSkill/src/main/proto/activity.proto delete mode 100644 samples/java/JavaReferenceSkill/src/test/java/com/microsoft/semantickernel/skills/random/RandomActivitySkillTest.java diff --git a/samples/java/JavaReferenceSkill/.gitignore b/samples/java/JavaReferenceSkill/.gitignore deleted file mode 100644 index fc3f89ced5..0000000000 --- a/samples/java/JavaReferenceSkill/.gitignore +++ /dev/null @@ -1,39 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/samples/java/JavaReferenceSkill/README.md b/samples/java/JavaReferenceSkill/README.md deleted file mode 100644 index 8a4306c51b..0000000000 --- a/samples/java/JavaReferenceSkill/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Java Reference Skill gRPC Server -This is a sample Java gRPC server that can be invoked via SK's gRPC client as a Native Skill/Function. The purpose of this project is to demonstrate how Polyglot skills can be supported using either REST or gRPC. - -## Prerequisites -* Java 17 -* Maven - -## Build -To build the project, run the following command: -``` -mvn clean package -``` -To generate the gRPC classes, run the following command: -``` -mvn protobuf:compile -``` - -## Run -To run the project, run the following command: -``` -java -jar ./target/JavaReferenceSkill-1.0-SNAPSHOT-jar-with-dependencies.jar -``` - diff --git a/samples/java/JavaReferenceSkill/pom.xml b/samples/java/JavaReferenceSkill/pom.xml deleted file mode 100644 index 0ea2afe1c8..0000000000 --- a/samples/java/JavaReferenceSkill/pom.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - 4.0.0 - - com.microsoft.semantic-kernel.skills.random - JavaReferenceSkill - 1.0-SNAPSHOT - - - 17 - 17 - UTF-8 - 1.54.0 - 1.2 - 1.7.1 - 0.6.1 - 3.22.2 - 5.2.0 - - - - - io.grpc - grpc-protobuf - ${grpc.version} - - - io.grpc - grpc-stub - ${grpc.version} - - - io.grpc - grpc-testing - ${grpc.version} - - - io.grpc - grpc-netty-shaded - ${grpc.version} - - - org.mockito - mockito-core - ${mockito-core.version} - - - javax.annotation - javax.annotation-api - ${javax.annotation-api.version} - - - - - - - kr.motd.maven - os-maven-plugin - ${os-maven-plugin.version} - - - - - org.xolstice.maven.plugins - protobuf-maven-plugin - ${protobuf-maven-plugin.version} - - com.google.protobuf:protoc:${protoc.version}:exe:${os.detected.classifier} - grpc-java - io.grpc:protoc-gen-grpc-java:${grpc.version}:exe:${os.detected.classifier} - - - - - compile - compile-custom - - - - - - org.apache.maven.plugins - maven-assembly-plugin - - - jar-with-dependencies - - - - com.microsoft.semantickernel.skills.random.Main - - - - - - make-assembly - package - - single - - - - - - - - \ No newline at end of file diff --git a/samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/Main.java b/samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/Main.java deleted file mode 100644 index 6719a9aefb..0000000000 --- a/samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/Main.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.microsoft.semantickernel.skills.random; - -import io.grpc.Server; -import io.grpc.ServerBuilder; - -import java.util.logging.Logger; - -public class Main { - - private static final int PORT = 50051; - - public static void main(String[] args) { - Logger logger = java.util.logging.Logger.getLogger(Main.class.getName()); - - Server server = ServerBuilder.forPort(PORT) - .addService(new RandomActivitySkill()).build(); - - System.out.println("Starting server..."); - try { - server.start(); - System.out.println("gRPC Server for random activity started on port " + PORT); - server.awaitTermination(); - } catch (Exception e) { - logger.severe("Error with request: " + e.getMessage()); - throw new RuntimeException(e); - } - } -} \ No newline at end of file diff --git a/samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/RandomActivitySkill.java b/samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/RandomActivitySkill.java deleted file mode 100644 index 7036a2dc89..0000000000 --- a/samples/java/JavaReferenceSkill/src/main/java/com/microsoft/semantickernel/skills/random/RandomActivitySkill.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.microsoft.semantickernel.skills.random; - -import io.grpc.stub.StreamObserver; -import reference_skill.ActivityOuterClass; -import reference_skill.RandomActivitySkillGrpc; - -import java.net.URI; -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.util.concurrent.CompletableFuture; -import java.util.logging.Logger; - -public class RandomActivitySkill extends RandomActivitySkillGrpc.RandomActivitySkillImplBase { - - public static final String API_ACTIVITY_URL = "https://www.boredapi.com/api/activity"; - - /** - *
-     * GetRandomActivity is an RPC method that retrieves a random activity from an API.
-     * 
- * - * @param request - * @param responseObserver - */ - @Override - public void getRandomActivity(ActivityOuterClass.GetRandomActivityRequest request, StreamObserver responseObserver) { - Logger logger = java.util.logging.Logger.getLogger(this.getClass().getName()); - HttpClient httpClient = HttpClient.newHttpClient(); - HttpRequest httpRequest = HttpRequest.newBuilder() - .uri(URI.create(API_ACTIVITY_URL)) - .build(); - try { - CompletableFuture> response = httpClient.sendAsync(httpRequest, HttpResponse.BodyHandlers.ofString()); - logger.info("Response: " + response.get().body()); - responseObserver.onNext(ActivityOuterClass.GetRandomActivityResponse.newBuilder().setActivity(response.get().body()).build()); - responseObserver.onCompleted(); - } catch (Exception e) { - logger.severe("Error with request: " + e.getMessage()); - } - } -} diff --git a/samples/java/JavaReferenceSkill/src/main/proto/activity.proto b/samples/java/JavaReferenceSkill/src/main/proto/activity.proto deleted file mode 100644 index ac09fb2b67..0000000000 --- a/samples/java/JavaReferenceSkill/src/main/proto/activity.proto +++ /dev/null @@ -1,30 +0,0 @@ -syntax = "proto3"; - -package reference_skill; - -// GetRandomActivityRequest is a message that contains input for the GetRandomActivity RPC method. -message GetRandomActivityRequest { - string input = 1; // Input is a hobby that is use to generate a random activity. -} - -// GetRandomActivityResponse is a message that contains the activity returned by the GetRandomActivity RPC method. -message GetRandomActivityResponse { - string activity = 1; // Activity is a description of the random activity. -} - -// RandomActivitySkill is a service that provides methods related to random activities. -service RandomActivitySkill { - // GetRandomActivity is an RPC method that retrieves a random activity from an API. - rpc GetRandomActivity (GetRandomActivityRequest) returns (GetRandomActivityResponse); -} - -// Activity is a message that represents an activity with its various properties. -message Activity { - string activity = 1; // A description of the activity. - string type = 2; // The type or category of the activity. - int32 participants = 3; // The number of participants required for the activity. - double price = 4; // The cost associated with the activity, from 0 (free) to 1 (most expensive). - string link = 5; // A URL providing more information about the activity. - string key = 6; // A unique identifier for the activity. - float accessibility = 7; // The accessibility of the activity, from 0 (most accessible) to 1 (least accessible). -} diff --git a/samples/java/JavaReferenceSkill/src/test/java/com/microsoft/semantickernel/skills/random/RandomActivitySkillTest.java b/samples/java/JavaReferenceSkill/src/test/java/com/microsoft/semantickernel/skills/random/RandomActivitySkillTest.java deleted file mode 100644 index fdc8f7268e..0000000000 --- a/samples/java/JavaReferenceSkill/src/test/java/com/microsoft/semantickernel/skills/random/RandomActivitySkillTest.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.microsoft.semantickernel.skills.random; - -import io.grpc.stub.StreamObserver; -import io.grpc.testing.GrpcServerRule; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import reference_skill.ActivityOuterClass; -import reference_skill.RandomActivitySkillGrpc; - -import java.net.http.HttpClient; -import java.net.http.HttpRequest; -import java.net.http.HttpResponse; -import java.util.concurrent.CompletableFuture; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.*; - -public class RandomActivitySkillTest { - - @Rule - public GrpcServerRule grpcServerRule = new GrpcServerRule().directExecutor(); - - private RandomActivitySkillGrpc.RandomActivitySkillBlockingStub blockingStub; - - @Before - public void setUp() { - grpcServerRule.getServiceRegistry().addService(new RandomActivitySkill()); - blockingStub = RandomActivitySkillGrpc.newBlockingStub(grpcServerRule.getChannel()); - } - - @Test - public void testGetRandomActivity() throws Exception { - HttpClient httpClient = mock(HttpClient.class); - HttpResponse httpResponse = mock(HttpResponse.class); - CompletableFuture> responseFuture = CompletableFuture.completedFuture(httpResponse); - - when(httpClient.sendAsync(any(HttpRequest.class), any(HttpResponse.BodyHandler.class))).thenReturn(responseFuture); - when(httpResponse.body()).thenReturn("{\"activity\":\"Test Activity\"}"); - - RandomActivitySkill randomActivitySkill = new RandomActivitySkill() { - }; - - ActivityOuterClass.GetRandomActivityRequest request = ActivityOuterClass.GetRandomActivityRequest.newBuilder().build(); - StreamObserver responseObserver = mock(StreamObserver.class); - randomActivitySkill.getRandomActivity(request, responseObserver); - - verify(responseObserver).onNext(any(ActivityOuterClass.GetRandomActivityResponse.class)); - verify(responseObserver).onCompleted(); - } -}