I build custom Redis and InMemory trackers that change the max_event_history variable based off this article Using a custom tracker store to manage max event history in RASA. | by Simran Kaur Kahlon | Gray Matrix | Medium. They all worked just fine. So I want to do the same for the Postgres version.
When I attempted the Postgres version it did not work for me. Here are my endpoints:
tracker_store: type: myTracker.MyTrackerStore dialect: "postgresql" # the dialect used to interact with the db url: "localhost" port: 5432 db: "mydb" # path to your db username: "post" password: "post" # password used for authentication action_endpoint: url: "http://localhost:5055/webhook"
Here is my custom tracker. I basically copy the sqlTracker class definition (from https://github.com/RasaHQ/rasa/blob/a4ee09c41e3f173c3aa9e7df69d3f0f727eeb61d/rasa/core/tracker_store.py) and add in the max_event_history value.
class MyTrackerStore(SQLTrackerStore): """Store which can save and retrieve trackers from an SQL database.""" def __init__( self, domain: Optional[Domain] = None, dialect: Text = "sqlite", host: Optional[Text] = None, port: Optional[int] = None, db: Text = "rasa.db", username: Text = None, password: Text = None, event_broker: Optional[EventBroker] = None, login_db: Optional[Text] = None, query: Optional[Dict] = None, **kwargs: Dict[Text, Any], ) -> None: self.max_event_history = 20 import sqlalchemy.exc engine_url = self.get_db_url( dialect, host, port, db, username, password, login_db, query ) self.engine = sa.create_engine(engine_url, **create_engine_kwargs(engine_url)) logger.debug( f"Attempting to connect to database via '{repr(self.engine.url)}'." ) # Database might take a while to come up while True: try: # if `login_db` has been provided, use current channel with # that database to create working database `db` if login_db: self._create_database_and_update_engine(db, engine_url) try: self.Base.metadata.create_all(self.engine) except ( sqlalchemy.exc.OperationalError, sqlalchemy.exc.ProgrammingError, ) as e: # Several Rasa services started in parallel may attempt to # create tables at the same time. That is okay so long as # the first services finishes the table creation. logger.error(f"Could not create tables: {e}") self.sessionmaker = sa.orm.session.sessionmaker(bind=self.engine) break except ( sqlalchemy.exc.OperationalError, sqlalchemy.exc.IntegrityError, ) as error: logger.warning(error) sleep(5) logger.debug(f"Connection to SQL database '{db}' successful.") # super().__init__(domain, event_broker, **kwargs)
You can see that super().init is commented out. When I had it in the code, it was giving me an error of:
TypeError: argument of type ‘NoneType’ is not iterable
Anyway, the error that I get when I initiate the rasa server locally, with the code from above is the following:
2021-08-04 20:14:35 DEBUG rasa.nlu.classifiers.diet_classifier - Failed to load model for 'ResponseSelector'. Maybe you did not provide enough training data and no model was trained or the path '/tmp/tmpsikts5ku/nlu' doesn't exist? 2021-08-04 20:14:35 DEBUG myTracker - Attempting to connect to database via 'postgresql://postgres:***@localhost:5432/mydb'. 2021-08-04 20:14:35 DEBUG myTracker - Connection to SQL database 'mydb' successful. 2021-08-04 20:14:35 DEBUG rasa.core.tracker_store - Connected to MyTrackerStore. 2021-08-04 20:14:35 DEBUG rasa.core.lock_store - Connected to lock store 'InMemoryLockStore'. 2021-08-04 20:14:36 DEBUG rasa.model - Extracted model to '/tmp/tmpbbh6eqan'. 2021-08-04 20:14:36 DEBUG rasa.utils.tensorflow.models - Loading the model from /tmp/tmpbbh6eqan/core/policy_1_TEDPolicy/ted_policy.tf_model with finetune_mode=False... 2021-08-04 20:14:43 DEBUG rasa.utils.tensorflow.models - Finished loading the model. 2021-08-04 20:14:43 DEBUG rasa.core.nlg.generator - Instantiated NLG to 'TemplatedNaturalLanguageGenerator'. 2021-08-04 20:14:43 ERROR rasa.core.agent - Could not load model due to 'MyTrackerStore' object has no attribute 'event_broker'. /home/my_test/venv/lib/python3.6/site-packages/rasa/shared/utils/io.py:96: UserWarning: The model at 'models' could not be loaded. Error: <class 'AttributeError'>: 'MyTrackerStore' object has no attribute 'event_broker' /home/my_test/venv/lib/python3.6/site-packages/rasa/shared/utils/io.py:96: UserWarning: Agent could not be loaded with the provided configuration. Load default agent without any model. 2021-08-04 20:14:43 DEBUG rasa.core.nlg.generator - Instantiated NLG to 'TemplatedNaturalLanguageGenerator'. [2021-08-04 20:14:43 +0000] [27810] [ERROR] Experienced exception while trying to serve Traceback (most recent call last): File "/home/my_test/venv/lib/python3.6/site-packages/sanic/app.py", line 1129, in run serve(**server_settings) File "/home/my_test/venv/lib/python3.6/site-packages/sanic/server.py", line 888, in serve trigger_events(before_start, loop) File "/home/my_test/venv/lib/python3.6/site-packages/sanic/server.py", line 696, in trigger_events loop.run_until_complete(result) File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/run.py", line 289, in load_agent_on_start remote_storage=remote_storage, File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/agent.py", line 365, in __init__ self.tracker_store = self.create_tracker_store(tracker_store, self.domain) File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/agent.py", line 869, in create_tracker_store return FailSafeTrackerStore(tracker_store) File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/tracker_store.py", line 1160, in __init__ super().__init__(tracker_store.domain, tracker_store.event_broker) AttributeError: 'MyTrackerStore' object has no attribute 'event_broker' Traceback (most recent call last): File "/home/my_test/venv/bin/rasa", line 8, in <module> sys.exit(main()) File "/home/my_test/venv/lib/python3.6/site-packages/rasa/__main__.py", line 116, in main cmdline_arguments.func(cmdline_arguments) File "/home/my_test/venv/lib/python3.6/site-packages/rasa/cli/run.py", line 90, in run rasa.run(**vars(args)) File "/home/my_test/venv/lib/python3.6/site-packages/rasa/run.py", line 57, in run **kwargs, File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/run.py", line 226, in serve_application workers=number_of_workers, File "/home/my_test/venv/lib/python3.6/site-packages/sanic/app.py", line 1129, in run serve(**server_settings) File "/home/my_test/venv/lib/python3.6/site-packages/sanic/server.py", line 888, in serve trigger_events(before_start, loop) File "/home/my_test/venv/lib/python3.6/site-packages/sanic/server.py", line 696, in trigger_events loop.run_until_complete(result) File "uvloop/loop.pyx", line 1456, in uvloop.loop.Loop.run_until_complete File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/run.py", line 289, in load_agent_on_start remote_storage=remote_storage, File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/agent.py", line 365, in __init__ self.tracker_store = self.create_tracker_store(tracker_store, self.domain) File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/agent.py", line 869, in create_tracker_store return FailSafeTrackerStore(tracker_store) File "/home/my_test/venv/lib/python3.6/site-packages/rasa/core/tracker_store.py", line 1160, in __init__ super().__init__(tracker_store.domain, tracker_store.event_broker) AttributeError: 'MyTrackerStore' object has no attribute 'event_broker' 2021-08-04 20:14:43 DEBUG urllib3.connectionpool - Starting new HTTPS connection (1): o251570.ingest.sentry.io:443 2021-08-04 20:14:43 DEBUG urllib3.connectionpool - https://o251570.ingest.sentry.io:443 "POST /api/2801673/store/ HTTP/1.1" 200 41
I have not done anything more in the other custom tracker versions regarding the ‘event_broker’. I am quite lost. Does anyone have any ideas? Thank you in advance.