TensorFlow Serving C++ API Documentation
prediction_service_grpc.h
1 /* Copyright 2020 Google Inc. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 #ifndef THIRD_PARTY_TENSORFLOW_SERVING_EXPERIMENTAL_TENSORFLOW_OPS_REMOTE_PREDICT_KERNELS_PREDICTION_SERVICE_GRPC_H_
16 #define THIRD_PARTY_TENSORFLOW_SERVING_EXPERIMENTAL_TENSORFLOW_OPS_REMOTE_PREDICT_KERNELS_PREDICTION_SERVICE_GRPC_H_
17 #include <string>
18 
19 #include "absl/status/status.h"
20 #include "absl/time/time.h"
21 #include "tensorflow/core/platform/statusor.h"
22 #include "tensorflow_serving/apis/prediction_service.grpc.pb.h"
23 
24 namespace tensorflow {
25 namespace serving {
26 
27 // gRPC based communication point with PredictionService.
29  public:
30  // Creates a new instance. Returns an error if the creation fails.
31  static absl::Status Create(const std::string& target_address,
32  std::unique_ptr<PredictionServiceGrpc>* service) {
33  service->reset(new PredictionServiceGrpc(target_address));
34  return ::absl::OkStatus();
35  }
36 
37  StatusOr<::grpc::ClientContext*> CreateRpc(absl::Duration max_rpc_deadline);
38 
39  void Predict(::grpc::ClientContext* rpc, PredictRequest* request,
40  PredictResponse* response,
41  std::function<void(absl::Status status)> callback);
42 
43  private:
44  PredictionServiceGrpc(const std::string& target_address);
45  std::unique_ptr<tensorflow::serving::PredictionService::Stub> stub_;
46 };
47 
48 } // namespace serving
49 } // namespace tensorflow
50 
51 #endif // THIRD_PARTY_TENSORFLOW_SERVING_EXPERIMENTAL_TENSORFLOW_OPS_REMOTE_PREDICT_KERNELS_PREDICTION_SERVICE_GRPC_H_