示例#1
0
    def Answer(self, request, context):

        question = request.question
        question = question.lower()  # convert to lower case

        if question.split()[0] in ['why', 'what', 'how', 'who', 'when']:

            # call Retort with question
            with grpc.insecure_channel('23.236.49.28:50051') as channel:
                stub = consultation_pb2_grpc.CampaignManagerStub(channel)
                retort_response = stub.Retort(
                    consultation_pb2.RetortRequest(
                        original_question=request.question))

            # replace all "you" with "i" and all "your" with "my"
            question_stub = question.replace('your', 'my')
            question_stub = question_stub.replace('you', 'I')

            return debate_pb2.AnswerReply(
                answer="You asked me " + question_stub +
                " but I want to say that " + retort_response.retort)

        else:
            # randomly select 0 or 1 and return a response
            num = random.randint(0, 1)
            if num == 0:
                return debate_pb2.AnswerReply(
                    answer="your 3 cent titanium tax goes too far")
            else:
                return debate_pb2.AnswerReply(
                    answer="your 3 cent titanium tax doesn't go too far enough​"
                )
示例#2
0
	def Answer(self,request,context):
		quest = request.question.split()
		start = quest[0].lower()
		#does the question start with why,what,how,who or when? 
		match = re.search(r'what|why|how|who|when',start)
		if not match:
			rando = randint(0,1) #flip a coin 
			if rando == 0:
				answer = "your 3 cent titanium tax goes too far"
			else:
				answer = "your 3 cent titanium tax doesn't go too far enough"
			return debate_pb2.AnswerReply(answer=answer)
		else:
			quest_sub = [] 
			for word in quest:
				word = word.lower()
				if word == "you":
					word ="I"
				elif word == "your":
					word = "my"
				quest_sub.append(word)
			string = " ".join(quest_sub)
			print string 
			#make rpc call to external server on port 50051

			channel = grpc.insecure_channel('localhost:50051') #grpc channel
			stub = consultation_pb2.CampaignManagerStub(channel) 
		
			try:
				retort = stub.Retort(consultation_pb2.RetortRequest(original_question=string))
				#reply back to the client
				reply = "You asked me " + string + " but i want to say " + retort; 
			except grpc.framework.interfaces.face.face.ExpirationError:
				reply = "nothing to say here"
			return debate_pb2.AnswerReply(answer=reply) 
示例#3
0
  def Answer(self, request, context):
    question = request.question
    first_word = question.split(' ', 1)[0]

    words = ['why', 'what', 'how', 'who', 'when']

    if not any(first_word.lower() in w for w in words):
      rand = random.randint(0, 1)

      if rand == 1:
        response = 'your 3 cent titanium tax goes too far'
      else:
        response ='your 3 cent titanium tax doesn\'t go too far enough'

    else:
      # replaces all occurrences of the word 'You' with 'I'
      # and all occurrences of the word 'your' with 'my'
      post_replacement = ' '.join('I' if word.lower() == 'you' else word for word in question.split())
      post_replacement = ' '.join('my' if word.lower() == 'your' else word for word in post_replacement.split())

      # Makes an RPC call with question to the external CampaignManager.Retort service
      channel = grpc.insecure_channel('23.236.49.28:50051')
      stub = consultation_pb2_grpc.CampaignManagerStub(channel)
      retort = stub.Retort(consultation_pb2.RetortRequest(original_question=question)).retort

      response = 'You asked me: ' + post_replacement + ' but I want to say that: ' + retort
    return debate_pb2.AnswerReply(answer=response)
示例#4
0
    def Answer(self, request, context):
        question = list(map(lambda x: x.lower(), request.question.split(" ")))

        if question[0] not in interrogatives:
            replies = [
                "your 3 cent titanium tax goes too far",
                "your 3 cent titanium tax doesn't go too far enough"
            ]
            return debate_pb2.AnswerReply(answer=replies[randint(0, 1)])
        for idx, word in enumerate(question):
            if word == "you":
                question[idx] = "I"
            elif word == "your":
                question[idx] = "my"
        channel = grpc.insecure_channel("23.236.49.28:50051")
        stub = consultation_pb2_grpc.CampaignManagerStub(channel)
        retort = stub.Retort(
            consultation_pb2.RetortRequest(
                original_question=" ".join(question)))
        return debate_pb2.AnswerReply(
            answer="You asked me " + " ".join(question) +
            " but I want to say that " + retort.retort)
    def Answer(self, request, context):
        words = ['why', 'what', 'how', 'who', 'when']
        lst = request.question.split(" ")
        if lst[0].lower() in words:
            for i in range(len(lst)):
                if lst[i].lower() == 'you':
                    lst[i] = 'I'
                elif lst[i].lower() == 'your':
                    lst[i] = 'my'
            go = " ".join(lst)
            retort = stub.Retort(
                consultation_pb2.RetortRequest(original_question=go)).retort
            return debate_pb2.AnswerReply(answer="You asked me " + go +
                                          " but I want to say that " + retort)

        else:
            if random.randint(0, 1):
                return debate_pb2.AnswerReply(
                    answer="your 3 cent titanium tax goes too far")
            else:
                return debate_pb2.AnswerReply(
                    answer="your 3 cent titanium tax doesn't go too far enough"
                )
示例#6
0
 def Answer(self, request, context):
     acceptable_question_starts = ['why', 'what', 'how', 'who', 'when']
     question = request.question.lower().split(' ')
     return_answer = ''
     if question[0] in acceptable_question_starts:
         question_sub = request.question.replace('You', 'I')
         question_sub = question_sub.replace('your', 'my')
         question_sub = question_sub.lower()
         retort = get_retort(request.question, request.timeout)
         return_answer = 'You asked me ' + question_sub + \
             ' but I want to say that ' + retort
         if retort == 'no comment':
             return_answer = retort
     else:
         answer_options = [
             'your 3 cent titanium tax goes too far',
             'your 3 cent titanium tax doesn\'t go too far enough'
         ]
         flip_value = coin_flip()
         return_answer = answer_options[flip_value]
     return debate_pb2.AnswerReply(answer=return_answer)