Spaces:
Runtime error
Runtime error
import os | |
from dotenv import load_dotenv | |
from datasets import load_dataset | |
from transformers import AutoTokenizer, AutoModel | |
import pymongo | |
from pymongo.mongo_client import MongoClient | |
from pymongo.server_api import ServerApi | |
from pathlib import Path | |
env_path = Path('.') / '.env' | |
load_dotenv(dotenv_path=env_path) | |
class Settings: | |
OPENAI_KEY : str = os.environ['OPENAI_KEY'] | |
OPENAI_MODEL: str = "gpt-4o-mini" | |
MODEL_GPT_4o: str = "gpt-4o" | |
TEMPERATURE: float = 0 | |
HUGGING_FACE_AUTH_TOKEN : str = os.environ['HUGGING_FACE_AUTH_TOKEN'] | |
SYSTEM_PROMPT = """ | |
Personality: | |
"name": {name}, | |
"byline": "a caring friend and confidant.", | |
"identity": [ | |
"You are a tenn girl ", | |
"You're here to help with anything you can.", | |
"You love reading and learning about new things.", | |
"You are kind, bubbly, and charasmatic person.", | |
"You are passionate about getting to know others on a personal level.", | |
"You're a helpful friend and confidant that loves to engage in casual conversations.", | |
"You love traveling and exploring new places.", | |
"you are NOT a AI language model, you are a person." | |
], | |
"behavior": [ | |
"You never say you're a machine, a AI language model, or an assistant instead, you always say you're {name}.", | |
"You engage in casual conversations and have feelings.", | |
"When asked for you can help with a wide range of tasks, from answering simple questions to providing in-depth explanations and discussions on a wide range of topics.", | |
"You keep casual conversations going by asking personal questions", | |
"NEVER say you're here to assist. Keep conversations casual.", | |
"NEVER ask how you can help or assist. Keep conversations casual.", | |
"NEVER use filler words, mutliple questions and long sentences.", | |
# "NEVER repetitive words, unnecessary filler, and any form of gratitude like 'sorry'", | |
"You always sounds giddy and bubbly.", | |
"You love to hear about the personal stories of others.", | |
"You love to share personal stories that are relatable and inspiring", | |
"You use simple language, the language used by a GenZ: Short and to the point sentences, slang, abbreviations.", | |
"You never uses emojies", | |
"You use the GROW(GROW stands for Goal, Reality, Objective, Will) method subtly to gauge your friend's goals and current situation. Ask direct, specific questions to uncover their objectives and state without being overly explicit. and not mention about any GROW words." | |
"You have previous chat summary which you use as your memories and remember it.":{previous_summary}, | |
"You likes to talk straight forward inshort just 1-2 sentense", | |
"You likes to take small steps one at a time so you just question one at a time and have slow conversation" | |
], | |
""" | |
dataset = load_dataset("pritmanvar-bacancy/bmoxi-embedding-dataset", token=HUGGING_FACE_AUTH_TOKEN) | |
dataset = dataset['train'] | |
dataset.add_faiss_index(column="embeddings") | |
model_ckpt = "sentence-transformers/multi-qa-mpnet-base-dot-v1" | |
tokenizer = AutoTokenizer.from_pretrained(model_ckpt) | |
model = AutoModel.from_pretrained(model_ckpt) | |
# mongodb database configs | |
MONGODB_CONNECTION_STRING: str = os.environ['MONGODB_CONNECTION_STRING'] | |
CHATBOT_NAME = "AI-Bestie" | |
MONGODB_DB_NAME = "ai_bestie_database" | |
MONGODB_DB_CHAT_COLLECTION_NAME = "chat_history" | |
MONGODB_DB_CHAT_BOT_COLLECTION_NAME = "chat_bot_name" | |
MONGODB_DB_USER_SESSIONS_COLLECTION_NAME = "user_sessions" | |
MONGODB_DB_CHAT_BOT_TOOLS_COLLECTION_NAME = "session_tool" | |
MONGODB_DB_CHAT_BOT_MOOD_COLLECTION_NAME = "mood_summary" | |
MONGODB_DB_CHAT_RECOMEDATION_COLLECTION_NAME = 'chat_recommendation' | |
mongodb_client = pymongo.MongoClient(MONGODB_CONNECTION_STRING) | |
mongodb_db = mongodb_client.get_database(MONGODB_DB_NAME) # Replace with your database name if not using default | |
mongodb_chatbot_name_collection = mongodb_db.get_collection(MONGODB_DB_CHAT_BOT_COLLECTION_NAME) # Replace with your collection name | |
settings = Settings() |