Skip to content

Commit e5036fa

Browse files
committed
fix vector db error
1 parent 29b01fa commit e5036fa

18 files changed

Lines changed: 411 additions & 625 deletions

.github/workflows/ci-cd.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI/CD Pipeline
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ master ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ master ]
88

99
jobs:
1010
backend-test:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ frontend/dist/
33
node_modules/
44
__pycache__/
55
*.pyc
6-
.pytest_cache/
6+
.pytest_cache/

backend/.coverage

52 KB
Binary file not shown.

backend/app/agents/executor.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,21 @@ def ExecutorAgent(state: AgentState) -> AgentState:
4040
f"Medical Information:\n{content}\n\n"
4141
"Provide a clear, caring response in 2-4 sentences. Be professional and reassuring."
4242
)
43-
response = llm.invoke(prompt)
44-
answer = (
45-
response.content.strip()
46-
if hasattr(response, "content")
47-
else str(response).strip()
48-
)
49-
logger.info("Executor: Generated response from documents")
43+
try:
44+
response = llm.invoke(prompt)
45+
answer = (
46+
response.content.strip()
47+
if hasattr(response, "content")
48+
else str(response).strip()
49+
)
50+
logger.info("Executor: Generated response from documents")
51+
except Exception as e:
52+
logger.error("Executor: LLM generation failed: %s", str(e))
53+
answer = (
54+
"I understand your concern about your symptoms. For accurate medical advice, "
55+
"please consult with a healthcare professional who can properly evaluate your condition."
56+
)
57+
source_info = "System Message"
5058

5159
elif state.get("llm_success") and state.get("generation"):
5260
answer = state["generation"]

backend/app/agents/llm_agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def LLMAgent(state: AgentState) -> AgentState:
1414
if not llm:
1515
state["llm_success"] = False
1616
state["llm_attempted"] = True
17+
state["generation"] = "Medical AI service is temporarily unavailable."
1718
return state
1819

1920
# Build conversation context

backend/app/agents/tavily.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ def TavilyAgent(state: AgentState) -> AgentState:
2020
return state
2121

2222
search_query = f"{state['question']} medical health treatment symptoms"
23-
results = tavily.invoke(search_query)
23+
try:
24+
results = tavily.invoke(search_query)
25+
except Exception as e:
26+
logger.error("Tavily: Search failed: %s", str(e))
27+
results = []
2428

2529
valid_results = [
2630
r

backend/app/core/logging_config.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import logging
77
import os
8+
import sys
89
from datetime import datetime
910
from logging.handlers import RotatingFileHandler
1011

@@ -13,21 +14,32 @@
1314

1415
def setup_logging(log_dir: str = LOG_DIR) -> logging.Logger:
1516
"""Setup rotating file + console logging. Returns the 'medigenius' logger."""
16-
if not os.path.exists(log_dir):
17-
os.makedirs(log_dir)
18-
1917
_logger = logging.getLogger("medigenius")
20-
_logger.setLevel(logging.INFO)
2118

2219
# Avoid duplicate handlers on re-import
2320
if _logger.handlers:
2421
return _logger
2522

26-
log_file = os.path.join(
27-
log_dir, f"medigenius_{datetime.now().strftime('%Y%m%d')}.log"
28-
)
29-
file_handler = RotatingFileHandler(log_file, maxBytes=10 * 1024 * 1024, backupCount=5)
30-
file_handler.setLevel(logging.INFO)
23+
# Skip file logging if in test environment
24+
is_testing = "pytest" in sys.modules or os.getenv("TESTING") == "1"
25+
26+
if is_testing:
27+
_logger.setLevel(logging.DEBUG)
28+
else:
29+
_logger.setLevel(logging.INFO)
30+
if not os.path.exists(log_dir):
31+
os.makedirs(log_dir)
32+
33+
log_file = os.path.join(
34+
log_dir, f"medigenius_{datetime.now().strftime('%Y%m%d')}.log"
35+
)
36+
file_handler = RotatingFileHandler(log_file, maxBytes=10 * 1024 * 1024, backupCount=5)
37+
file_handler.setLevel(logging.INFO)
38+
file_handler.setFormatter(logging.Formatter(
39+
"%(asctime)s - %(name)s - %(levelname)s - %(message)s",
40+
datefmt="%Y-%m-%d %H:%M:%S",
41+
))
42+
_logger.addHandler(file_handler)
3143

3244
console_handler = logging.StreamHandler()
3345
console_handler.setLevel(logging.INFO)
@@ -36,11 +48,9 @@ def setup_logging(log_dir: str = LOG_DIR) -> logging.Logger:
3648
"%(asctime)s - %(name)s - %(levelname)s - %(message)s",
3749
datefmt="%Y-%m-%d %H:%M:%S",
3850
)
39-
file_handler.setFormatter(formatter)
4051
console_handler.setFormatter(formatter)
41-
42-
_logger.addHandler(file_handler)
4352
_logger.addHandler(console_handler)
53+
4454
return _logger
4555

4656

backend/app/models/message.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"""
55

66
from datetime import datetime
7-
from typing import Dict, Optional
7+
from typing import Dict
88

99
from sqlalchemy import Column, DateTime, Integer, String, Text
1010
from sqlalchemy.orm import declarative_base

backend/app/tools/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
from app.tools.llm_client import get_llm
77
from app.tools.pdf_loader import load_pdf, process_pdf, split_documents
88
from app.tools.tavily_search import get_tavily_search
9-
from app.tools.vector_store import get_embeddings, get_or_create_vectorstore, get_retriever
9+
from app.tools.vector_store import (
10+
get_embeddings,
11+
get_or_create_vectorstore,
12+
get_retriever,
13+
)
1014
from app.tools.wikipedia_search import get_wikipedia_wrapper
1115

1216
__all__ = [

backend/logs/medigenius_20260217.log

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)