From 6054b313c9a5c52fa4a7aa27b5a660ae6e4dd60a Mon Sep 17 00:00:00 2001 From: Abhi <85984486+AbhiTheModder@users.noreply.github.com> Date: Sun, 14 Apr 2024 08:58:19 +0000 Subject: [PATCH] Add cohere(Coral) Ai support --- install.sh | 12 +++++++++++- install_yum.sh | 12 +++++++++++- termux-install.sh | 12 +++++++++++- utils/config.py | 1 + utils/db.py | 16 ++++++++++++++++ 5 files changed, 50 insertions(+), 3 deletions(-) diff --git a/install.sh b/install.sh index 02ba8ef..318260c 100644 --- a/install.sh +++ b/install.sh @@ -86,7 +86,16 @@ echo "You can get it here -> https://makersuite.google.com/app/apikey" read -r -p "GEMINI_KEY > " gemini_key if [[ $gemini_key = "" ]]; then - echo "NOTE: API Not set you'll not be able to use AI modules" + echo "NOTE: API Not set you'll not be able to use Gemini AI modules" +fi + +echo +echo "Enter COHERE_KEY if you want to use AI" +echo "You can get it here -> https://dashboard.cohere.com/api-keys" +read -r -p "COHERE_KEY > " cohere_key + +if [[ $cohere_key = "" ]]; then + echo "NOTE: API Not set you'll not be able to use Coral AI modules" fi echo @@ -151,6 +160,7 @@ RMBG_KEY=${rmbg_key} VT_KEY=${vt_key} GEMINI_KEY=${gemini_key} VCA_API_KEY=${vca_api_key} +COHERE_KEY=${cohere_key} PM_LIMIT=${pm_limit} EOL diff --git a/install_yum.sh b/install_yum.sh index 2f05f61..bacef1c 100644 --- a/install_yum.sh +++ b/install_yum.sh @@ -79,7 +79,16 @@ echo "You can get it here -> https://makersuite.google.com/app/apikey" read -r -p "GEMINI_KEY > " gemini_key if [[ $gemini_key = "" ]]; then - echo "NOTE: API Not set you'll not be able to use AI modules" + echo "NOTE: API Not set you'll not be able to use Gemini AI modules" +fi + +echo +echo "Enter COHERE_KEY if you want to use AI" +echo "You can get it here -> https://dashboard.cohere.com/api-keys" +read -r -p "COHERE_KEY > " cohere_key + +if [[ $cohere_key = "" ]]; then + echo "NOTE: API Not set you'll not be able to use Coral AI modules" fi echo @@ -142,6 +151,7 @@ APIFLASH_KEY=${apiflash_key} RMBG_KEY=${rmbg_key} VT_KEY=${vt_key} GEMINI_KEY=${gemini_key} +COHERE_KEY=${cohere_key} VCA_API_KEY=${vca_api_key} EOL diff --git a/termux-install.sh b/termux-install.sh index 7fa0504..389fdeb 100644 --- a/termux-install.sh +++ b/termux-install.sh @@ -75,7 +75,16 @@ echo "You can get it here -> https://makersuite.google.com/app/apikey" read -r -p "GEMINI_KEY > " gemini_key if [[ $gemini_key = "" ]]; then - echo "NOTE: API Not set you'll not be able to use AI modules" + echo "NOTE: API Not set you'll not be able to use Gemini AI modules" +fi + +echo +echo "Enter COHERE_KEY if you want to use AI" +echo "You can get it here -> https://dashboard.cohere.com/api-keys" +read -r -p "COHERE_KEY > " cohere_key + +if [[ $cohere_key = "" ]]; then + echo "NOTE: API Not set you'll not be able to use Coral AI modules" fi echo @@ -130,6 +139,7 @@ APIFLASH_KEY=${apiflash_key} RMBG_KEY=${rmbg_key} VT_KEY=${vt_key} GEMINI_KEY=${gemini_key} +COHERE_KEY=${cohere_key} VCA_API_KEY=${vca_api_key} PM_LIMIT=${pm_limit} EOL diff --git a/utils/config.py b/utils/config.py index 636502d..e58e482 100644 --- a/utils/config.py +++ b/utils/config.py @@ -21,6 +21,7 @@ rmbg_key = os.getenv("RMBG_KEY", env.str("RMBG_KEY")) vt_key = os.getenv("VT_KEY", env.str("VT_KEY")) gemini_key = os.getenv("GEMINI_KEY", env.str("GEMINI_KEY")) vca_api_key = os.getenv("VCA_API_KEY", env.str("VCA_API_KEY")) +cohere_key = os.getenv("COHERE_KEY", env.str("COHERE_KEY")) pm_limit = int(os.getenv("PM_LIMIT", env.int("PM_LIMIT"))) diff --git a/utils/db.py b/utils/db.py index 0787aa1..8fc1a0d 100644 --- a/utils/db.py +++ b/utils/db.py @@ -70,6 +70,14 @@ class MongoDatabase(Database): def close(self): self._client.close() + def add_chat_history(self, message): + chat_history = db.get("core.cohere", "chat_history", default=[]) + chat_history.append(message) + db.set("core.cohere", "chat_history", chat_history) + + def get_chat_history(self): + return db.get("core.cohere", "chat_history", default=[]) + class SqliteDatabase(Database): def __init__(self, file): @@ -163,6 +171,14 @@ class SqliteDatabase(Database): self._conn.commit() self._conn.close() + def add_chat_history(self, message): + chat_history = db.get("core.cohere", "chat_history", default=[]) + chat_history.append(message) + db.set("core.cohere", "chat_history", chat_history) + + def get_chat_history(self): + return db.get("core.cohere", "chat_history", default=[]) + if config.db_type in ["mongo", "mongodb"]: db = MongoDatabase(config.db_url, config.db_name)