Rename embedchain to mem0 and open sourcing code for long term memory (#1474)
Co-authored-by: Deshraj Yadav <deshrajdry@gmail.com>
This commit is contained in:
1
embedchain/examples/whatsapp_bot/.env.example
Normal file
1
embedchain/examples/whatsapp_bot/.env.example
Normal file
@@ -0,0 +1 @@
|
||||
OPENAI_API_KEY=
|
||||
8
embedchain/examples/whatsapp_bot/.gitignore
vendored
Normal file
8
embedchain/examples/whatsapp_bot/.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
__pycache__
|
||||
db
|
||||
database
|
||||
pyenv
|
||||
venv
|
||||
.env
|
||||
trash_files/
|
||||
.ideas.md
|
||||
11
embedchain/examples/whatsapp_bot/Dockerfile
Normal file
11
embedchain/examples/whatsapp_bot/Dockerfile
Normal file
@@ -0,0 +1,11 @@
|
||||
FROM python:3.11-slim
|
||||
|
||||
WORKDIR /usr/src/
|
||||
COPY requirements.txt .
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
CMD ["python", "whatsapp_bot.py"]
|
||||
3
embedchain/examples/whatsapp_bot/README.md
Normal file
3
embedchain/examples/whatsapp_bot/README.md
Normal file
@@ -0,0 +1,3 @@
|
||||
# WhatsApp Bot
|
||||
|
||||
This is a replit template to create your own WhatsApp bot using the embedchain package. To know more about the bot and how to use it, go [here](https://docs.embedchain.ai/examples/whatsapp_bot).
|
||||
3
embedchain/examples/whatsapp_bot/requirements.txt
Normal file
3
embedchain/examples/whatsapp_bot/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
Flask==2.3.2
|
||||
twilio==8.5.0
|
||||
embedchain
|
||||
10
embedchain/examples/whatsapp_bot/run.py
Normal file
10
embedchain/examples/whatsapp_bot/run.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from embedchain.bots.whatsapp import WhatsAppBot
|
||||
|
||||
|
||||
def main():
|
||||
whatsapp_bot = WhatsAppBot()
|
||||
whatsapp_bot.start()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
51
embedchain/examples/whatsapp_bot/whatsapp_bot.py
Normal file
51
embedchain/examples/whatsapp_bot/whatsapp_bot.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from flask import Flask, request
|
||||
from twilio.twiml.messaging_response import MessagingResponse
|
||||
|
||||
from embedchain import App
|
||||
|
||||
app = Flask(__name__)
|
||||
chat_bot = App()
|
||||
|
||||
|
||||
@app.route("/chat", methods=["POST"])
|
||||
def chat():
|
||||
incoming_message = request.values.get("Body", "").lower()
|
||||
response = handle_message(incoming_message)
|
||||
twilio_response = MessagingResponse()
|
||||
twilio_response.message(response)
|
||||
return str(twilio_response)
|
||||
|
||||
|
||||
def handle_message(message):
|
||||
if message.startswith("add "):
|
||||
response = add_sources(message)
|
||||
else:
|
||||
response = query(message)
|
||||
return response
|
||||
|
||||
|
||||
def add_sources(message):
|
||||
message_parts = message.split(" ", 2)
|
||||
if len(message_parts) == 3:
|
||||
data_type = message_parts[1]
|
||||
url_or_text = message_parts[2]
|
||||
try:
|
||||
chat_bot.add(data_type, url_or_text)
|
||||
response = f"Added {data_type}: {url_or_text}"
|
||||
except Exception as e:
|
||||
response = f"Failed to add {data_type}: {url_or_text}.\nError: {str(e)}"
|
||||
else:
|
||||
response = "Invalid 'add' command format.\nUse: add <data_type> <url_or_text>"
|
||||
return response
|
||||
|
||||
|
||||
def query(message):
|
||||
try:
|
||||
response = chat_bot.chat(message)
|
||||
except Exception:
|
||||
response = "An error occurred. Please try again!"
|
||||
return response
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app.run(host="0.0.0.0", port=8000, debug=False)
|
||||
Reference in New Issue
Block a user