Srushti-Kamble commited on
Commit
89cfd9a
·
1 Parent(s): a15319b

backend ci fixed

Browse files
.github/workflows/ci.yml CHANGED
@@ -48,16 +48,18 @@ jobs:
48
  env:
49
  SECRET_KEY: ci-dummy-secret
50
  DATABASE_URL: sqlite:///./ci_test.db
 
51
  HF_TOKEN: ci-dummy-token
52
  UPLOAD_DIR: /tmp/uploads
53
  CHROMA_PERSIST_DIR: /tmp/chroma
54
  run: |
55
- python -c "import sys; sys.path.insert(0, 'backend'); from app.config import settings; print('Config imports OK')" || true
56
 
57
  - name: Run backend pytest suite
58
  env:
59
  SECRET_KEY: ci-dummy-secret
60
  DATABASE_URL: sqlite:///./ci_test.db
 
61
  HF_TOKEN: ci-dummy-token
62
  UPLOAD_DIR: /tmp/uploads
63
  CHROMA_PERSIST_DIR: /tmp/chroma
 
48
  env:
49
  SECRET_KEY: ci-dummy-secret
50
  DATABASE_URL: sqlite:///./ci_test.db
51
+ DEBUG: "false"
52
  HF_TOKEN: ci-dummy-token
53
  UPLOAD_DIR: /tmp/uploads
54
  CHROMA_PERSIST_DIR: /tmp/chroma
55
  run: |
56
+ python -c "import sys; sys.path.insert(0, 'backend'); from app.config import get_settings; get_settings(); print('Config imports OK')"
57
 
58
  - name: Run backend pytest suite
59
  env:
60
  SECRET_KEY: ci-dummy-secret
61
  DATABASE_URL: sqlite:///./ci_test.db
62
+ DEBUG: "false"
63
  HF_TOKEN: ci-dummy-token
64
  UPLOAD_DIR: /tmp/uploads
65
  CHROMA_PERSIST_DIR: /tmp/chroma
backend/app/routes/chat.py CHANGED
@@ -29,6 +29,28 @@ logger = logging.getLogger(__name__)
29
  router = APIRouter(prefix="/chat", tags=["Chat"])
30
 
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
  @router.post("/ask", response_model=ChatResponse)
33
  @limiter.limit("10/minute")
34
  def ask_question(
@@ -82,9 +104,6 @@ def ask_question(
82
  detail=f"Document is still {doc.status}. Please wait for processing to complete.",
83
  )
84
 
85
- # Generate answer
86
- from app.rag.agent import generate_answer
87
-
88
  result = generate_answer(
89
  question=payload.question,
90
  user_id=user.id,
@@ -174,8 +193,6 @@ def ask_question_stream(
174
  sources = []
175
 
176
  try:
177
- from app.rag.agent import generate_answer_stream
178
-
179
  for chunk in generate_answer_stream(
180
  question=payload.question,
181
  user_id=user.id,
 
29
  router = APIRouter(prefix="/chat", tags=["Chat"])
30
 
31
 
32
+ def generate_answer(question: str, user_id: str, document_id: Optional[str] = None):
33
+ """Import the RAG agent lazily so route tests can patch this boundary."""
34
+ from app.rag.agent import generate_answer as _generate_answer
35
+
36
+ return _generate_answer(
37
+ question=question,
38
+ user_id=user_id,
39
+ document_id=document_id,
40
+ )
41
+
42
+
43
+ def generate_answer_stream(question: str, user_id: str, document_id: Optional[str] = None):
44
+ """Import the streaming RAG agent lazily so route tests can patch this boundary."""
45
+ from app.rag.agent import generate_answer_stream as _generate_answer_stream
46
+
47
+ return _generate_answer_stream(
48
+ question=question,
49
+ user_id=user_id,
50
+ document_id=document_id,
51
+ )
52
+
53
+
54
  @router.post("/ask", response_model=ChatResponse)
55
  @limiter.limit("10/minute")
56
  def ask_question(
 
104
  detail=f"Document is still {doc.status}. Please wait for processing to complete.",
105
  )
106
 
 
 
 
107
  result = generate_answer(
108
  question=payload.question,
109
  user_id=user.id,
 
193
  sources = []
194
 
195
  try:
 
 
196
  for chunk in generate_answer_stream(
197
  question=payload.question,
198
  user_id=user.id,
backend/tests/conftest.py CHANGED
@@ -16,11 +16,12 @@ BACKEND_DIR = ROOT / "backend"
16
  if str(BACKEND_DIR) not in sys.path:
17
  sys.path.insert(0, str(BACKEND_DIR))
18
 
19
- os.environ.setdefault("SECRET_KEY", "test-secret-key")
20
- os.environ.setdefault("DATABASE_URL", "sqlite:///./test_bootstrap.db")
21
- os.environ.setdefault("HF_TOKEN", "test-hf-token")
22
- os.environ.setdefault("UPLOAD_DIR", str(ROOT / "backend" / "test_uploads"))
23
- os.environ.setdefault("CHROMA_PERSIST_DIR", str(ROOT / "backend" / "test_chroma"))
 
24
 
25
 
26
  fake_embeddings = types.ModuleType("app.rag.embeddings")
 
16
  if str(BACKEND_DIR) not in sys.path:
17
  sys.path.insert(0, str(BACKEND_DIR))
18
 
19
+ os.environ["SECRET_KEY"] = "test-secret-key"
20
+ os.environ["DATABASE_URL"] = "sqlite:///./test_bootstrap.db"
21
+ os.environ["DEBUG"] = "false"
22
+ os.environ["HF_TOKEN"] = "test-hf-token"
23
+ os.environ["UPLOAD_DIR"] = str(ROOT / "backend" / "test_uploads")
24
+ os.environ["CHROMA_PERSIST_DIR"] = str(ROOT / "backend" / "test_chroma")
25
 
26
 
27
  fake_embeddings = types.ModuleType("app.rag.embeddings")