예제 #1
0
def chat(request):
    try:
        client = str(request.GET["q"]).strip()
    except:
        msg = "hi"
    call = multiFunctionCall({"whoIs": whoIs, "getQues": getQues})
    bot = Chat(pairs, reflections, call=call)
    bot.conversation["general"].append(
        "Hi, I am your stackExchange bot. What can I do for you?")
    bot.conversation["general"].append(client)
    reply = bot.respond(client, sessionID="general")
    bot.conversation["general"].append(reply)
    return HttpResponse(reply)
예제 #2
0
def whereIs(query,sessionID="general"):
    return about(query,qtype="Place")

def whatIs(query,sessionID="general"):
    try:
        return wikipedia.summary(query)
    except:
        for newquery in wikipedia.search(query):
            try:
                return wikipedia.summary(newquery)
            except:
                pass
    return about(query)

call = multiFunctionCall({"whoIs":whoIs,
                          "whatIs":whatIs,
                          "whereIs":whereIs,
                          "tellMeAbout":tellMeAbout})

class UserMemory:

    def __init__(self,senderID, *args, **kwargs):
        self.senderID=senderID
        self.update(*args, **kwargs)

    def __getitem__(self, key):
        try:return Memory.objects.get(sender__messengerSenderID=self.senderID,key=key).value
        except:raise KeyError(key)

    def __setitem__(self, key, val):
        try:
            memory = Memory.objects.get(sender__messengerSenderID=self.senderID,key=key)
예제 #3
0
                data = response.json()
                data_list = [
                    str(i + 1) + '. ' + data['items'][i]['title']
                    for i in range((n))
                ]

                return '<br/>'.join(data_list)
            except:
                pass
    return "Oh, You misspelled somewhere!"


#Display recent 3 python questions which are not answered
firstQuestion = "Hi, How may i help you?"

call = multiFunctionCall({"whoIs": whoIs, "results": results})

chat = Chat(os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         "chatbotTemplate", "Example.template"),
            reflections,
            call=call)


def Home(request):
    return render(request, "alpha/home.html", {
        'home': 'active',
        'chat': 'chat'
    })


@csrf_exempt
예제 #4
0
from chatbot import Chat, reflections, multiFunctionCall
import wikipedia


def whoIs(query, sessionID="general"):
    try:
        return wikipedia.summary(query)
    except:
        for newquery in wikipedia.search(query):
            try:
                return wikipedia.summary(newquery)
            except:
                pass
    return "I don't know about " + query


call = multiFunctionCall({"whoIs": whoIs})
firstQuestion = "Hi, how are you?"
Chat("examples/Example.template", reflections,
     call=call).converse(firstQuestion)
import googlemaps
from chatbot import Chat, reflections, multiFunctionCall

pairs = [(
    "(what is distance between|what is distance from|what is distance|direction from)(.*)",
    ("{% call Maps:%2 %}", ))]
gmaps = googlemaps.Client(key='AIzaSyDqJydghURg-1nNGI957AH7qTNIoZs2MCY')


def Maps(query, sessionID='general'):
    query = query.split('to')
    firstdirection = query[0]
    seconddirection = query[1]
    dirs = gmaps.directions(firstdirection, seconddirection)
    dirs = dirs[0]
    dirs = dirs['legs']
    dirs = dirs[0]
    print("Distance :- " + dirs['distance']['text'])
    print("start address : " + dirs['start_address'])
    print("end address : " + dirs['end_address'])
    return ''


call = multiFunctionCall({"Maps": Maps})

firstQuestion = "Hi, how are you?"
Chat(pairs, reflections, call=call).converse(firstQuestion)
예제 #6
0
from chatbot import Chat,reflections,multiFunctionCall
import wikipedia,os

import warnings
warnings.filterwarnings("ignore")

def whoIs(query,sessionID="general"):
    try:
        return wikipedia.summary(query)
    except:
        for newquery in wikipedia.search(query):
            try:
                return wikipedia.summary(newquery)
            except:
                pass
    return "I don't know about "+query
        
    

call = multiFunctionCall({"whoIs":whoIs})
firstQuestion="Hi, how are you?"
chat = Chat(os.path.join(os.path.dirname(os.path.abspath(__file__)),"Example.template"), reflections,call=call)
chat.converse(firstQuestion)
#chat.save_template("test.template")
    if 'questions' or 'question' in search:
        types='questions'
        tag='sort'

    # for not answered questions
    if 'not answered' in search:
        types='unanswered'
        tag='tab'


    # to make url of your given question
    for domain in search.split(' '):
        url = 'https://stackoverflow.com' + '/' + types + '/tagged' + '/' + domain
        key = {tag: view,
               'pageSize': 15
               }
        if url == 'https://stackoverflow.com' + '/' + types + '/tagged/':
            continue
        searching(url, key, number)
    else:
        # print("else")
        url = 'https://stackoverflow.com' + '/' + types
        searching(url, '', number)

    return ''


call = multiFunctionCall({"StackOver":StackOver})
firstQuestion="Hi, how are you?"
Chat(pairs, reflections,call=call).converse(firstQuestion)
예제 #8
0
    cur.execute("UPDATE flights SET seats = seats - (?) WHERE id = (?)",(sno, fno))
    
    cur.execute("SELECT seats FROM flights WHERE id = (?)", (fno,))
    seats = cur.fetchall()
    
    # for key in flights.keys():
    #     if key == fno:
    #         if(flights[key].seats[sno].booked == 0):
    #             flights[key].seats[sno].booked = 1
    #             print("Succesfully booked")
    #         else:
    #             print("This seat has already been taken")
    return str(seats[0][0])

call = multiFunctionCall({"showSeats":showSeats,
        "returnFlights":returnFlights, 
        "getFlightDetails":getFlightDetails,
        "bookFlight":bookFlight})
chat = Chat(os.path.join(os.path.dirname(os.path.abspath(__file__)),"examples/flightRules.template"), reflections,call=call)
chat.converse_http("Hi","") 

@app.route('/chat', methods = ["POST"])
def hello():
    print(request.json)
    message = request.json['message']
    print(message)                         
    return chat.converse_http(message),200

    
def whoIs(query,sessionID="general"):
    try:
        return wikipedia.summary(query)