コード例 #1
0
def main():
    ai = apiai.ApiAI(CLIENT_ACCESS_TOKEN)

    session_id = uuid.uuid4(
    ).hex  # some unuque session id for user identification

    entries = [
        apiai.UserEntityEntry('Firefox', ['Firefox']),
        apiai.UserEntityEntry('XCode', ['XCode']),
        apiai.UserEntityEntry('Sublime Text', ['Sublime Text'])
    ]

    user_entities_request = ai.user_entities_request(
        [apiai.UserEntity("Application", entries, session_id)])

    user_entities_response = user_entities_request.getresponse()

    print 'Uplaod user entities response: ', (user_entities_response.read())

    request = ai.text_request()

    request.session_id = session_id
    request.query = "Open application Firefox"

    response = request.getresponse()

    print 'Query response: ', (response.read())
コード例 #2
0
ファイル: StreamingMain.py プロジェクト: zspasztori/Portfolio
botDo =botActions.botActions()

ai = apiai.ApiAI('e04adfd76c294f628762d676927ff97c')
session_id = uuid.uuid4().hex

session_over  = False
#Getting the list of available actions
action_list = os.listdir("LearnedActions")
entries = []
for action in action_list:
    single_action = apiai.UserEntityEntry(action, [action])
    entries.append(single_action)
user_entities_request = ai.user_entities_request(
    [
        apiai.UserEntity("eUserActions", entries, session_id)
    ]
)
user_entities_response = user_entities_request.getresponse()
action_list.extend(['Baxter','tuck','untuck','right','left','open','close','wave','ball lifting','lifting','wake up'])


#Starting the robot with a voice command
while 1:
    print 'Start with phrase "wake up Baxter"'
    client = Client(action_list)
    value_g = client.listen()
    if ('Baxter' in value_g ) or (value_g in 'Jacob Baxter') or (value_g in 'Abort'):
        break

#Invokng the welcome intent
コード例 #3
0
ファイル: views.py プロジェクト: sumit12dec/IMPress
def post_user_text(request):
    if request.method == "POST":
        user_id = request.POST.get('user_id')
        user_query = request.POST.get('user_query')
        question_id = request.POST.get('question_id', None)
        question_option_clicked = request.POST.get('option_number_clicked',
                                                   None)

    ai = apiai.ApiAI(settings.CLIENT_ACCESS_TOKEN)

    session_id = uuid.uuid4().hex

    entries = [
        apiai.UserEntityEntry('Firefox', ['Firefox']),
        apiai.UserEntityEntry('XCode', ['XCode']),
        apiai.UserEntityEntry('Sublime Text', ['Sublime Text'])
    ]

    user_entities_request = ai.user_entities_request(
        [apiai.UserEntity("Application", entries, session_id)])

    user_entities_response = user_entities_request.getresponse()

    print 'Upload user entities response: ', (user_entities_response.read())

    request = ai.text_request()

    request.session_id = session_id
    request.query = user_query

    response = request.getresponse()
    a = json.loads(response.read())
    intent_name = a['result']['metadata']['intentName']

    if intent_name == 'Welcome Intent':
        obj = UserQuestion.objects.all()[0]
        next_question_to_ask = obj.question_text
        next_question_id = obj.question_id
        print next_question_to_ask, "next_question_to_ask"
        res = {
            'question': next_question_to_ask,
            'options': None,
            'question_id': next_question_id
        }
        return JsonResponse(res)

    if question_id:
        obj = QuestionHistory(user_id=user_id,
                              question_id=question_id,
                              question_answer=user_query)
        obj.save()
        print type(question_id), question_id, "ok"
        print question_option_clicked
        if question_option_clicked:
            nxt_ques_obj = NextQuestionLink.objects.get(
                question_id=int(question_id),
                question_options=int(question_option_clicked))
            print nxt_ques_obj
            print nxt_ques_obj.question_id
            print nxt_ques_obj.question_options
            next_question_id = nxt_ques_obj.next_question_id
            print next_question_id, "next_question_id"

            q_obj = UserQuestion.objects.get(question_id=int(next_question_id))
            next_question_to_ask = q_obj.question_text
            print next_question_to_ask
            next_question_id = q_obj.question_id
            options = q_obj.question_options
            scores = q_obj.question_scores

            res = {
                'question': next_question_to_ask,
                'options': options,
                'scores': scores,
                'question_id': next_question_id,
            }
            return JsonResponse(res)
        return HttpResponse("Something")