def get_sds_server(self): sds_channel = grpc.insecure_channel('localhost:9860') print 'stub' MG = resolver_pb2.ModelGroup() # ATTENTION - Until Find Function MG.name = 'grammar' MG.lang = self.lang MG.is_external = self.is_external resolver_stub = resolver_pb2.SdsServiceResolverStub(sds_channel) resolver_stub.CreateModelGroup(MG) MP = resolver_pb2.ModelParam() MP.lang = self.lang MP.is_external = self.is_external MP.group_name = MG.name for mn in self.model_list: MP.model_name = mn resolver_stub.LinkModel(MP) print "model_name : " + MP.model_name self.server_status = resolver_stub.Find(MG) logging.debug('find result :%s', self.server_status) self.sds_stub = sds_pb2.SpokenDialogServiceInternalStub( grpc.insecure_channel(self.server_status.server_address)) self.sds_server_addr = self.server_status.server_address
def GetSdsServer(self, model): model_list = [model] sds_channel = grpc.insecure_channel('0.0.0.0:9860') resolver_stub = resolver_pb2_grpc.SdsServiceResolverStub(sds_channel) # Model Group MG = resolver_pb2.ModelGroup() MG.name = model MG.lang = 0 MG.is_external = True #resolver_stub.CreateModelGroup(MG) try: resolver_stub.CreateModelGroup(MG) except Exception as e: pass # print(e) # traceback.print_exc(limit=None) Model = resolver_pb2.Model() Model.lang = MG.lang Model.is_external = MG.is_external MP = resolver_pb2.ModelParam() MP.lang = MG.lang MP.is_external = MG.is_external MP.group_name = MG.name ML = resolver_pb2.ModelList() for mn in model_list: Model.name = mn MP.model_name = mn Model = ML.models.add() resolver_stub.LinkModel(MP) server_status = resolver_stub.Find(MG) print "<Find result>" # 서버가 시동중일 때 sleep 필요 if server_status.state is resolver_pb2.SERVER_STATE_STARTING: print "SERVER STARTING" time.sleep(0.5) self.sds_stub = sds_pb2_grpc.SpokenDialogServiceStub( grpc.insecure_channel(server_status.server_address)) # self.sds_stub = sds_pb2_grpc.SpokenDialogServiceInternalStub(grpc.insecure_channel(server_status.server_address)) self.sds_server_addr = server_status.server_address
def serve(): sds_channel = grpc.insecure_channel('0.0.0.0:9860') resolver_stub = resolver_pb2.SdsServiceResolverStub(sds_channel) #print sds_channel print 'resolver_stub', resolver_stub MG = resolver_pb2.ModelGroup() MG.name = 'test_kor' MG.lang = 0 MG.is_external = True print MG resolver_stub.CreateModelGroup(MG) M = resolver_pb2.Model() M.lang = 0 M.is_external = True MP = resolver_pb2.ModelParam() MP.lang = 0 MP.group_name = 'test_kor' MP.is_external = True print MP ML = resolver_pb2.ModelList() model_name_list = ['base', 'AI_Agent'] for mn in model_name_list: M.name = mn MP.model_name = mn M = ML.models.add() resolver_stub.LinkModel(MP) ss = resolver_stub.Find(MG) print ss sds_stub = sds_pb2.SpokenDialogServiceStub( grpc.insecure_channel(ss.server_address)) print sds_stub time.sleep(20) empty = empty_pb2.Empty() time.sleep(20) cML = sds_stub.GetCurrentModels(empty) print 'cML' print cML aML = sds_stub.GetAvailableModels(empty) print 'aML' print aML pong = sds_stub.Ping(MG) print pong dp = sds_pb2.DialogueParam() dp.model = 'AI_Agent' dp.session_key = 0 dp.user_initiative = False OpenResult = sds_stub.Open(dp) print OpenResult sq = sds_pb2.SdsQuery() sq.model = dp.model sq.session_key = dp.session_key sq.apply_indri_score = 0 sq.utter = '안녕' Intent = sds_stub.Understand(sq) print Intent Entity = sds_pb2.Entities() Entity.session_key = dp.session_key Entity.model = dp.model sds_utter = sds_stub.GenerateEntities(Entity) print sds_utter print sds_utter.response '''