Skip to content

Commit 18a6d74

Browse files
committed
<BACK> - Added check connection function.
1 parent 06796c6 commit 18a6d74

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

backend/app/db.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
load_dotenv(dotenv_path=os.path.join(os.path.dirname(__file__), '..', '.env'))
1313

1414
client = MongoClient(os.getenv("MONGO_URI"))
15-
db = client.smartreply
15+
db = client.epic
1616

1717
def get_user_db(UserEmail: str):
1818
# Create collections if they don't exist
@@ -107,3 +107,10 @@ def get_records_to_process(UserEmail: str):
107107
def set_records_to_process(UserEmail: str, count: int):
108108
db[UserEmail][SETTINGS].update_one({"Email": UserEmail}, {"$set": {"Records_to_process": count}})
109109
return count
110+
111+
def get_collections():
112+
try:
113+
db.list_collection_names()
114+
return True
115+
except Exception as e:
116+
return False

backend/app/gemini_client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,11 @@ def generate_mail_class(input: list[ThreadInput], userPrompt:str, processCount:
4848

4949
response = model.generate_content(prompt)
5050
return response.text
51+
52+
def get_gemini_connection():
53+
try:
54+
genai.list_models()
55+
return True
56+
except Exception as e:
57+
return False
58+

backend/app/routes.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from fastapi import APIRouter
22
from pydantic import BaseModel
33
import time
4-
from backend.app.gemini_client import generate_mail_class
5-
from backend.app.db import save_thread, query_thread, get_stats, get_user_db, get_prompt, save_prompt, reset_stats, delete_records_by_oldest, delete_records_by_category, get_records_to_process, set_records_to_process
4+
from backend.app.gemini_client import *
5+
from backend.app.db import *
66
from backend.app.schemas import RecordInput, ThreadInput, UserData, PromptInput, DeleteInput, RecordsToProcessInput
77

88
router = APIRouter()
@@ -153,3 +153,10 @@ async def apply_records_to_process(input: RecordsToProcessInput):
153153
set_records_to_process(input.UserEmail, input.RecordsToProcess)
154154
print(f"Records to process set to {input.RecordsToProcess} for {input.UserEmail}.")
155155
return {"message": "Records to process setting applied successfully."}
156+
157+
@router.get("/get_connection")
158+
async def get_connection():
159+
if (get_collections() and get_gemini_connection()):
160+
return {"status": True}
161+
else:
162+
return {"status": False}

0 commit comments

Comments
 (0)