Update main.py
Browse files
main.py
CHANGED
@@ -34,9 +34,11 @@ from google.genai import types
|
|
34 |
|
35 |
# MongoDB Configuration
|
36 |
MONGO_PASSWORD = quote_plus(os.getenv("MONGO_PASSWORD"))
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
USER_COLLECTION = "users"
|
41 |
VIDEO_COLLECTION = "videos"
|
42 |
|
@@ -107,8 +109,8 @@ class VideoData(BaseModel):
|
|
107 |
# MongoDB connection and chat management
|
108 |
class MongoDB:
|
109 |
def __init__(self):
|
110 |
-
self.client = MongoClient(
|
111 |
-
self.db = self.client[
|
112 |
self.users = self.db[USER_COLLECTION]
|
113 |
self.videos = self.db[VIDEO_COLLECTION]
|
114 |
|
@@ -176,7 +178,7 @@ class ChatManagement:
|
|
176 |
|
177 |
# Global variables and instances
|
178 |
mongodb = MongoDB()
|
179 |
-
chat_manager = ChatManagement(
|
180 |
sessions = {} # In-memory session storage for retrievers
|
181 |
|
182 |
# Video directory for temporary storage
|
@@ -246,9 +248,9 @@ def get_llm():
|
|
246 |
Returns the language model instance (LLM) using ChatGroq API.
|
247 |
The LLM used is Llama 3.3 with a versatile 70 billion parameters model.
|
248 |
"""
|
249 |
-
api_key = os.getenv("
|
250 |
if not api_key:
|
251 |
-
raise ValueError("
|
252 |
|
253 |
llm = ChatGroq(
|
254 |
model="llama-3.3-70b-versatile",
|
|
|
34 |
|
35 |
# MongoDB Configuration
|
36 |
MONGO_PASSWORD = quote_plus(os.getenv("MONGO_PASSWORD"))
|
37 |
+
MONGO_DATABASE_NAME = os.getenv("DATABASE_NAME")
|
38 |
+
MONGO_COLLECTION_NAME = os.getenv("COLLECTION_NAME")
|
39 |
+
connection_string_template = os.getenv("CONNECTION_STRING")
|
40 |
+
MONGO_CLUSTER_URL = connection_string_template.replace("${PASSWORD}", MONGO_PASSWORD)
|
41 |
+
CHAT_COLLECTION = MONGO_COLLECTION_NAME or "chat_history"
|
42 |
USER_COLLECTION = "users"
|
43 |
VIDEO_COLLECTION = "videos"
|
44 |
|
|
|
109 |
# MongoDB connection and chat management
|
110 |
class MongoDB:
|
111 |
def __init__(self):
|
112 |
+
self.client = MongoClient(MONGO_CLUSTER_URL)
|
113 |
+
self.db = self.client[MONGO_DATABASE_NAME]
|
114 |
self.users = self.db[USER_COLLECTION]
|
115 |
self.videos = self.db[VIDEO_COLLECTION]
|
116 |
|
|
|
178 |
|
179 |
# Global variables and instances
|
180 |
mongodb = MongoDB()
|
181 |
+
chat_manager = ChatManagement(MONGO_CLUSTER_URL, MONGO_DATABASE_NAME, CHAT_COLLECTION)
|
182 |
sessions = {} # In-memory session storage for retrievers
|
183 |
|
184 |
# Video directory for temporary storage
|
|
|
248 |
Returns the language model instance (LLM) using ChatGroq API.
|
249 |
The LLM used is Llama 3.3 with a versatile 70 billion parameters model.
|
250 |
"""
|
251 |
+
api_key = os.getenv("CHATGROQ_API_KEY", "")
|
252 |
if not api_key:
|
253 |
+
raise ValueError("CHATGROQ_API_KEY environment variable not set")
|
254 |
|
255 |
llm = ChatGroq(
|
256 |
model="llama-3.3-70b-versatile",
|