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)
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("Example.template", reflections,call=call) senderID="1,2,3" chat._startNewSession(senderID) chat.conversation[senderID].append('Say "Hello"') #firstQuestion='Say "Hello"' #chat.converse(firstQuestion,sessionID=senderID) message="" while message!="bye": message=input(">") chat.conversation[senderID].append(message) result = chat.respond(message,sessionID=senderID) chat.conversation[senderID].append(result) print(result)
from chatbot import Chat, register_call import wikipedia @register_call("whoIs") def who_is(query, session_id="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 chat = Chat("Example.template") sender_id = "1,2,3" chat.start_new_session(sender_id) chat.conversation[sender_id].append('Say "Hello"') message = "" while message != "bye": message = input(">") chat.conversation[sender_id].append(message) result = chat.respond(message, session_id=sender_id) chat.conversation[sender_id].append(result) print(result)