import argparse import warnings from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.utils import EndpointConfig from rasa_core.trackers import DialogueStateTracker from rasa_core.slots import TextSlot from rasa_core.events import SlotSet from model.network_config import actionIP # Start Rasa-Core Agent interpreter = RasaNLUInterpreter('model/agent-data/models/nlu/default/current') action_endpoint = EndpointConfig(url=actionIP) agent = Agent.load('model/agent-data/models/dialogue', interpreter=interpreter, action_endpoint=action_endpoint) # Handle user message and return responses from training data def getResponse(sessionId, message): responses = agent.handle_text(message, sender_id=sessionId) print('Rasa-Core responses: ', responses) if (len(responses) > 0): returnResponses = [] for response in responses: if 'buttons' in response: returnResponses.append({ 'text': response['text'], 'buttons': response['buttons']
def run_bot_online(interpreter, domain_file, training_data_file): action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") fallback = FallbackPolicy(fallback_action_name="action_default_fallback", core_threshold=0.3, nlu_threshold=0.3) agent = Agent(domain=domain_file, policies=[ MemoizationPolicy(max_history=6), KerasPolicy(max_history=6, epochs=200), fallback, FormPolicy() ], interpreter=interpreter, action_endpoint=action_endpoint) data = agent.load_data(training_data_file) agent.train(data) interactive.run_interactive_learning(agent, training_data_file) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter(NLU_INTERPRETER) run_bot_online(interpreter=nlu_interpreter, domain_file=DOMAIN_FILE, training_data_file=TRAINING_DATA_FILE)
from rasa_core.channels import HttpInputChannel from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter from rasa_slack_connector import SlackInput nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/restaurantnlu') agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter) input_channel = SlackInput('xoxp-517280283250-517151581972-516736065809-6f37c4a1df0ecb3aa9b1e10dd8a7e94b', #app verification token 'xoxb-517280283250-516736066865-kODLJiSWGq0vX6tdfxIfxL6i', # bot verification token 'cyhtM54NFDEBlxRlklsyKIU5', # slack verification token True) agent.handle_channel(HttpInputChannel(5004, '/', input_channel))
from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter logger = logging.getLogger(__name__) def run_restaurant_online(input_channel, interpreter, domain_file="restaurant_domain.yml", training_data_file='data/stories.md'): agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()], interpreter=interpreter) agent.train_online(training_data_file, input_channel=input_channel, max_history=2, batch_size=50, epochs=200, max_training_samples=300) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter( './models/foodiebot/nlu/default/current') print(nlu_interpreter.parse(u"Send an email on [email protected]"))
from rasa_core.interpreter import RasaNLUInterpreter logger = logging.getLogger(__name__) def train_agent(interpreter, domain_file="domain.yml", training_file='data/stories.md'): action_endpoint = EndpointConfig('http://localhost:5055/webhook') policies = [ MemoizationPolicy(max_history=3), KerasPolicy(max_history=3, epochs=10, batch_size=10) ] agent = Agent(domain_file, policies=policies, interpreter=interpreter, action_endpoint=action_endpoint) stories = agent.load_data(training_file) agent.train(stories) interactive.run_interactive_learning(agent, training_file) return agent if __name__ == '__main__': utils.configure_colored_logging(loglevel="INFO") interpreter = RasaNLUInterpreter('./models/current/healthbot') train_agent(interpreter)
from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter logger = logging.getLogger(__name__) def run_news_online( input_channel, interpreter, domain_def_file='./domain/domain.yml', training_data_file='./data/stories.md', ): agent = Agent(domain_def_file, policies=[MemoizationPolicy(max_history=3), KerasPolicy()], interpreter=interpreter) training_data = agent.load_data(training_data_file) agent.train_online(training_data, input_channel=input_channel, batch_size=50, epochs=200, max_training_samples=300) return agent if __name__ == '__main__': logging.basicConfig(level='INFO') nlu_interpreter = RasaNLUInterpreter('models/tour_guide/default/nlu') run_news_online(ConsoleInputChannel(), nlu_interpreter)
from klein import Klein from collections import defaultdict from datetime import datetime import json import logging from uuid import uuid4 from rasa_core.interpreter import RasaNLUInterpreter from rasa_nlu.server import check_cors from rasa_core.channels.channel import UserMessage from rasa_core.channels.channel import InputChannel, OutputChannel from rasa_core.events import SlotSet logger = logging.getLogger() nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/weathernlu') class FileMessageStore: DEFAULT_FILENAME = "message_store.json" def __init__(self, filename=DEFAULT_FILENAME): self._store = defaultdict(list) self._filename = filename try: for k, v in json.load(open(self._filename, "r")).items(): self._store[k] = v except IOError: pass def log(self, cid, username, message, uuid=None):
def load_model(project="Lambton"): interpreter = RasaNLUInterpreter('./NLU/models/default/' + project) agent = Agent.load('./Core/models/' + project + '/dialogue/', interpreter=interpreter) return agent
agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()], interpreter=interpreter, generator=None) agent.train(training_data_file, input_channel=input_channel, max_history=2, batch_size=50, epochs=200, max_training_samples=300, validation_split=0.2) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") directory = './models' for filename in os.listdir(directory): if filename.endswith(".tar.gz"): #print('FILE NAME== ',filename) tar = tarfile.open(os.path.join(directory, filename)) tar.extractall() tar.close() continue else: continue nlu_interpreter = RasaNLUInterpreter('./nlu') run_restaurant_online(CmdlineInput(), nlu_interpreter)
from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.train import interactive from rasa_core.utils import EndpointConfig logger = logging.getLogger(__name__) # checkSelfPermission def run_criminal_online(interpreter, domain_file="data/criminal_domain.yml", training_data_file='data/stories.md'): action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent(domain_file, policies=[ MemoizationPolicy(max_history=2), KerasPolicy(max_history=3, epochs=5, batch_size=50) ], interpreter=interpreter, action_endpoint=action_endpoint) data = agent.load_data(training_data_file) agent.train(data) interactive.run_interactive_learning(agent, training_data_file) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/criminalnlu') run_criminal_online(nlu_interpreter)
from rasa_core.channels.console import ConsoleInputChannel from rasa_core.interpreter import RegexInterpreter from rasa_core.policies.keras_policy import KerasPolicy from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter logger = logging.getLogger(__name__) def run_weather_online(input_channel, interpreter, domain_file="domain.yml", training_data_file='data/stories.md'): agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()], interpreter=interpreter) agent.train_online(training_data_file, input_channel=input_channel, max_history=2, batch_size=50, epochs=200, max_training_samples=300) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/customernlu') run_weather_online(ConsoleInputChannel(), nlu_interpreter)
from flask import Flask from model_manager import ModelManager from rasa_core.channels import HttpInputChannel from rasa_core.channels.facebook import FacebookInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml import os #from rasa_core.utils import EndpointConfig from rasa_core.interpreter import RegexInterpreter interpreter = RasaNLUInterpreter("models/nlu/default/current") agent = Agent.load("models\\dialogue", interpreter= interpreter) # RegexInterpreter()) input_channel = FacebookInput( fb_verify= os.eviron["VERIFY_TOKEN"], fb_secret = os.eviron["FB_SECRET"], fb_access_token = os.eviron["PAGE_ACCESS_TOKEN"]) agent.handle_channel(HttpInputChannel(input_channel))
def pretrained(): interpreter = RasaNLUInterpreter("models/nlu/default/current") agent = Agent.load("models/dialogue", interpreter=interpreter) return agent
def train(): train_nlu() train_dialogue() interpreter = RasaNLUInterpreter("models/nlu/default/current") agent = Agent.load("models/dialogue", interpreter=interpreter) return agent
from rasa_core.agent import Agent from rasa_core.policies.keras_policy import KerasPolicy from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.train import online from rasa_core.utils import EndpointConfig logger = logging.getLogger(__name__) def run_weather_online(interpreter, domain_file="domain.yml", training_data_file='data/stories.md'): action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=2), KerasPolicy()], interpreter=interpreter, action_endpoint=action_endpoint) data = agent.load_data(training_data_file) agent.train(data, batch_size=50, epochs=200, max_training_samples=600) online.serve_agent(agent) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter('./models/tracker/default/trackermodel') run_weather_online(nlu_interpreter)
from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter interpreter = RasaNLUInterpreter("./models/current/nlu") agent = Agent.load("models/dialogue", interpreter=interpreter) while True: user = input(">> ") msg = agent.handle_text(user) print(msg)
def run_weather_bot(serve_forever=True): interpreter = RasaNLUInterpreter('models/nlu/default/weathernlu') agent = Agent.load('models/dialogue', interpreter=interpreter) if serve_forever: agent.handle_channel(ConsoleInputChannel()) return agent
from rasa_core.agent import Agent from rasa_core.policies.keras_policy import KerasPolicy from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.train import interactive from rasa_core.utils import EndpointConfig def nlu_train_interactive(interpreter, domain_file="domain.yml", training_data_file='stories.md'): action_endpoint = EndpointConfig(url="http://localhost:5005/webhook") agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=2), KerasPolicy(max_history=3, epochs=3, batch_size=50)], interpreter=interpreter, action_endpoint=action_endpoint) data = agent.load_data(training_data_file) agent.train(data) interactive.run_interactive_learning(agent, training_data_file) return agent if __name__ == '__main__': nlu_interpreter = RasaNLUInterpreter('./models/test1/nlu/') nlu_train_interactive(nlu_interpreter)
from rasa_core.policies.keras_policy import KerasPolicy from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter logger = logging.getLogger(__name__) def run_weather_online(input_channel, interpreter, domain_file="exchange_domain.yml", training_data_file='data/stories.md'): agent = Agent(domain_file, policies=[MemoizationPolicy(), KerasPolicy()], interpreter=interpreter) agent.train_online(training_data_file, input_channel=input_channel, max_history=2, batch_size=50, epochs=200, max_training_samples=300) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/exchangenlu') run_weather_online(ConsoleInputChannel(), nlu_interpreter)
import logging from rasa_core.agent import Agent from rasa_core.policies.keras_policy import KerasPolicy from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.train import interactive from rasa_core.utils import EndpointConfig logger = logging.getLogger(__name__) def run_weather_online(interpreter, domain_file="sell4bidsBot_domain.yml", training_data_file='data/stories.md'): action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=2), KerasPolicy(max_history=3, epochs=3, batch_size=50)], interpreter=interpreter, action_endpoint=action_endpoint) data = agent.load_data(training_data_file) agent.train(data) interactive.run_interactive_learning(agent, training_data_file) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/sell4bidsbotnlu') run_weather_online(nlu_interpreter)
from rasa_core.channels.socketio import SocketIOInput from rasa_core.agent import Agent from rasa_core.interpreter import RegexInterpreter from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.run import serve_application import rasa_core interpreter = RasaNLUInterpreter('./models/nlu/default') agent = Agent.load('./models/dialogue', interpreter=interpreter) input_channel = SocketIOInput( # event name for messages sent from the user user_message_evt="user_uttered", # event name for messages sent from the bot bot_message_evt="bot_uttered", # socket.io namespace to use for the messages namespace=None) # set serve_forever=False if you want to keep the server running s = agent.handle_channels([input_channel], 5004, serve_forever=False) rasa_core.run.serve_application(agent, channel='socketio')
def run(serve_forever=True): interpreter = RasaNLUInterpreter('./models/nlu/default/trainedNlu') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter=interpreter, action_endpoint=action_endpoint) rasa_core.run.serve_application(agent ,channel='cmdline') return agent
def run_bot(serve_forever=True): interpreter = RasaNLUInterpreter('./models/current/nlu/') agent = Agent.load('./models/dialogue/', interpreter=interpreter) if serve_forever: agent.handle_channels([CmdlineInput()]) return agent
import logging from rasa_core.agent import Agent from rasa_core.policies.keras_policy import KerasPolicy from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.train import online logger = logging.getLogger(__name__) def run_online(interpreter,domain_file="./domain.yml",training_data_file='./backend/stories.md'): agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=2), KerasPolicy()], interpreter=interpreter) data = agent.load_data(training_data_file) agent.train(data, batch_size=50, epochs=200, max_training_samples=300) online.serve_agent(agent) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/current') run_online(nlu_interpreter)
else: request.setResponseCode(400) return json.dumps({"error": "Invalid parse parameter specified"}) try: parse_data = self.agent.start_message_handling(message, sender_id) out = CollectingOutputChannel() response_data = self.agent.handle_message(message, output_channel=out, sender_id=sender_id) response = low_confidence_filter(message, sender_id, parse_data, response_data) request.setResponseCode(200) return json.dumps(response) except Exception as e: request.setResponseCode(500) logger.error("Caught an exception during " "parse: {}".format(e), exc_info=1) return json.dumps({"error": "{}".format(e)}) if __name__ == "__main__": read_yaml() users = ConfusedUsers() filter_object = FilterServer( "models/dialogue/", RasaNLUInterpreter("models/nlu/default" "/nlu_model")) logger.info("Started http server on port %s" % 8081) filter_object.app.run("0.0.0.0", 8081)
from rasa_core.policies.memoization import MemoizationPolicy from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.train import online from rasa_core.utils import EndpointConfig logger = logging.getLogger(__name__) def run_Ogwugo_online(interpreter, domain_file="shopassistant_domain.yml", training_data_file='data/stories.md'): action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent(domain_file, policies=[MemoizationPolicy(max_history=2), KerasPolicy()], interpreter=interpreter, action_endpoint=action_endpoint) data = agent.load_data(training_data_file) agent.train(data, batch_size=50, epochs=200, max_training_samples=300) online.run_online_learning(agent) return agent if __name__ == '__main__': logging.basicConfig(level="INFO") nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/shopnlu') run_Ogwugo_online(nlu_interpreter)
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/nlu/default/travelnlu') action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load('./models/dialogue', interpreter = nlu_interpreter, action_endpoint = action_endpoint) input_channel = SlackInput('xoxb-551852374470-567879210517-sgpPTQKPlU7b2WmFdYy17ZAW') agent.handle_channels([input_channel], 5004, serve_forever=True)
from rasa_nlu.model import Metadata, Interpreter from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter interpreter = Interpreter.load('./models/nlu/default/chat') def parse_question(question): print('question:', question) print('parse:', interpreter.parse(question)) parse_question("Hey") parse_question("How many days in March") parse_question("Goodbye") def ask_question(question): print('question:', question) print('answer:', agent.handle_message(question)) rasaNLU = RasaNLUInterpreter("models/nlu/default/chat") agent = Agent.load("models/dialogue", interpreter=rasaNLU) ask_question('Hi') ask_question('How many days in January') ask_question('Bye')
from rasa_core.channels.slack import SlackInput from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter import yaml from rasa_core.utils import EndpointConfig nlu_interpreter = RasaNLUInterpreter('./models/current/nlu') action_endpoint = EndpointConfig( url="http://localhost:5005/webhooks/slack/webhook") agent = Agent.load('./models/dialogue', interpreter=nlu_interpreter, action_endpoint=action_endpoint) input_channel = SlackInput( 'xoxb-626938457776-620596434449-iaW4Ef00VtIM5oYEl7BWiHmK' #your bot user authentication token ) agent.handle_channels([input_channel], 5005, serve_forever=True)
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2' #To ignore Tensorflow AVX AVX2 bonary warning logger = logging.getLogger(__name__) speak = wincl.Dispatch("SAPI.SpVoice") nlp = spacy.load('en') phrases = [] # Declare paths domain_file = './nurse_domain.yml' model_path = './models/dialogue' interpreter_path ='./models/nursebot/interpreter' training_data_file = './data/stories.md' conf_file = './config_spacy.json action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") interpreter = RasaNLUInterpreter(interpreter_path) agent = Agent.load('./models/dialogue', interpreter=interpreter, action_endpoint=action_endpoint) # def train_dialogue(train = True,domain_file = 'nurse_domain.yml', # model_path = './models/dialogue', # training_data_file = './data/stories.md'): # if(train == True): # agent = Agent(domain_file, policies = [MemoizationPolicy(), KerasPolicy(max_history=3, epochs=200, batch_size=50)]) # data = agent.load_data(training_data_file) # agent.train(data) # agent.visualize("data/stories.md",output_file="graph.html", max_history=2) # agent.persist(model_path) # return agent # def saveDependencyGraph(phrase,saveImages = True): # phrases.append(nlp(phrase))