public async stt::Task ExplainResourceNamesAsync()
        {
            moq::Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new moq::Mock <PredictionService.PredictionServiceClient>(moq::MockBehavior.Strict);
            ExplainRequest request = new ExplainRequest
            {
                EndpointAsEndpointName = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]"),
                Instances       = { new wkt::Value(), },
                DeployedModelId = "deployed_model_idf0bd41af",
                Parameters      = new wkt::Value(),
            };
            ExplainResponse expectedResponse = new ExplainResponse
            {
                Explanations    = { new Explanation(), },
                DeployedModelId = "deployed_model_idf0bd41af",
                Predictions     = { new wkt::Value(), },
            };

            mockGrpcClient.Setup(x => x.ExplainAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <ExplainResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
            PredictionServiceClient client = new PredictionServiceClientImpl(mockGrpcClient.Object, null);
            ExplainResponse         responseCallSettings = await client.ExplainAsync(request.EndpointAsEndpointName, request.Instances, request.Parameters, request.DeployedModelId, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));

            xunit::Assert.Same(expectedResponse, responseCallSettings);
            ExplainResponse responseCancellationToken = await client.ExplainAsync(request.EndpointAsEndpointName, request.Instances, request.Parameters, request.DeployedModelId, st::CancellationToken.None);

            xunit::Assert.Same(expectedResponse, responseCancellationToken);
            mockGrpcClient.VerifyAll();
        }
 protected override void ExpectResponse(ExplainResponse <Project> response)
 {
     response.IsValid.Should().BeTrue();
     response.Matched.Should().BeTrue();
     response.Get.Should().NotBeNull();
     response.Get.Source.ShouldAdhereToSourceSerializerWhenSet();
 }
        public void ExplainRequestObject()
        {
            moq::Mock <PredictionService.PredictionServiceClient> mockGrpcClient = new moq::Mock <PredictionService.PredictionServiceClient>(moq::MockBehavior.Strict);
            ExplainRequest request = new ExplainRequest
            {
                EndpointAsEndpointName = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]"),
                Instances               = { new wkt::Value(), },
                DeployedModelId         = "deployed_model_idf0bd41af",
                Parameters              = new wkt::Value(),
                ExplanationSpecOverride = new ExplanationSpecOverride(),
            };
            ExplainResponse expectedResponse = new ExplainResponse
            {
                Explanations    = { new Explanation(), },
                DeployedModelId = "deployed_model_idf0bd41af",
                Predictions     = { new wkt::Value(), },
            };

            mockGrpcClient.Setup(x => x.Explain(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(expectedResponse);
            PredictionServiceClient client   = new PredictionServiceClientImpl(mockGrpcClient.Object, null);
            ExplainResponse         response = client.Explain(request);

            xunit::Assert.Same(expectedResponse, response);
            mockGrpcClient.VerifyAll();
        }
Beispiel #4
0
        public async Task IQuery_Explain(string q, ExplainResponse expected)
        {
            using var handler = MockHttpMessageHandler.SetupHandler(expected);
            var api    = handler.SetupApi <IQuery>();
            var result = await api.GetAsync(q, CancellationToken.None, "v44.0");

            result.Should().BeEquivalentTo(expected);
            handler.ConfirmPath("/services/data/v44.0/query?explain=", q);
        }
 /// <summary>Snippet for Explain</summary>
 public void ExplainResourceNames()
 {
     // Snippet: Explain(EndpointName, IEnumerable<Value>, Value, string, CallSettings)
     // Create client
     PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
     // Initialize request argument(s)
     EndpointName        endpoint  = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]");
     IEnumerable <Value> instances = new Value[] { new Value(), };
     Value  parameters             = new Value();
     string deployedModelId        = "";
     // Make the request
     ExplainResponse response = predictionServiceClient.Explain(endpoint, instances, parameters, deployedModelId);
     // End snippet
 }
 /// <summary>Snippet for Explain</summary>
 public void Explain()
 {
     // Snippet: Explain(string, IEnumerable<Value>, Value, string, CallSettings)
     // Create client
     PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
     // Initialize request argument(s)
     string endpoint = "projects/[PROJECT]/locations/[LOCATION]/endpoints/[ENDPOINT]";
     IEnumerable <Value> instances = new Value[] { new Value(), };
     Value  parameters             = new Value();
     string deployedModelId        = "";
     // Make the request
     ExplainResponse response = predictionServiceClient.Explain(endpoint, instances, parameters, deployedModelId);
     // End snippet
 }
 /// <summary>Snippet for Explain</summary>
 public void ExplainRequestObject()
 {
     // Snippet: Explain(ExplainRequest, CallSettings)
     // Create client
     PredictionServiceClient predictionServiceClient = PredictionServiceClient.Create();
     // Initialize request argument(s)
     ExplainRequest request = new ExplainRequest
     {
         EndpointAsEndpointName = EndpointName.FromProjectLocationEndpoint("[PROJECT]", "[LOCATION]", "[ENDPOINT]"),
         Instances               = { new Value(), },
         DeployedModelId         = "",
         Parameters              = new Value(),
         ExplanationSpecOverride = new ExplanationSpecOverride(),
     };
     // Make the request
     ExplainResponse response = predictionServiceClient.Explain(request);
     // End snippet
 }
        public void ExplainWithDocumentIdTest()
        {
            Span span = new Span
            {
                CharacterStart = 1,
                CharacterEnd   = 2,
                Text           = "A"
            };

            List <Span> spans = new List <Span>
            {
                span
            };

            Explanation explanation = new Explanation
            {
                AppliedSpans = spans,
                IgnoredSpans = new List <Span>()
            };

            ExplainResponse mockResponse = new ExplainResponse
            {
                FilteredText = "His SSN was {{{REDACTED-ssn}}}.",
                DocumentId   = "docid",
                Explanation  = explanation
            };

            string json = Newtonsoft.Json.JsonConvert.SerializeObject(mockResponse);

            _simulator.Post("/api/explain").Responds(json).WithCode(200);

            PhilterClient   philterClient   = new PhilterClient(GetClient());
            ExplainResponse explainResponse = philterClient.Explain("His SSN was 123-45-6789.", "context", "docid", "invalid");

            Assert.IsNotNull(explainResponse);
            Assert.AreEqual(1, explainResponse.Explanation.AppliedSpans.Count);
            Assert.AreEqual(0, explainResponse.Explanation.IgnoredSpans.Count);
            Assert.AreEqual("docid", explainResponse.DocumentId);
        }