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:
Taranjeet Singh
2024-07-12 20:21:33 +05:30
committed by GitHub
co-authored by Deshraj Yadav
parent 83e8c97295
commit f842a92e25
665 changed files with 9427 additions and 6592 deletions
@@ -0,0 +1 @@
OPENAI_API_KEY=
@@ -0,0 +1,8 @@
__pycache__
db
database
pyenv
venv
.env
trash_files/
.ideas.md
@@ -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"]
@@ -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).
@@ -0,0 +1,3 @@
Flask==2.3.2
twilio==8.5.0
embedchain
+10
View File
@@ -0,0 +1,10 @@
from embedchain.bots.whatsapp import WhatsAppBot
def main():
whatsapp_bot = WhatsAppBot()
whatsapp_bot.start()
if __name__ == "__main__":
main()
@@ -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)