예제 #1
0
        public async Task PredictAsync()
        {
            Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new Mock <PredictionService.PredictionServiceClient>(MockBehavior.Strict);

            mockGrpcClient.Setup(x => x.CreateOperationsClient())
            .Returns(new Mock <Operations.OperationsClient>().Object);
            PredictRequest expectedRequest = new PredictRequest
            {
                ModelName = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]"),
                Payload   = new ExamplePayload(),
                Params    = { },
            };
            PredictResponse expectedResponse = new PredictResponse();

            mockGrpcClient.Setup(x => x.PredictAsync(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(new Grpc.Core.AsyncUnaryCall <PredictResponse>(Task.FromResult(expectedResponse), null, null, null, null));
            PredictionServiceClient client       = new PredictionServiceClientImpl(mockGrpcClient.Object, null);
            ModelName      name                  = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]");
            ExamplePayload payload               = new ExamplePayload();
            IDictionary <string, string> @params = new Dictionary <string, string>();
            PredictResponse response             = await client.PredictAsync(name, payload, @params);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #2
0
 /// <summary>Snippet for Predict</summary>
 public void Predict()
 {
     // Snippet: Predict(ModelName,ExamplePayload,IDictionary<string, string>,CallSettings)
     // Create client
     PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
     // Initialize request argument(s)
     ModelName      name    = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]");
     ExamplePayload payload = new ExamplePayload();
     IDictionary <string, string> @params = new Dictionary <string, string>();
     // Make the request
     PredictResponse response = predictionServiceClient.Predict(name, payload, @params);
     // End snippet
 }
예제 #3
0
 /// <summary>Snippet for Predict</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void Predict()
 {
     // Create client
     PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
     // Initialize request argument(s)
     string         name    = "projects/[PROJECT]/locations/[LOCATION]/models/[MODEL]";
     ExamplePayload payload = new ExamplePayload();
     IDictionary <string, string> @params = new Dictionary <string, string> {
         { "", "" },
     };
     // Make the request
     PredictResponse response = predictionServiceClient.Predict(name, payload, @params);
 }
 /// <summary>Snippet for Predict</summary>
 /// <remarks>
 /// This snippet has been automatically generated for illustrative purposes only.
 /// It may require modifications to work in your environment.
 /// </remarks>
 public void PredictResourceNames()
 {
     // Create client
     PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
     // Initialize request argument(s)
     ModelName      name    = ModelName.FromProjectLocationModel("[PROJECT]", "[LOCATION]", "[MODEL]");
     ExamplePayload payload = new ExamplePayload();
     IDictionary <string, string> @params = new Dictionary <string, string> {
         { "", "" },
     };
     // Make the request
     PredictResponse response = predictionServiceClient.Predict(name, payload, @params);
 }
예제 #5
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictAsync()
        {
            // Snippet: PredictAsync(ModelName,ExamplePayload,IDictionary<string, string>,CallSettings)
            // Additional: PredictAsync(ModelName,ExamplePayload,IDictionary<string, string>,CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            ModelName      name    = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]");
            ExamplePayload payload = new ExamplePayload();
            IDictionary <string, string> @params = new Dictionary <string, string>();
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(name, payload, @params);

            // End snippet
        }
예제 #6
0
        /// <summary>Snippet for PredictAsync</summary>
        public async Task PredictAsync()
        {
            // Snippet: PredictAsync(string, ExamplePayload, IDictionary<string,string>, CallSettings)
            // Additional: PredictAsync(string, ExamplePayload, IDictionary<string,string>, CancellationToken)
            // Create client
            PredictionServiceClient predictionServiceClient = await PredictionServiceClient.CreateAsync();

            // Initialize request argument(s)
            string         name    = "projects/[PROJECT]/locations/[LOCATION]/models/[MODEL]";
            ExamplePayload payload = new ExamplePayload();
            IDictionary <string, string> @params = new Dictionary <string, string> {
                { "", "" },
            };
            // Make the request
            PredictResponse response = await predictionServiceClient.PredictAsync(name, payload, @params);

            // End snippet
        }
        public void Predict()
        {
            Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new Mock <PredictionService.PredictionServiceClient>(MockBehavior.Strict);
            PredictRequest expectedRequest = new PredictRequest
            {
                ModelName = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]"),
                Payload   = new ExamplePayload(),
                Params    = { },
            };
            PredictResponse expectedResponse = new PredictResponse();

            mockGrpcClient.Setup(x => x.Predict(expectedRequest, It.IsAny <CallOptions>()))
            .Returns(expectedResponse);
            PredictionServiceClient client       = new PredictionServiceClientImpl(mockGrpcClient.Object, null);
            ModelName      name                  = new ModelName("[PROJECT]", "[LOCATION]", "[MODEL]");
            ExamplePayload payload               = new ExamplePayload();
            IDictionary <string, string> @params = new Dictionary <string, string>();
            PredictResponse response             = client.Predict(name, payload, @params);

            Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
예제 #8
0
        private void prediction()
        {
            try
            {
                ExamplePayload payload = new ExamplePayload()
                {
                    //TextSnippet = new TextSnippet()
                    //{
                    //    Content = "{\"payload\":{\"row\":{\"values\":[\"3795.67486950037\",\"0.0\",\"30.0\"]}}}"
                    //}
                };


                PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();

                PredictRequest request = new PredictRequest
                {
                    ModelName = ModelName.FromProjectLocationModel("thermal-creek-272919", "us-central1", "TBL5828849788421931008"),
                    Payload   = payload,
                    //model_path = client.model_path('thermal-creek-272919', 'us-central1', 'TBL5828849788421931008')

                    Params = { { "feature_importance", "false" } },
                };

                var response = predictionServiceClient.Predict(request);
            }
            catch (Exception ex)
            {
                throw;
            }
            //mockGrpcClient.Setup(x => x.Predict(request, moq::It.IsAny<grpccore::CallOptions>())).Returns(expectedResponse);

            //PredictionServiceClient client = new PredictionServiceClientImpl(mockGrpcClient.Object, null);

            //PredictResponse response = client.Predict(request);
        }