when using a feedback chatterbot it shows the following error:
Traceback (most recent call last):
File "/Applications/XAMPP/xamppfiles/htdocs/chat1.cgi", line 65, in <module>
bot.learn_response(response1, input_statement)
File "/Users/yuvikakoul/anaconda/lib/python2.7/site-packages/chatterbot/chatterbot.py", line 145, in learn_response
statement.add_response(
AttributeError: 'str' object has no attribute 'add_response'
It seems to me that you transfer your requests from a web server to chatterbot. This might converted your statmenet object into a string, If possible could you try to run your code stand alone before integrated into webserver
it works when i try to run it stand alone, but i need it to work on the server. How can i do that ?
If possible I'll will help you, if you could share your server code?
#!/Users/yuvikakoul/anaconda/bin/python
# -*- coding: utf-8 -*-
import cgi
def htmlTop():
print("""Content-type:text/html\n\n
<!DOCTYPE html>
<meta charset="utf-8"/>
<title>chat</title>
</head>
<body>""")
def htmlTail():
print("""</body>
</html>""")
if __name__ == "__main__":
try:
htmlTop()
from chatterbot import ChatBot
import logging
bot = ChatBot("Terminal",
storage_adapter="chatterbot.storage.JsonFileStorageAdapter",
)
def getdata1():
formData = cgi.FieldStorage()
text1 = formData.getvalue('text1')
text = formData.getvalue('text')
text2 = formData.getvalue('text2')
print(text)
print(text1)
print(text2)
def get_feedback():
if 'Yes' in text1 :
return False
elif 'No' in text1 :
return True
else:
print('\n\nPlease type either "Yes" or "No"')
return get_feedback()
bol=get_feedback()
if bol :
bot.learn_response(text2, text)
getdata1()
htmlTail()
except:
cgi.print_exception()
learn_response accepts statement object but you are passing strings, try to look feedback example once again for more information
I have to get the input from a Html page, so it will be a string, but how can i convert it into a statement object
Problem solved, added this
if bol :
text3 = bot.input.process_input_statement(text2)
text4 = bot.input.process_input_statement(text)
bot.learn_response(text3, text4)
I am closing this issue, feel free to reopen if you have any questions
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
Problem solved, added this
if bol :
text3 = bot.input.process_input_statement(text2)
text4 = bot.input.process_input_statement(text)
bot.learn_response(text3, text4)