예제 #1
0
def get_retort(question, timeout):
    channel = implementations.insecure_channel('54.88.18.92', 50051)
    stub = consultation_pb2.beta_create_CampaignManager_stub(channel)
    try:
        response = stub.Retort(consultation_pb2.RetortRequest(
            original_question=question), timeout + 10)
        return response.retort
    except framework.interfaces.face.face.ExpirationError:
        return 'no comment'
예제 #2
0
def get_retort(question, timeout):
    channel = implementations.insecure_channel('54.88.18.92', 50051)
    stub = consultation_pb2.beta_create_CampaignManager_stub(channel)
    try:
        response = stub.Retort(
            consultation_pb2.RetortRequest(original_question=question),
            timeout + 10)
        return response.retort
    except framework.interfaces.face.face.ExpirationError:
        return 'no comment'
예제 #3
0
    def Answer(self, request, context=None):
        if re.match("^(why|what|how|who|when)", request.question, re.IGNORECASE):
            replaced = re.sub("your", "my", request.question, len(request.question), re.IGNORECASE)
            replaced = re.sub("you", "I", replaced, len(request.question), re.IGNORECASE)

            try:
                channel = implementations.insecure_channel('54.88.18.92', 50051)
                stub = consultation_pb2.beta_create_CampaignManager_stub(channel)
                response = stub.Retort(consultation_pb2.RetortRequest(original_question=replaced), request.timeout+10)
                ans = 'You asked me %s but I want to say that %s.' % (replaced, response.retort)

            except grpc.framework.interfaces.face.face.ExpirationError:
                ans = 'No comment.'

        else:
            i = random.randint(0, 1)
            if i == 0:
                ans = 'Your 3 cent titanium tax goes too far.'
            else:
                ans = 'Your 3 cent titanium tax doesn\'t go too far enough.'

        return debate_pb2.AnswerReply(answer=ans)
        def Answer(self, request, context): 
                sentence = request.question.split()
                start_word = sentence[0].lower()
                match = re.search(r'what|why|how|who|when',start_word)
                if not match:
                        rand_num = randint (0,1)
                        if rand_num == 0:
                                ran_answer = "your 3 cent titanium tax goes too far"
                        else:
                                ran_answer = "your 3 cent titanium tax doesn't go too far enough"
                                #AnswerReply.answer
                        return debate_pb2.AnswerReply(answer=ran_answer)
                if match:
                        # if question is "what is your opinion on China", I change it to "what is my opinion on China"
                        answer_sub = []
                        for word in sentence:
                                word = word.lower()
                                if word == "you":
                                        word = "I"
                                elif word == "your":
                                        word = "my"
        
                                answer_sub.append(word + " ")
                        answer_string = ''.join(answer_sub)
                        
                        #makes an RPC call to external server CampainManager.Retort with request = "answer_string "
                        channel = implementations.insecure_channel('54.88.18.92', 50051)
                        stub = consultation_pb2.beta_create_CampaignManager_stub(channel)
                        try:
                                RetortReply = stub.Retort(consultation_pb2.RetortRequest(original_question=answer_string), request.timeout+10)
                                answer = 'You asked me ' + answer_string + 'but I want to say that ' + RetortReply.retort
                        #this service will reply something ridiculous, like "I am going to disprove CAP thoerem"
                        except grpc.framework.interfaces.face.face.ExpirationError:

                                answer = 'No comment.'
                        else:
                                answer = 'You asked me ' + answer_string + 'but I want to say that ' + RetortReply.retort

                        return debate_pb2.AnswerReply(answer=answer)