pierredavidbelanger / chatter-bot-api

A Mono/.NET, JAVA, Python and PHP chatter bot API that supports Cleverbot, JabberWacky and Pandorabots.
181 stars 72 forks source link

always has a b' or a b" #27

Closed sudo-d4s3 closed 7 years ago

sudo-d4s3 commented 8 years ago

I don't know what I'm doing wrong this is my code

from chatterbotapi import ChatterBotFactory, ChatterBotType

factory = ChatterBotFactory()

bot1 = factory.create(ChatterBotType.CLEVERBOT)
bot1session = bot1.create_session()

bot2 = factory.create(ChatterBotType.CLEVERBOT)
bot2session = bot2.create_session()

s = 'Hi'
while (1):

    print ('bot1> ' + s)

    s = bot2session.think(s);
    print ('bot2> ' + s)

    s = bot1session.think(s);

and here is the output

bot1> Hi bot2> b'Ja jestem ch\xc5\x82opakiem palancie. bot1> b"That's not english. bot2> b'Yash, it is. bot1> b"Your last message was, but not the one before. bot2> b'What are you doing? bot1> b"Talking to you. What are you doing? bot2> b'Talking with you. I think. bot1> b"Ohhh, that was suprising.

pierredavidbelanger commented 8 years ago

Did you mod the chatterbotapi.py file ?

Can you paste here whats in your chatterbotapi.py file, near the lines 73 and 144

sudo-d4s3 commented 8 years ago

thought.text = text return self.think_thought(thought).text

class ChatterBotThought:

pass

#################################################

Cleverbot impl

#################################################

class _Cleverbot(ChatterBot):

def __init__(self, baseUrl, serviceUrl, endIndex):
    self.baseUrl = baseUrl
    self.serviceUrl = serviceUrl
    self.endIndex = endIndex

def create_session(self):
    return _CleverbotSession(self)

class _CleverbotSession(ChatterBotSession):

def __init__(self, bot):
    self.bot = bot
    self.vars = OrderedDict()
    #self.vars['start'] = 'y'
    self.vars['stimulus'] = ''
    self.vars['islearning'] = '1'
    self.vars['icognoid'] = 'wsf'
    #self.vars['fno'] = '0'
    #self.vars['sub'] = 'Say'
    #self.vars['cleanslate'] = 'false'
    self.cookieJar = cookielib.CookieJar()
    self.opener = build_opener(HTTPCookieProcessor(self.cookieJar))
    self.opener.open(self.bot.baseUrl)

def think_thought(self, thought):
    self.vars['stimulus'] = thought.text
    data = urlencode(self.vars)
    data_to_digest = data[9:self.bot.endIndex]
    data_digest =

hashlib.md5(data_to_digest.encode('utf-8')).hexdigest() data = data + '&icognocheck=' + data_digest url_response = self.opener.open(self.bot.serviceUrl, data.encode('utf-8')) response = str(url_response.read()) response_values = re.split(r'\r|\r', response)

self.vars['??'] = _utils_string_at_index(response_values, 0)

    self.vars['sessionid'] = _utils_string_at_index(response_values, 1)
    self.vars['logurl'] = _utils_string_at_index(response_values, 2)
    self.vars['vText8'] = _utils_string_at_index(response_values, 3)
    self.vars['vText7'] = _utils_string_at_index(response_values, 4)
    self.vars['vText6'] = _utils_string_at_index(response_values, 5)
    self.vars['vText5'] = _utils_string_at_index(response_values, 6)
    self.vars['vText4'] = _utils_string_at_index(response_values, 7)
    self.vars['vText3'] = _utils_string_at_index(response_values, 8)
    self.vars['vText2'] = _utils_string_at_index(response_values, 9)
    self.vars['prevref'] = _utils_string_at_index(response_values, 10)
    #self.vars['??'] = _utils_string_at_index(response_values, 11)

self.vars['emotionalhistory'] =

_utils_string_at_index(response_values, 12)

self.vars['ttsLocMP3'] = _utils_string_at_index(response_values,

13)

self.vars['ttsLocTXT'] = _utils_string_at_index(response_values,

14)

self.vars['ttsLocTXT3'] = _utils_string_at_index(response_values,

15)

self.vars['ttsText'] = _utils_string_at_index(response_values, 16)

self.vars['lineRef'] = _utils_string_at_index(response_values, 17)

self.vars['lineURL'] = _utils_string_at_index(response_values, 18)

self.vars['linePOST'] = _utils_string_at_index(response_values, 19)

self.vars['lineChoices'] = _utils_string_at_index(response_values,

20)

self.vars['lineChoicesAbbrev'] =

_utils_string_at_index(response_values, 21)

self.vars['typingData'] = _utils_string_at_index(response_values,

22)

self.vars['divert'] = _utils_string_at_index(response_values, 23)

    response_thought = ChatterBotThought()
    response_thought.text = _utils_string_at_index(response_values, 0)

On Tue, May 10, 2016 at 3:03 PM, Pierre-David Bélanger < notifications@github.com> wrote:

Did you mod the chatterbotapi.py https://github.com/pierredavidbelanger/chatter-bot-api/blob/master/python/chatterbotapi.py file ?

Can you paste here whats in your chatterbotapi.py https://github.com/pierredavidbelanger/chatter-bot-api/blob/master/python/chatterbotapi.py file, near the lines 73 https://github.com/pierredavidbelanger/chatter-bot-api/blob/master/python/chatterbotapi.py#L73 and 144 https://github.com/pierredavidbelanger/chatter-bot-api/blob/master/python/chatterbotapi.py#L144

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/pierredavidbelanger/chatter-bot-api/issues/27#issuecomment-218274146

pierredavidbelanger commented 8 years ago

This is strange. I do not know your OS, or even if you are executing this is an terminal. But, if you happen to use a unix like OS (linux or osx), execute the locale command in a terminal and paste the output here. It should give you something like this:

$ locale
LANG="fr_CA.UTF-8"
LC_COLLATE="fr_CA.UTF-8"
LC_CTYPE="fr_CA.UTF-8"
LC_MESSAGES="fr_CA.UTF-8"
LC_MONETARY="fr_CA.UTF-8"
LC_NUMERIC="fr_CA.UTF-8"
LC_TIME="fr_CA.UTF-8"
LC_ALL=
sudo-d4s3 commented 8 years ago

I am running this on windows, with python idle but on another pc and it doesn't do this On May 11, 2016 3:01 PM, "Pierre-David Bélanger" notifications@github.com wrote:

This is strange. I do not know your OS, or even if you are executing this is an terminal. But, if you happen to use a unix like OS (linux or osx), execute the locale command in a terminal and paste the output here. It should give you something like this:

$ locale LANG="fr_CA.UTF-8" LC_COLLATE="fr_CA.UTF-8" LC_CTYPE="fr_CA.UTF-8" LC_MESSAGES="fr_CA.UTF-8" LC_MONETARY="fr_CA.UTF-8" LC_NUMERIC="fr_CA.UTF-8" LC_TIME="fr_CA.UTF-8" LC_ALL=

— You are receiving this because you authored the thread. Reply to this email directly or view it on GitHub https://github.com/pierredavidbelanger/chatter-bot-api/issues/27#issuecomment-218572902

pierredavidbelanger commented 8 years ago

I do not have access to Windows, so I can not reproduce this strange bug. Are you able to tel what is the difference between the two pc ? Maybe the Python version, the OS locale, the IDE ..

Also, before your program (after the from chatterbotapi import ChatterBotFactory, ChatterBotType), try putting those lines:

import locale
locale.setlocale(locale.LC_ALL, '')

Anyways, I guess it has something to do with your OS regional or locale settings.