Hemang Thakur
commited on
Commit
·
5d8896b
1
Parent(s):
3a314ec
fixed enf file paths
Browse files- main.py +18 -3
- src/helpers/helper.py +3 -3
- src/integrations/mcp_client.py +2 -2
main.py
CHANGED
@@ -8,8 +8,9 @@ import logging
|
|
8 |
import traceback
|
9 |
from httpx import AsyncClient, RequestError
|
10 |
from typing import List, Dict, Any, Optional
|
|
|
11 |
from fastapi import FastAPI, Request, HTTPException, UploadFile, File, Form
|
12 |
-
from fastapi.responses import StreamingResponse, JSONResponse
|
13 |
from fastapi.middleware.cors import CORSMiddleware
|
14 |
from dotenv import load_dotenv
|
15 |
from tenacity import RetryError
|
@@ -21,6 +22,9 @@ from src.helpers.helper import get_folder_size, clear_folder
|
|
21 |
logger = logging.getLogger()
|
22 |
logger.setLevel(logging.INFO)
|
23 |
|
|
|
|
|
|
|
24 |
# Define the upload directory and maximum folder size
|
25 |
UPLOAD_DIRECTORY = "uploads"
|
26 |
MAX_FOLDER_SIZE = 10 * 1024 * 1024 # 10 MB in bytes
|
@@ -64,7 +68,7 @@ def get_oauth_token(provider: str) -> Optional[str]:
|
|
64 |
|
65 |
# Initialize the components
|
66 |
async def initialize_components():
|
67 |
-
load_dotenv(override=True)
|
68 |
|
69 |
from src.search.search_engine import SearchEngine
|
70 |
from src.query_processing.query_processor import QueryProcessor
|
@@ -843,6 +847,9 @@ app.add_middleware(
|
|
843 |
allow_headers=["*"], # Allows all headers
|
844 |
)
|
845 |
|
|
|
|
|
|
|
846 |
# Define the routes for the FastAPI app
|
847 |
|
848 |
# Define the route for sources action to display search results
|
@@ -1368,4 +1375,12 @@ def stop():
|
|
1368 |
state["process_task"].cancel()
|
1369 |
del state["process_task"]
|
1370 |
|
1371 |
-
return {"message": "Stopped task manually"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
import traceback
|
9 |
from httpx import AsyncClient, RequestError
|
10 |
from typing import List, Dict, Any, Optional
|
11 |
+
from fastapi.staticfiles import StaticFiles
|
12 |
from fastapi import FastAPI, Request, HTTPException, UploadFile, File, Form
|
13 |
+
from fastapi.responses import StreamingResponse, JSONResponse, FileResponse
|
14 |
from fastapi.middleware.cors import CORSMiddleware
|
15 |
from dotenv import load_dotenv
|
16 |
from tenacity import RetryError
|
|
|
22 |
logger = logging.getLogger()
|
23 |
logger.setLevel(logging.INFO)
|
24 |
|
25 |
+
# Path to the .env file
|
26 |
+
ENV_FILE_PATH = os.getenv("WRITABLE_DIR", "/tmp") + "/.env"
|
27 |
+
|
28 |
# Define the upload directory and maximum folder size
|
29 |
UPLOAD_DIRECTORY = "uploads"
|
30 |
MAX_FOLDER_SIZE = 10 * 1024 * 1024 # 10 MB in bytes
|
|
|
68 |
|
69 |
# Initialize the components
|
70 |
async def initialize_components():
|
71 |
+
load_dotenv(ENV_FILE_PATH, override=True)
|
72 |
|
73 |
from src.search.search_engine import SearchEngine
|
74 |
from src.query_processing.query_processor import QueryProcessor
|
|
|
847 |
allow_headers=["*"], # Allows all headers
|
848 |
)
|
849 |
|
850 |
+
# Serve the React app (the production build) at the root URL.
|
851 |
+
app.mount("/static", StaticFiles(directory="frontend/build/static", html=True), name="static")
|
852 |
+
|
853 |
# Define the routes for the FastAPI app
|
854 |
|
855 |
# Define the route for sources action to display search results
|
|
|
1375 |
state["process_task"].cancel()
|
1376 |
del state["process_task"]
|
1377 |
|
1378 |
+
return {"message": "Stopped task manually"}
|
1379 |
+
|
1380 |
+
# Catch-all route for frontend paths.
|
1381 |
+
@app.get("/{full_path:path}")
|
1382 |
+
async def serve_frontend(full_path: str, request: Request):
|
1383 |
+
index_path = os.path.join("frontend", "build", "index.html")
|
1384 |
+
if not os.path.exists(index_path):
|
1385 |
+
raise HTTPException(status_code=500, detail="Frontend build not found")
|
1386 |
+
return FileResponse(index_path)
|
src/helpers/helper.py
CHANGED
@@ -6,9 +6,9 @@ import torch
|
|
6 |
import transformers
|
7 |
from langchain.text_splitter import RecursiveCharacterTextSplitter, TokenTextSplitter
|
8 |
|
9 |
-
ENV_FILE_PATH = os.path.join(os.
|
10 |
-
WEBHOOK_PATH = os.path.join(os.
|
11 |
-
SLACK_CREDENTIALS_PATH = os.path.join(os.
|
12 |
|
13 |
def remove_markdown(text: str) -> str:
|
14 |
# Remove code block format type and the code block itself
|
|
|
6 |
import transformers
|
7 |
from langchain.text_splitter import RecursiveCharacterTextSplitter, TokenTextSplitter
|
8 |
|
9 |
+
ENV_FILE_PATH = os.path.join(os.getenv("WRITABLE_DIR", "/tmp"), ".env")
|
10 |
+
WEBHOOK_PATH = os.path.join(os.getcwd(), ".webhook_secret")
|
11 |
+
SLACK_CREDENTIALS_PATH = os.path.join(os.getcwd(), ".slack_credentials")
|
12 |
|
13 |
def remove_markdown(text: str) -> str:
|
14 |
# Remove code block format type and the code block itself
|
src/integrations/mcp_client.py
CHANGED
@@ -12,8 +12,8 @@ from src.utils.api_key_manager import with_api_manager
|
|
12 |
from src.helpers.helper import remove_markdown
|
13 |
|
14 |
# Load environment variables from .env file
|
15 |
-
|
16 |
-
load_dotenv(
|
17 |
|
18 |
# Configure logging
|
19 |
logger = logging.getLogger(__name__)
|
|
|
12 |
from src.helpers.helper import remove_markdown
|
13 |
|
14 |
# Load environment variables from .env file
|
15 |
+
ENV_FILE_PATH = os.getenv("WRITABLE_DIR", "/tmp") + "/.env"
|
16 |
+
load_dotenv(ENV_FILE_PATH, override=True)
|
17 |
|
18 |
# Configure logging
|
19 |
logger = logging.getLogger(__name__)
|