mem0ai / mem0

The Memory layer for your AI apps
https://mem0.ai
Apache License 2.0
21.62k stars 1.97k forks source link

Issue on docs #1405

Closed jonabert closed 3 months ago

jonabert commented 3 months ago

Path: /examples/whatsapp_bot

below is the code that returns this error error:

python -m embedchain.bots.whatsapp --port 5555

:128: RuntimeWarning: 'embedchain.bots.whatsapp' found in sys.modules after import of package 'embedchain.bots', but prior to execution of 'embedchain.bots.whatsapp'; this may result in unpredictable behaviour Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/bots/whatsapp.py", line 83, in start_command() File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/bots/whatsapp.py", line 78, in start_command whatsapp_bot = WhatsAppBot() ^^^^^^^^^^^^^ File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/bots/whatsapp.py", line 25, in __init__ super().__init__() File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/bots/base.py", line 15, in __init__ self.app = App(config=AppConfig(), llm=OpenAILlm(), db=ChromaDB(), embedding_model=OpenAIEmbedder()) ^^^^^^^^^^^ File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/llm/openai.py", line 24, in __init__ super().__init__(config=config) File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/llm/base.py", line 28, in __init__ self.memory = ChatHistory() ^^^^^^^^^^^^^ File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/memory/base.py", line 16, in __init__ self.db_session = get_session() ^^^^^^^^^^^^^ File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/core/db/database.py", line 84, in get_session return database_manager.get_session() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jonathan/anaconda3/envs/embedch/lib/python3.12/site-packages/embedchain/core/db/database.py", line 40, in get_session raise RuntimeError("Session factory is not initialized. Call setup_engine() first.") RuntimeError: Session factory is not initialized. Call setup_engine() first. code: import argparse import importlib import logging import signal import sys from embedchain.helpers.json_serializable import register_deserializable from .base import BaseBot logger = logging.getLogger(__name__) @register_deserializable class WhatsAppBot(BaseBot): def __init__(self): try: self.flask = importlib.import_module("flask") self.twilio = importlib.import_module("twilio") except ModuleNotFoundError: raise ModuleNotFoundError( "The required dependencies for WhatsApp are not installed. " 'Please install with `pip install --upgrade "embedchain[whatsapp]"`' ) from None super().__init__() def handle_message(self, message): if message.startswith("add "): response = self.add_data(message) else: response = self.ask_bot(message) return response def add_data(self, message): data = message.split(" ")[-1] try: self.add(data) response = f"Added data from: {data}" except Exception: logger.exception(f"Failed to add data {data}.") response = "Some error occurred while adding data." return response def ask_bot(self, message): try: response = self.query(message) except Exception: logger.exception(f"Failed to query {message}.") response = "An error occurred. Please try again!" return response def start(self, host="0.0.0.0", port=5000, debug=True): app = self.flask.Flask(__name__) def signal_handler(sig, frame): logger.info("\nGracefully shutting down the WhatsAppBot...") sys.exit(0) signal.signal(signal.SIGINT, signal_handler) @app.route("/chat", methods=["POST"]) def chat(): incoming_message = self.flask.request.values.get("Body", "").lower() response = self.handle_message(incoming_message) twilio_response = self.twilio.twiml.messaging_response.MessagingResponse() twilio_response.message(response) return str(twilio_response) app.run(host=host, port=port, debug=debug) def start_command(): parser = argparse.ArgumentParser(description="EmbedChain WhatsAppBot command line interface") parser.add_argument("--host", default="0.0.0.0", help="Host IP to bind") parser.add_argument("--port", default=5000, type=int, help="Port to bind") args = parser.parse_args() whatsapp_bot = WhatsAppBot() whatsapp_bot.start(host=args.host, port=args.port) if __name__ == "__main__": start_command()
Dev-Khant commented 3 months ago

Hi @jonabert This PR #1401 will fix this issue.