Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Help me please figure out why the program does not work?

+1 vote
asked Feb 21, 2023 by Егор Емельянов (130 points)
Online Python Compiler.
                Code, Compile, Run and Debug python program online.
Write your code in this editor and press "Run" button to execute it.

'''

print("Hello World")
import apiai
import json
import colorama as i
import termcolor as t
from termcolor import colored, cprint
i.init ()
print('----------April----------------')
def send_message(message):
# Токен API к Dialogflow
request = apiai.ApiAI('284b7a7808e148bd8675345de315ba1c').text_request()
# На каком языке будет послан запрос
request.lang = 'ru'
# ID Сессии диалога (нужно, чтобы учить бота)
request.session_id = 'April2020'
# Посылаем запрос к ИИ с сообщением от пользователя
request.query = message
# Разбираем JSON и вытаскиваем ответ
response = json.loads (request.getresponse().read().decode('utf-8'))
a = response['result']['fulfillment']['speech']
print(t.colored(a, 'white', 'on_blue'))
print ('--')
return response['result']['action']
print (t.colored('Напишите мне что-нибудь: ', 'red'))
message = input()
print ('--')
action = None
while True:
action = send_message(message)
if action == 'smalltalk.greetings.bye':
a.break
message = input ()
print ('--')

1 Answer

0 votes
answered Feb 22, 2023 by Peter Minarik (86,200 points)
  1. Fix your indentation. I'm not sure if you didn't indent anything or it got lost when you copied your code.
  2. On line 31 a.break should be probably just break.
  3. apiai is not found. Probably the server doesn't have it. You can ask the owners of OnlineGDB if they want to add this library or not. You can always install Python on your own machine and grab this library for yourself.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...