Exemplo n.º 1
0
    def Talk(self, input_text, session_id, model, indri_score=0):
        self.GetSdsServer(model)

        empty = empty_pb2.Empty()
        cML = self.sds_stub.GetCurrentModels(empty)
        aML = self.sds_stub.GetAvailableModels(empty)
        dp = sds_pb2.DialogueParam()
        dp.model = model

        dp.session_key = session_id
        dp.user_initiative = True

        OpenResult = self.sds_stub.Open(dp)

        sq = sds_pb2.SdsQuery()
        sq.model = dp.model
        sq.session_key = dp.session_key
        #        sq.apply_indri_score = indri_score
        sq.utter = input_text

        intent = self.sds_stub.Understand(sq)
        entities = sds_pb2.Entities()
        entities.session_key = dp.session_key
        entities.model = dp.model
        print '<intent>', intent
        print("[ENTITIES]: {}".format(entities))
        sds_utter = self.sds_stub.Generate(entities)  # 권장
        #print(sds_utter)
        confidence = sds_utter.confidence

        skill = json_format.MessageToDict(intent).get('filledEntities')
        if skill:
            skill = skill.get('skill')
        if sds_utter.finished == True:
            self.sds_stub.Close(dp)
        #return sds_utter.response.replace('\n', '')
        res = {
            "response": sds_utter.response.replace('\n', ''),
            "intent": sds_utter.system_intent,
            "intent_only": sds_utter.system_da_type,
            "current_task": sds_utter.current_task,
            "confidence": confidence,
            "best_slu": intent.origin_best_slu,
            "slots": intent.filled_entities,
            "skill": skill,
            "intent.filled_slots.items": intent.filled_entities.items()
        }
        print("--------------------------------------------------")
        print("[TASK]: {}".format(res['current_task']))
        print("[INTENT]: {}".format(res['intent_only']))
        print("[SLOT]")
        for i in res["intent.filled_slots.items"]:
            print("{}: {}".format(i[0], i[1]))
        print("[CONFIDENCE]: {}".format(res['confidence']))
        print("[RESPONSE]: {}".format(res['response']))
        print("[res]: {}".format(res))
        print("--------------------------------------------------")
        return res
Exemplo n.º 2
0
 def Close(self, req, context):
     print 'Closing for ', req.session_id, req.agent_key
     talk_stat = provider_pb2.TalkStat()
     talk_stat.session_key = req.session_id
     talk_stat.agent_key = req.agent_key
     dp = sds_pb2.DialogueParam()
     dp.session_key = req.session_id
     self.sds_stub.Close(dp)
     return talk_stat
Exemplo n.º 3
0
 def CloseTalk(self, session_id, skill):
     dp = sds_pb2.DialogueParam()
     dp.model = skill
     dp.session_key = session_id
     dp.user_initiative = True
     try:
         self.sds_stub.Close(dp)
         print "Talk Closed"
     except:
         print "Talk Close:Fail"
Exemplo n.º 4
0
    def Talk(self, talk, context):
        session_id = talk.session_id
        empty = empty_pb2.Empty()

        if not session_id in self.stat:
            self.stat[session_id] = Stat()
        local_stat = self.stat[session_id]
        logging.debug('target server address: %s',
                      self.server_status.server_address)
        ## Opening AI_Manager_Start
        dp = sds_pb2.DialogueParam()
        dp.session_key = int(session_id)
        logging.debug('session : %d', dp.session_key)

        if talk.text.find('grammar') == 0:
            local_stat.c_model = str(talk.text[-1])

        dp.model = 'grammar' + local_stat.c_model
        dp.user_initiative = False
        print 'dp model : ', dp.model
        logging.debug(dp)

        OpenResult = self.sds_stub.Open(dp)
        logging.debug('Open result : %s', OpenResult)
        print OpenResult
        talk_res = talk_pb2.TalkResponse()

        if talk.text.lower() in ['end.', 'stop.', 'done.', 'skip.']:
            self.sds_stub.Close(dp)
            talk_res.text = "We are ending the service now. Bye"  #문구 바꾸기
            talk_res.state = provider_pb2.DIAG_CLOSED
            return talk_res

        sq = sds_pb2.SdsQuery()
        sq.session_key = dp.session_key
        sq.model = dp.model
        sq.utter = talk.text.lower()
        sq.apply_indri_score = 0

        Dialog = self.sds_stub.Dialog(sq)
        logging.debug('User_talk : %s', talk.text)
        logging.debug('Dialog : %s', Dialog)
        talk_res = talk_pb2.TalkResponse()
        talk_res.text = Dialog.response

        if Dialog.status == 'end':  # 한 session 마무리 시 다음 session으로 이동
            self.sds_stub.Close(dp)
            print "domain is closed"
            talk_res.text = "RESULT: Congratulations, You did it!!"
            talk_res.state = provider_pb2.DIAG_CLOSED
        return talk_res
Exemplo n.º 5
0
    def GetIntent(self, input_text, model):
        self.GetSdsServer(model)

        empty = empty_pb2.Empty()
        cML = self.sds_stub.GetCurrentModels(empty)
        aML = self.sds_stub.GetAvailableModels(empty)
        dp = sds_pb2.DialogueParam()
        dp.model = model

        dp.session_key = 1234567898765432123
        #dp.session_key = session_id
        dp.user_initiative = True

        OpenResult = self.sds_stub.Open(dp)

        sq = sds_pb2.SdsQuery()
        sq.model = dp.model
        sq.session_key = dp.session_key
        #        sq.apply_indri_score = indri_score
        sq.utter = input_text

        intent = self.sds_stub.Understand(sq)
        return intent.intent
Exemplo n.º 6
0
    def Talk(self, input_text, session_id, model, indri_score=0):
        self.GetSdsServer(model)

        empty = empty_pb2.Empty()
        cML = self.sds_stub.GetCurrentModels(empty)
        aML = self.sds_stub.GetAvailableModels(empty)
        dp = sds_pb2.DialogueParam()
        dp.model = model

        dp.session_key = session_id
        dp.user_initiative = True
        print("-----------------------------------------")
        print("[type]: %s" % (type(dp)))
        print("[dp]: %s" % (dp))
        print("-----------------------------------------")

        OpenResult = self.sds_stub.Open(dp)
        print("-----------------------------------------")
        print("[type]: %s" % (type(OpenResult)))
        print("[dp]: %s" % (OpenResult))
        print("-----------------------------------------")

        print("test1")
        sq = sds_pb2.SdsQuery()
        sq.model = dp.model
        sq.session_key = dp.session_key
        print("test2")
        #        sq.apply_indri_score = indri_score
        print("test3")
        sq.utter = input_text

        print("test4")
        intent = self.sds_stub.Understand(sq)
        entities = sds_pb2.Entities()
        entities.session_key = dp.session_key
        entities.model = dp.model
        print '<intent>', intent
        sds_utter = self.sds_stub.Generate(entities)
        print(sds_utter)
        print '<intent.slu>', intent.origin_best_slu
        print '<intent.intent>', intent.intent
        print '<intent.filled_entities>', intent.filled_entities

        print '<intent.filled_slots.items()>', intent.filled_entities.items()
        confidence = sds_utter.confidence

        skill = json_format.MessageToDict(intent).get('filledEntities')
        if skill:
            skill = skill.get('skill')
        if sds_utter.finished == True:
            self.sds_stub.Close(dp)
        #return sds_utter.response.replace('\n', '')
        return {
            "response": sds_utter.response.replace('\n', ''),
            "intent": sds_utter.system_intent,
            "confidence": confidence,
            "best_slu": intent.origin_best_slu,
            "slots": intent.filled_entities,
            "skill": skill,
            "intent.filled_slots.items": intent.filled_entities.items()
        }
Exemplo n.º 7
0
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
    '''
Exemplo n.º 8
0
def serve():
    parser = argparse.ArgumentParser(description='dialExternalDB Test')
    parser.add_argument('-e',
                        '--endpoint',
                        nargs='?',
                        dest='endpoint',
                        required=True,
                        type=str,
                        help='server to access SDS')
    args = parser.parse_args()

    sds_stub = sds_pb2.SpokenDialogServiceStub(
        grpc.insecure_channel(args.endpoint))
    empty = empty_pb2.Empty()

    print "<Model List>"
    modelList = sds_stub.GetCurrentModels(empty)
    for ml in modelList.models:
        print str(ml)

    print "select model"
    model = raw_input()

    session_id = 1
    print "Session ID : " + str(session_id)
    print "Model : " + str(model)

    # Create OpenParam & set session_key
    dp = sds_pb2.DialogueParam()
    dp.session_key = session_id
    dp.model = model

    # Dialog Open
    sdsSession = sds_stub.Open(dp)
    print "open success"

    sdsUser = sds_pb2.SdsQuery()
    sdsUser.session_key = 1
    sdsUser.model = model
    print("Hello!")

    user_utter = "hi"
    while (user_utter != "exit"):

        sdsUser.utter = user_utter
        sa = sds_stub.Understand(sdsUser)

        entities = sds_pb2.Entities()
        entities.session_key = 1
        entities.model = model
        sdsResponse = sds_stub.GenerateEntities(entities)

        if (not sdsResponse.response):
            break

        print "[System] " + sdsResponse.response

        user_utter = raw_input("[User]  ")

    sds_stub.Close(dp)

    print("SDS is closed")
Exemplo n.º 9
0
    def Talk(self, talk, context):
        session_id = talk.session_id
        empty = empty_pb2.Empty()
        if not session_id in self.stat:
            self.stat[session_id] = Stat()
        local_stat = self.stat[session_id]

        logging.debug('target server address: %s',
                      self.server_status.server_address)
        ## Opening AI_Manager_Start
        dp = sds_pb2.DialogueParam()
        dp.session_key = int(session_id)
        logging.debug('session : %d', dp.session_key)
        print dp.session_key, 'talk.text: ', talk.text

        #print talk.text.find('lg_speaker_1_4_')
        p = re.compile(_REQ_REX_LG_SPEAKER)
        dp.model = str(talk.text)
        m = p.match(talk.text)
        if m:
            self.lecture_turn = m.group(0)
            self.lecture = m.group(1)
            self.turn = m.group(2)
            if self.lecture_turn in self.model_list:
                local_stat.c_model = self.lecture_turn

        dp.model = local_stat.c_model

        print 'dp model : ', dp.model
        logging.debug(dp)

        OpenResult = self.sds_stub.Open(dp)
        logging.debug('Open result : %s', OpenResult)
        print 'openResult', OpenResult
        talk_res = provider_pb2.TalkResponse()

        if talk.text.lower() in [
                'end.', 'stop.', 'done.', 'skip.', 'before', 'next',
                'one lecture', 'two lecture', 'tree lecture'
        ]:
            self.sds_stub.Close(dp)
            talk_res.text = "We are ending the service now. Bye"  # 문구 바꾸기
            print 'talk_res.text', talk_res.text, talk.text.lower()
            talk_res.state = provider_pb2.DIAG_CLOSED
            return talk_res

        sq = sds_pb2.SdsQuery()
        sq.session_key = dp.session_key
        sq.model = dp.model
        sq.utter = talk.text.lower()
        sq.apply_indri_score = 0

        Dialog = self.sds_stub.Dialog(sq)
        logging.debug('User_talk : %s', talk.text)
        logging.debug('Dialog : %s', Dialog)
        talk_res = provider_pb2.TalkResponse()
        talk_res.text = Dialog.response
        print 'talk_res.text', talk_res.text
        print 'Dialog.status', Dialog.status
        if Dialog.status == 'end':  # 한 session 마무리 시 다음 session으로 이동
            self.sds_stub.Close(dp)
            print "domain is closed"
            print 'self.turn_match', self.turn_match, 'turn', self.turn
            print 'tm', self.turn_match[self.turn]
            talk_res.text = self.lecture + self.turn_match[self.turn] + "qga"
            talk_res.state = provider_pb2.DIAG_CLOSED
        else:
            talk_res.text = self.lecture + self.turn_match[self.turn] + "qwa"
        return talk_res
Exemplo n.º 10
0
    def Talk(self,
             input_text,
             session_id,
             model,
             product_code="",
             indri_score=0):
        self.GetSdsServer(model)

        empty = empty_pb2.Empty()
        cML = self.sds_stub.GetCurrentModels(empty)
        aML = self.sds_stub.GetAvailableModels(empty)
        dp = sds_pb2.DialogueParam()
        dp.model = model
        #슬롯 값 지정하는 i
        # get_slot = self.DBConnect("select session_name,phone,user_name,join_time,talk_time,insurance_contractor,insurance_insured,insurance_closeproduct,privacy_add1,privacy_add2,insurance_productname from hc_hh_1_score where phone = '" + phoneNum + "';")
        #  if product_code != "":
        #     dp.slots["product_code"] = product_code
        # dp.slots["test"] = "하잉!"
        #dp.slots["슬롯명"] = "슬롯값"

        dp.session_key = session_id
        dp.user_initiative = True

        OpenResult = self.sds_stub.Open(dp)

        sq = sds_pb2.SdsQuery()
        sq.model = dp.model
        sq.session_key = dp.session_key
        #        sq.apply_indri_score = indri_score
        sq.utter = input_text

        intent = self.sds_stub.Understand(sq)
        entities = sds_pb2.Entities()
        entities.session_key = dp.session_key
        entities.model = dp.model
        print '<intent>', intent
        print("[ENTITIES]: {}".format(entities))
        sds_utter = self.sds_stub.Generate(entities)  # 권장
        #print(sds_utter)
        confidence = sds_utter.confidence

        skill = json_format.MessageToDict(intent).get('filledEntities')
        if skill:
            skill = skill.get('skill')
        if sds_utter.finished == True:
            self.sds_stub.Close(dp)
        #return sds_utter.response.replace('\n', '')
        res = {
            "response": sds_utter.response.replace('\n', ''),
            "intent": sds_utter.system_intent,
            "intent_only": sds_utter.system_da_type,
            "current_task": sds_utter.current_task,
            "confidence": confidence,
            "best_slu": intent.origin_best_slu,
            "slots": intent.filled_entities,
            "skill": skill,
            "intent.filled_slots.items": intent.filled_entities.items()
        }
        print("--------------------------------------------------")
        print("[TASK]: {}".format(res['current_task']))
        print("[INTENT]: {}".format(res['intent_only']))
        print("[SLOT]")
        for i in res["intent.filled_slots.items"]:
            print("{}: {}".format(i[0], i[1]))
        print("[EMPTY_SLOT]: {}".format(intent.empty_entities))
        print("[CONFIDENCE]: {}".format(res['confidence']))
        print("[RESPONSE]: {}".format(res['response']))
        print("[res]: {}".format(res))
        print("--------------------------------------------------")
        return res
Exemplo n.º 11
0
def serve():
    parser = argparse.ArgumentParser(description='dialInternalDB Test')
    parser.add_argument('-e',
                        '--endpoint',
                        nargs='?',
                        dest='endpoint',
                        required=True,
                        type=str,
                        help='server to access SDS')

    args = parser.parse_args()

    sds_stub = sds_pb2.SpokenDialogServiceInternalStub(
        grpc.insecure_channel(args.endpoint))
    empty = empty_pb2.Empty()

    print "<Model List>"
    modelList = sds_stub.GetCurrentModels(empty)
    for ml in modelList.models:
        print str(ml)

    session_id = 1

    name = raw_input("Choose a domain: ")

    # Create DialogSessionKey & set session_key
    dp = sds_pb2.DialogueParam()
    dp.session_key = session_id
    dp.model = name

    # Dialog Open
    OpenResult = sds_stub.Open(dp)

    model = resolver_pb2.Model()
    model.name = name
    model.lang = 1
    model.is_external = False

    print(OpenResult.system_dialog)

    sdsUser = sds_pb2.SdsQuery()
    sdsUser.session_key = 1
    sdsUser.model = name
    user_utter = raw_input("[User]  ")
    sdsUser.utter = user_utter
    Dialog = sds_stub.Dialog(sdsUser)

    while (Dialog.status == "no end"):
        print Dialog

        print Dialog.response

        user_utter = raw_input("[User] ") + "\n"

        sdsUser.utter = user_utter

        Dialog = sds_stub.Dialog(sdsUser)

    print "You have successfully finished unit " + name + "!\n"

    dsk = sds_pb2.DialogueParam()
    dsk.session_key = 1
    dsk.model = name
    print dsk

    sds_stub.Close(dsk)

    print("SDS is now closed")