Skip to content

Instantly share code, notes, and snippets.

@itsromiljain
Created April 1, 2019 03:53
Show Gist options
  • Save itsromiljain/44e738cd8712ea990fadc325a475e756 to your computer and use it in GitHub Desktop.
Save itsromiljain/44e738cd8712ea990fadc325a475e756 to your computer and use it in GitHub Desktop.
Python file for Training and Running Rasa Core
import logging
from rasa_core import config
from rasa_core import utils
from rasa_core.agent import Agent
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.utils import EndpointConfig
logfile = 'dialogue_model.log'
def train_core(domain_file, model_path, training_data_file, policy_config):
logging.basicConfig(filename=logfile, level=logging.DEBUG)
agent = Agent(domain_file, policies=config.load(policy_config))
training_data = agent.load_data(training_data_file)
agent.train(training_data)
agent.persist(model_path)
return agent
def run_core(core_model_path, nlu_model_path, action_endpoint_url):
logging.basicConfig(filename=logfile, level=logging.DEBUG)
nlu_interpreter = RasaNLUInterpreter(nlu_model_path)
action_endpoint = EndpointConfig(url=action_endpoint_url)
agent = Agent.load(core_model_path, interpreter=nlu_interpreter, action_endpoint=action_endpoint)
print("Your bot is ready to talk! Type your messages here or send 'stop'")
while True:
a = input()
if a == 'stop':
break
responses = agent.handle_text(a)
for response in responses:
print(response["text"])
return agent
if __name__ == '__main__':
actionConfig = utils.read_yaml_file('endpoints.yml')
train_core('domain.yml', './models/dialogue', './data/stories.md', 'policy.yml')
run_core('./models/dialogue', './models/current/nlu',
actionConfig["action_endpoint"]["url"])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment