-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclient.cpp
56 lines (44 loc) · 1.45 KB
/
client.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <memory>
#include <string>
#include <grpcpp/grpcpp.h>
#include "llm.grpc.pb.h"
using namespace de::kherud::grpc::llm;
using grpc::Channel;
using grpc::ClientContext;
using grpc::Status;
class LLMClient {
public:
LLMClient(std::shared_ptr<Channel> channel)
: stub_(LLM::NewStub(channel)) {}
// Assembles the client's payload, sends it and presents the response back
// from the server.
void status() {
// Data we are sending to the server.
GetStatusRequest request;
// Container for the data we expect from the server.
GetStatusReply reply;
// Context for the client. It could be used to convey extra information to
// the server and/or tweak certain RPC behaviors.
ClientContext context;
// The actual RPC.
Status status = stub_->status(&context, request, &reply);
// Act upon its status.
if (status.ok()) {
std::cout << "available" << std::endl;
std::cout << reply.available() << std::endl;
} else {
std::cout << "not available" << std::endl;
std::cout << status.error_code() << ": " << status.error_message() << std::endl;
}
}
private:
std::unique_ptr<LLM::Stub> stub_;
};
int main(int argc, char** argv) {
LLMClient client(
grpc::CreateChannel("0.0.0.0:50051", grpc::InsecureChannelCredentials())
);
client.status();
return 0;
}