New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is it possible to do math like calculations in chatterbot? #1331
Comments
Yes, this is possible. You just need to add http://chatterbot.readthedocs.io/en/stable/logic/#mathematical-evaluation-adapter |
instead of calling mathematical adapter,can it be written in as a custom logic adapter,where the prompt from bot comes to input the number.Then user inputs the number and the calculation happens? |
You are more than welcome to create your own logic adapters. The idea you are proposing definitely sounds like it would be possible to make. |
I have created my own logic adapter,and integrated with flask. Instead of asking the values to user in python terminal,I want to ask in logic adapter to display through flask.Can you please help with this ? |
@swathy06 Are you looking this kind of implementation? # -*- coding: utf-8 -*-
from chatterbot import ChatBot
# Create a new instance of a ChatBot
bot = ChatBot(
'Exact Response Example Bot',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.SpecificResponseAdapter',
'input_text': 'Help me!',
'output_text': 'Ok, here is a link: http://chatterbot.rtfd.org'
}
],
trainer='chatterbot.trainers.ListTrainer'
)
# Get a response given the specific input
response = bot.get_response('Help me!')
print(response) If not could you elaborate your question with an example? |
This is my custom logic adapter, class MathLogicAdapter1(LogicAdapter):
def can_process(self, statement):
words = [ 'ADD']
if all(x in statement.text.split() for x in words):
return True
else:
return False
def process(self, statement):
from chatterbot.conversation import Statement
user_input = statement.text.lower()
if 'ADD' not in user_input:
return 0, Statement('')
else :
w = float( input("enter the number"))
h = float(input("enter the number"))
m = ( (w )/(h*h))
confidence = 1
response_statement = Statement('Your sum is {}'.format(m))
response_statement.confidence = confidence
return response_statement I want print statement of w and h to be displayed through flask and the value which user gives should be taken to do the calculation.Is it possible to do so? |
@swathy06 Are you trying to get inputs from flask? You may see this repo https://github.com/chamkank/flask-chatterbot |
Yes,flask is working properly. |
@swathy06 Yes, that is possible. I'm going to close this ticket off since it's been a while and a number of changes have been made to ChatterBot. Feel free to open a new ticket if you have any further 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. |
The user will input the number,the bot will do according to user and display response?
The text was updated successfully, but these errors were encountered: