Chatterbot: Feedback example

Created on 10 Aug 2017  Â·  24Comments  Â·  Source: gunthercox/ChatterBot

I trying to run example for feedback, with this code:

bot = ChatBot(
    'test',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    logic_adapters=[
        'chatterbot.logic.BestMatch'
    ],
    input_adapter='chatterbot.input.TerminalAdapter',
    output_adapter='chatterbot.output.TerminalAdapter',
    database="../database.db",
)
DEFAULT_SESSION_ID = bot.default_session.id
def get_feedback():
    from chatterbot.utils import input_function
    text = input_function()

    if 'yes' in text.lower():
        return True
    elif 'no' in text.lower():
        return False
    else:
        print('Please type either "Yes" or "No"')
        return get_feedback()
print('Type something to begin...')
while True:
    try:
        input_statement = bot.input.process_input_statement()
        statement, response = bot.generate_response(input_statement, DEFAULT_SESSION_ID)
        print('\n Is "{}" this a coherent response to "{}"? \n'.format(response, input_statement))
        if get_feedback():
            bot.learn_response(response, input_statement)
        bot.output.process_response(response)
        bot.storage.add_to_converation(bot.default_session, statement, response)
    except (KeyboardInterrupt, EOFError, SystemExit):
        break

And I got this error:

Type something to begin...
hola

 Is "hola" this a coherent response to "hola"? 

yes
hola
Traceback (most recent call last):
  File "feedback.py", line 61, in <module>
    bot.storage.add_to_converation(bot.default_session, statement, response)
**AttributeError: 'SQLStorageAdapter' object has no attribute 'add_to_converation'`**

All 24 comments

@nalancer08 I think the example are working fine, which version of chatterbot are you using? To know current version of chatterbot, please paste below commands on your terminal.

python -m chatterbot --version

Hi @vkosuri , I have 0.7.6

Check your code. converation has prob been corrected to conversation.
You're also going to run into an issue with the default_session.id cause it
has changed too. See pull request #916.

Cheers,

-- les

On Aug 10, 2017 5:54 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hi, I have 0.7.6

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321542541,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGN5SMw1ynZZ-k75X0ANLf4k_Q7Bexks5sWv2VgaJpZM4Oy6EZ
.

Hello @lesleslie how can I updated the code? Is there an a command?

If your getting that error the problem is in your code not chatterbot. The
spelling correction of conversation took place 6 hours ago. Follow the
traceback from the error code you're getting and it will point you to which
module and which line is calling the wrong function.

-- les

On Aug 10, 2017 6:11 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hello @lesleslie https://github.com/lesleslie how can I updated the
code? Is there an a command?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321546334,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGN5IO-KY_eTmBFd76smUrZnjyA-dKks5sWwFrgaJpZM4Oy6EZ
.

In your case line 61 in feedback.py needs converation changed to
conversation.

On Aug 10, 2017 6:17 AM, "les" les@wedgwoodwebworks.com wrote:

If your getting that error the problem is in your code not chatterbot.
The spelling correction of conversation took place 6 hours ago. Follow the
traceback from the error code you're getting and it will point you to which
module and which line is calling the wrong function.

-- les

On Aug 10, 2017 6:11 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hello @lesleslie https://github.com/lesleslie how can I updated the
code? Is there an a command?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321546334,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGN5IO-KY_eTmBFd76smUrZnjyA-dKks5sWwFrgaJpZM4Oy6EZ
.

Don't forget too to change default_session.id to default_conversation_id
too in your code.

On Aug 10, 2017 6:18 AM, "les" les@wedgwoodwebworks.com wrote:

In your case line 61 in feedback.py needs converation changed to
conversation.

On Aug 10, 2017 6:17 AM, "les" les@wedgwoodwebworks.com wrote:

If your getting that error the problem is in your code not chatterbot.
The spelling correction of conversation took place 6 hours ago. Follow the
traceback from the error code you're getting and it will point you to which
module and which line is calling the wrong function.

-- les

On Aug 10, 2017 6:11 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hello @lesleslie https://github.com/lesleslie how can I updated the
code? Is there an a command?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321546334,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGN5IO-KY_eTmBFd76smUrZnjyA-dKks5sWwFrgaJpZM4Oy6EZ
.

@lesleslie yes, I was reading the last corrections, this is my code with the corrections

from chatterbot import ChatBot

bot = ChatBot(
    'Feedback Learning Bot',
    storage_adapter='chatterbot.storage.SQLStorageAdapter',
    logic_adapters=[
        'chatterbot.logic.BestMatch'
    ],
    input_adapter='chatterbot.input.TerminalAdapter',
    output_adapter='chatterbot.output.TerminalAdapter'
)

DEFAULT_SESSION_ID = bot.default_conversation_id

def get_feedback():
    from chatterbot.utils import input_function

    text = input_function()

    if 'yes' in text.lower():
        return True
    elif 'no' in text.lower():
        return False
    else:
        print('Please type either "Yes" or "No"')
        return get_feedback()


print('Type something to begin...')

while True:
    try:
        input_statement = bot.input.process_input_statement()
        statement, response = bot.generate_response(input_statement, DEFAULT_SESSION_ID)

        print('\n Is "{}" this a coherent response to "{}"? \n'.format(response, input_statement))

        if get_feedback():
            bot.learn_response(response, input_statement)

        bot.output.process_response(response)
        bot.storage.add_to_conversation(bot.default_session, statement, response)

    except (KeyboardInterrupt, EOFError, SystemExit):
        break

But now, I getting this error:

Traceback (most recent call last):
  File "feedback.py", line 15, in <module>
    DEFAULT_SESSION_ID = bot.default_conversation_id
AttributeError: 'ChatBot' object has no attribute 'default_conversation_id'

@lesleslie I was checking the SQLAdapter code, but the function add_to_conversation doesn't exists, only add_to_converation

In the file sql_storage.py, line 248, def add_to_converation(self, conversation_id, statement, response):

But in both cases, return error

@lesleslie
I was cheking your fork, and you updated the code and adapters, to use the correct function add_to_converation, how can I upgrade the ChatterBot code to use correctly the examples?

Ok, change back to default_session.id and try that. We may be using
slightly different versions.

On Aug 10, 2017 6:28 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

@lesleslie https://github.com/lesleslie yes, I was reading the last
corrections, this is my code with the corrections

from chatterbot import ChatBot

bot = ChatBot(
'Feedback Learning Bot',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
'chatterbot.logic.BestMatch'
],
input_adapter='chatterbot.input.TerminalAdapter',
output_adapter='chatterbot.output.TerminalAdapter',
database="../database.db",

)
DEFAULT_SESSION_ID = bot.default_conversation_id
def get_feedback():
from chatterbot.utils import input_function

text = input_function()

if 'yes' in text.lower():
    return True
elif 'no' in text.lower():
    return False
else:
    print('Please type either "Yes" or "No"')
    return get_feedback()

print('Type something to begin...')
while True:
try:
input_statement = bot.input.process_input_statement()
statement, response = bot.generate_response(input_statement, DEFAULT_SESSION_ID)

    print('\n Is "{}" this a coherent response to "{}"? \n'.format(response, input_statement))

    if get_feedback():
        bot.learn_response(response, input_statement)

    bot.output.process_response(response)
    bot.storage.add_to_conversation(bot.default_session, statement, response)

except (KeyboardInterrupt, EOFError, SystemExit):
    break

But now, I getting this error:

Traceback (most recent call last):
File "feedback.py", line 15, in
DEFAULT_SESSION_ID = bot.default_conversation_id
AttributeError: 'ChatBot' object has no attribute 'default_conversation_id'

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321550788,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGN8BTVb0WoCWgr4vyztrP53lm1dyaks5sWwV_gaJpZM4Oy6EZ
.

@lesleslie I did it, but gave me this error

```
Type something to begin...
hola

Is "hola" this a coherent response to "hola"?

yes
hola
Traceback (most recent call last):
File "feedback.py", line 42, in
bot.storage.add_to_conversation(bot.default_session, statement, response)
AttributeError: 'SQLStorageAdapter' object has no attribute 'add_to_conversation'
m-C02SH023G8WP:bot2 eec000i$

```

Look at chatterbot/storage/sql_storage.py and see what the name of the
function is in your version and adjust accordingly.

-- les

On Aug 10, 2017 7:52 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

@lesleslie https://github.com/lesleslie I did it, but give me this error

Type something to begin...
hola

Is "hola" this a coherent response to "hola"?

yes
hola
Traceback (most recent call last):
File "feedback.py", line 42, in
bot.storage.add_to_conversation(bot.default_session, statement, response)
AttributeError: 'SQLStorageAdapter' object has no attribute 'add_to_conversation'
m-C02SH023G8WP:bot2 eec000i$

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321575251,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGNw0W43XRkfV_Q8OVCe8TN7VmBY6xks5sWxkxgaJpZM4Oy6EZ
.

Hi again @lesleslie

I tested you fork repo, and installed, but the same example, now gave me this error

Type something to begin...
hi

 Is "hi" this a coherent response to "hi"? 

no
hi
Traceback (most recent call last):
  File "so.py", line 47, in <module>
    bot.storage.add_to_conversation(bot.default_session, statement, response)
  File "build/bdist.macosx-10.12-intel/egg/chatterbot/storage/sql_storage.py", line 266, in add_to_conversation
  File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 864, in get
  File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 875, in _get_impl
TypeError: object of type 'NoneType' has no len()

My repo was constantly being tweaked and worked on recently so I'm not sure
when you downloaded it. As of just a few hours ago is it passing all of
the tests and is stable. Please try forking my version again and if you
run into the same problem again I'll give it a good look and help resolve
the issue. My repo, as at stands as of RIGHT NOW is, I believe, about to
be merged into the main branch.

-- les

On Aug 11, 2017 9:59 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hi again @lesleslie https://github.com/lesleslie

I tested you fork repo, and installed, but the same example, now gave me
this error

Type something to begin...
hi

Is "hi" this a coherent response to "hi"?

no
hi
Traceback (most recent call last):
File "so.py", line 47, in
bot.storage.add_to_conversation(bot.default_session, statement, response)
File "build/bdist.macosx-10.12-intel/egg/chatterbot/storage/sql_storage.py", line 266, in add_to_conversation
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 864, in get
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 875, in _get_impl
TypeError: object of type 'NoneType' has no len()

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321865598,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGNzl236gQciCKkZ0M-SSRfu_ZcJY9ks5sXIhngaJpZM4Oy6EZ
.

Nevermind that last statement. You need to change default_session to
conversation_id in line 61 of so.py. Again if you follow the traceback, to
the Exception, it will tell you exactly where the error is occurring in the
code. It may do you some good to read a python debugging tutorial.

-- les

On Aug 11, 2017 10:09 AM, "les" les@wedgwoodwebworks.com wrote:

My repo was constantly being tweaked and worked on recently so I'm not
sure when you downloaded it. As of just a few hours ago is it passing all
of the tests and is stable. Please try forking my version again and if you
run into the same problem again I'll give it a good look and help resolve
the issue. My repo, as at stands as of RIGHT NOW is, I believe, about to
be merged into the main branch.

-- les

On Aug 11, 2017 9:59 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hi again @lesleslie https://github.com/lesleslie

I tested you fork repo, and installed, but the same example, now gave me
this error

Type something to begin...
hi

Is "hi" this a coherent response to "hi"?

no
hi
Traceback (most recent call last):
File "so.py", line 47, in
bot.storage.add_to_conversation(bot.default_session, statement, response)
File "build/bdist.macosx-10.12-intel/egg/chatterbot/storage/sql_storage.py", line 266, in add_to_conversation
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 864, in get
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 875, in _get_impl
TypeError: object of type 'NoneType' has no len()

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321865598,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGNzl236gQciCKkZ0M-SSRfu_ZcJY9ks5sXIhngaJpZM4Oy6EZ
.

Make that line 47 in so.py. I think I got it right this time.

-- les

On Aug 11, 2017 10:17 AM, les les@wedgwoodwebworks.com wrote:

Sorry again, that's line 41 in so.py. I'm doing this from my phone.

On Aug 11, 2017 10:15 AM, "les" les@wedgwoodwebworks.com wrote:

Nevermind that last statement. You need to change default_session to
conversation_id in line 61 of so.py. Again if you follow the traceback, to
the Exception, it will tell you exactly where the error is occurring in the
code. It may do you some good to read a python debugging tutorial.

-- les

On Aug 11, 2017 10:09 AM, "les" les@wedgwoodwebworks.com wrote:

My repo was constantly being tweaked and worked on recently so I'm not
sure when you downloaded it. As of just a few hours ago is it passing all
of the tests and is stable. Please try forking my version again and if you
run into the same problem again I'll give it a good look and help resolve
the issue. My repo, as at stands as of RIGHT NOW is, I believe, about to
be merged into the main branch.

-- les

On Aug 11, 2017 9:59 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hi again @lesleslie https://github.com/lesleslie

I tested you fork repo, and installed, but the same example, now gave
me this error

Type something to begin...
hi

Is "hi" this a coherent response to "hi"?

no
hi
Traceback (most recent call last):
File "so.py", line 47, in
bot.storage.add_to_conversation(bot.default_session, statement, response)
File "build/bdist.macosx-10.12-intel/egg/chatterbot/storage/sql_storage.py", line 266, in add_to_conversation
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 864, in get
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 875, in _get_impl
TypeError: object of type 'NoneType' has no len()

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321865598,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGNzl236gQciCKkZ0M-SSRfu_ZcJY9ks5sXIhngaJpZM4Oy6EZ
.

Sorry again, that's line 41 in so.py. I'm doing this from my phone.

-- les

On Aug 11, 2017 10:15 AM, "les" les@wedgwoodwebworks.com wrote:

Nevermind that last statement. You need to change default_session to
conversation_id in line 61 of so.py. Again if you follow the traceback, to
the Exception, it will tell you exactly where the error is occurring in the
code. It may do you some good to read a python debugging tutorial.

-- les

On Aug 11, 2017 10:09 AM, "les" les@wedgwoodwebworks.com wrote:

My repo was constantly being tweaked and worked on recently so I'm not
sure when you downloaded it. As of just a few hours ago is it passing all
of the tests and is stable. Please try forking my version again and if you
run into the same problem again I'll give it a good look and help resolve
the issue. My repo, as at stands as of RIGHT NOW is, I believe, about to
be merged into the main branch.

-- les

On Aug 11, 2017 9:59 AM, "Erick Sánchez Pérez" notifications@github.com
wrote:

Hi again @lesleslie https://github.com/lesleslie

I tested you fork repo, and installed, but the same example, now gave me
this error

Type something to begin...
hi

Is "hi" this a coherent response to "hi"?

no
hi
Traceback (most recent call last):
File "so.py", line 47, in
bot.storage.add_to_conversation(bot.default_session, statement, response)
File "build/bdist.macosx-10.12-intel/egg/chatterbot/storage/sql_storage.py", line 266, in add_to_conversation
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 864, in get
File "build/bdist.macosx-10.12-intel/egg/sqlalchemy/orm/query.py", line 875, in _get_impl
TypeError: object of type 'NoneType' has no len()

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/gunthercox/ChatterBot/issues/920#issuecomment-321865598,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AOUGNzl236gQciCKkZ0M-SSRfu_ZcJY9ks5sXIhngaJpZM4Oy6EZ
.

@nalancer08 sorry but there is an issue with the sql_storage adapter right now. the default_conversation_id can not be 'None' when querying sql databases. i've been strictly using mongodb so i didn't see it and somehow all the tests pass this way. i was just playing around with the sql_adapter again and see what you are talking about. good catch. i have solution that i'll be proposing and pushing hopefully within the next hour or so. stay tuned ..... i'll keep you informed.

i am referring to this:

TypeError: object of type 'NoneType' has no len()

as I got it too.

@nalancer08

this is my the workaround that i propose for you:

change DEFAULT_CONVERSATION_ID or DEFAULT_SESSION_ID or whatever you have in your code to bot.storage.create_conversation(). ie:

DEFAULT_CONVERSATION_ID = bot.storage.create_conversation()

this change makes more sense to me because each time you access the bot via terminal, or however you're doing it, it actually is it's own conversation and should be treated as such. Let's say you talk to your bot in terminal mode and the somebody else then talks your bot in terminal mode - these are two separate conversations and should be treated as such.

what i am going to recommend in my pull request is changing DEFAULT_CONVERSATION_ID to just CONVERSATION_ID in examples/learning_feedback_example.py and examples/learning_new_response.py like so:

CONVERSATION_ID = bot.storage.create_conversation()

this would mean the rest of your code would need to change DEFAULT_CONVERSATION_ID to CONVERSATION_ID.

i will also be adding a line to learning new_response.py so lines 45-50 will now look like this:

    if get_feedback():
        print("please input the correct one")
        response1 = bot.input.process_input_statement()
        bot.learn_response(response1, input_statement)
        bot.storage.add_to_conversation(CONVERSATION_ID, statement, response1)
        print("Responses added to bot!")

this way the new response will be saved to the conversation too.

-- les

@nalancer08

see #927

@lesleslie let me check

I'm going to close this ticket off. ChatterBot has evolved quite a bit since this was opened and conversation/session IDs are no longer used. (Conversation has been simplified to just be a string attribute on each statement object).

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

juanpialbano picture juanpialbano  Â·  4Comments

ArunSingh1 picture ArunSingh1  Â·  3Comments

yuvalBor picture yuvalBor  Â·  3Comments

AfrahAsif picture AfrahAsif  Â·  3Comments

gunthercox picture gunthercox  Â·  3Comments