def __init__(self): """ Se generan los trackers y se asocian a agentes ambos para ingles y espanol """ with open(r'parameters.conf', encoding="utf-8") as f: datos = json.load(f) self.track_store = MongoTrackerStore( domain=Domain.load("../Jarvis/domain.yml"), host=datos['url'], db=datos['db'], username=datos['username'], password=datos['password']) self.track_store_en = MongoTrackerStore( domain=Domain.load("../Jarvis/domain_en.yml"), host=datos['url'], db=datos['db'], username=datos['username'], password=datos['password']) action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") self.agent = Agent.load( '../Jarvis/models/latest.tar.gz', action_endpoint=action_endpoint, tracker_store=self.track_store, ) self.agent_en = Agent.load( '../Jarvis/models/latest_en.tar.gz', action_endpoint=action_endpoint, tracker_store=self.track_store_en, )
def get_tracker_and_domain(bot: Text): domain = ChatHistory.mongo_processor.load_domain(bot) endpoint = ChatHistory.mongo_processor.get_endpoints(bot) tracker = MongoTrackerStore(domain=domain, host=endpoint['tracker_endpoint']['url'], db=endpoint['tracker_endpoint']['db'], username=endpoint['tracker_endpoint'].get("username"), password=endpoint['tracker_endpoint'].get("password")) return (domain, tracker)
def get_local_mongo_store(bot: Text, domain: Domain): "create local mongo tracker" db_url = Utility.environment['mongo_url'] db_name = Utility.environment['test_conversation_db'] username, password, url = Utility.extract_user_password(db_url) return MongoTrackerStore(domain=domain, host=url, db=db_name, collection=bot, username=username, password=password)
async def on_trynow(self, request): res_data = await request.json() print("----------- Inside Try now --from SID {}--------------".format(res_data['sessionId'])) result = await ExportProject.main(res_data['sessionId'], res_data['projectObjectId'], 'SESSION') print(result) if result is not None: return web.json_response({"status": "Error", "message": result}) import rasa.model as model from rasa.core.agent import Agent from rasa.core.tracker_store import MongoTrackerStore from rasa.core.domain import Domain from rasa.train import train_async from rasa.utils.endpoints import EndpointConfig base_path = CONFIG.get('api_gateway', 'SESSION_MODEL_PATH') config = "config.yml" training_files = "data/" domain = "domain.yml" output = "models/" endpoints = EndpointConfig(url="http://action_server:5055/webhook") base_path = base_path + res_data['sessionId'] + "/" config = base_path + config training_files = base_path + training_files domain = base_path + domain output = base_path + output start_time = time.time() try: model_path = await train_async(domain, config, [training_files], output, additional_arguments={"augmentation_factor": 10}) end_time = time.time() print("it took this long to run: {}".format(end_time - start_time)) unpacked = model.get_model(model_path) domain = Domain.load(domain) _tracker_store = MongoTrackerStore(domain=domain, host=CONFIG.get('api_gateway', 'MONGODB_URL'), db=CONFIG.get('api_gateway', 'MONGODB_NAME'), username=None, password=None, auth_source="admin", collection="conversations", event_broker=None) print("*************** Actions Endpoint as per data ********** {}".format(endpoints.url)) self.agent = Agent.load(unpacked, tracker_store=_tracker_store, action_endpoint=endpoints) return web.json_response({"status": "Success", "message": "Ready to chat"}) #await sio.emit('chatResponse', {"status": "Success", "message": "Ready to chat"}, namespace='/trynow', room=sid) except Exception as e: print("Exception while try Now --- "+str(e)) #await sio.emit('chatResponse', {"status": "Error", "message": repr(e)}, namespace='/trynow', room=sid) return web.json_response({"status": "Error", "message": repr(e)})
def get_tracker_and_domain(bot: Text): """ Returns the Mongo Tracker and Domain of the bot """ domain = ChatHistory.mongo_processor.load_domain(bot) try: endpoint = ChatHistory.mongo_processor.get_endpoints(bot) tracker = MongoTrackerStore( domain=domain, host=endpoint["tracker_endpoint"]["url"], db=endpoint["tracker_endpoint"]["db"], username=endpoint["tracker_endpoint"].get("username"), password=endpoint["tracker_endpoint"].get("password"), ) except Exception: tracker = Utility.get_local_mongo_store(bot, domain) return (domain, tracker)
def get_local_mongo_store(bot: Text, domain: Domain): """ create local mongo tracker :param bot: bot id :param domain: domain data :return: mongo tracker """ username, password, url, db_name = Utility.get_local_db() return MongoTrackerStore( domain=domain, host=url, db=db_name, collection=bot, username=username, password=password, )
def get_local_mongo_store(bot: Text, domain): """ create local mongo tracker :param bot: bot id :param domain: domain data :return: mongo tracker """ from rasa.core.tracker_store import MongoTrackerStore config = Utility.get_local_db() return MongoTrackerStore( domain=domain, host=config['host'], db=config['db'], collection=bot, username=config.get('username'), password=config.get('password'), auth_source=config['options'].get("authSource") if config['options'].get("authSource") else "admin")
def get_tracker_and_domain(bot: Text): """ loads domain data and mongo tracker :param bot: bot id :return: tuple domain, tracker """ domain = ChatHistory.mongo_processor.load_domain(bot) message = None try: endpoint = ChatHistory.mongo_processor.get_endpoints(bot) tracker = MongoTrackerStore( domain=domain, host=endpoint["tracker_endpoint"]["url"], db=endpoint["tracker_endpoint"]["db"], username=endpoint["tracker_endpoint"].get("username"), password=endpoint["tracker_endpoint"].get("password"), ) except Exception as e: logger.info(e) message = "Loading test conversation! " + str(e) tracker = Utility.get_local_mongo_store(bot, domain) return domain, tracker, message
def get_tracker_and_domain_data(self, *args, **kwargs): domain = Domain.from_file("tests/testing_data/initial/domain.yml") return domain, MongoTrackerStore( domain, host="mongodb://192.168.100.140:27169"), None
def __init__(self): from rasa.core.tracker_store import (TrackerStore, InMemoryTrackerStore, MongoTrackerStore) default_domain = get_default_domain() self.tracker_store = MongoTrackerStore(domain=default_domain)
import logging from logs import LogHandler from config import ConfigManager as CM # setup logging ErrorLogger = logging.getLogger("ErrorLogs") InfoLogger = logging.getLogger("InfoLogs") LogHandler.setup_logging() domain = Domain.load('domain.yml') modelPath = CM.rasa_model_path action_endpoint = EndpointConfig(url="http://localhost:5055/webhook") agent = Agent.load(str(modelPath), action_endpoint=action_endpoint, tracker_store=MongoTrackerStore(domain=domain)) async def parse(text, senderId): global agent response = await agent.handle_text(text, sender_id=senderId) return response def get_bot_response(userMsg, senderId): response = None if agent.is_ready(): loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) response = loop.run_until_complete(parse(userMsg, senderId)) InfoLogger.info("BOT RESPONSE ::: " + str(response))
def get_tracker_and_domain_data(self, *args, **kwargs): domain = Domain.from_file("tests/testing_data/initial/domain.yml") return domain, MongoTrackerStore(domain, host="mongodb://localhost:27019")
# Load all send methods classes message_exec.load() config = load_config() host, port = '0.0.0.0', config['websocket']['port'] dashlog = Tracker(config['dashbot']['api'], config['dashbot'][config["template"]["module"]]['api_key']) action_endpoint = EndpointConfig(url=config['server']['actions_endpoint']) nlg_endpoint = EndpointConfig(url=config['server']['nlg_endpoint']) domain = Domain.load('domain.yml') db_conf = config['bluelog'] mongo_tracker = MongoTrackerStore(domain, host=db_conf['host'], db=db_conf['db'], username=db_conf['username'], password=db_conf['password'], auth_source=db_conf['authsource'], collection=config['template']['module']) agent_all = {} try: if os.path.isdir('./models/nlu'): if os.path.isdir('./models/nlu/idn'): nlu_interpreter_idn = RasaNLUInterpreter('./models/nlu/idn/') agent_idn = Agent.load('./models/core/core.tar.gz', interpreter=nlu_interpreter_idn, action_endpoint=action_endpoint, generator=nlg_endpoint, tracker_store=mongo_tracker)