Jatin Mehra commited on
Commit
9a2da40
·
1 Parent(s): a8dbd59

Refactor: Remove '/api' prefix from route paths for consistency across backend and frontend

Browse files
backend/routes/chat_routes.py CHANGED
@@ -12,7 +12,7 @@ from utils import get_processor, generate_response, get_global_state, update_glo
12
  router = APIRouter()
13
 
14
 
15
- @router.post("/api/chat", response_model=ChatResponse)
16
  async def chat(message: ChatMessage):
17
  """Process a chat message and return response with citations and themes."""
18
  try:
@@ -63,7 +63,7 @@ async def chat(message: ChatMessage):
63
  raise HTTPException(status_code=500, detail=str(e))
64
 
65
 
66
- @router.delete("/api/clear-chat")
67
  async def clear_chat():
68
  """Clear chat history and reset session data."""
69
  import sys
 
12
  router = APIRouter()
13
 
14
 
15
+ @router.post("/chat", response_model=ChatResponse)
16
  async def chat(message: ChatMessage):
17
  """Process a chat message and return response with citations and themes."""
18
  try:
 
63
  raise HTTPException(status_code=500, detail=str(e))
64
 
65
 
66
+ @router.delete("/clear-chat")
67
  async def clear_chat():
68
  """Clear chat history and reset session data."""
69
  import sys
backend/routes/main_routes.py CHANGED
@@ -19,7 +19,7 @@ async def read_root():
19
  return FileResponse(frontend_path)
20
 
21
 
22
- @router.post("/api/set-api-key")
23
  async def set_api_key(request: APIKeyRequest):
24
  """Set the GROQ API key."""
25
  try:
@@ -30,14 +30,14 @@ async def set_api_key(request: APIKeyRequest):
30
  raise HTTPException(status_code=400, detail=str(e))
31
 
32
 
33
- @router.get("/api/stats")
34
  async def get_stats():
35
  """Get processing statistics."""
36
  state = get_global_state()
37
  return {"stats": state["processing_stats"], "vector_store_loaded": state["vector_store_loaded"]}
38
 
39
 
40
- @router.get("/api/chat-history")
41
  async def get_chat_history():
42
  """Get chat history."""
43
  state = get_global_state()
 
19
  return FileResponse(frontend_path)
20
 
21
 
22
+ @router.post("/set-api-key")
23
  async def set_api_key(request: APIKeyRequest):
24
  """Set the GROQ API key."""
25
  try:
 
30
  raise HTTPException(status_code=400, detail=str(e))
31
 
32
 
33
+ @router.get("/stats")
34
  async def get_stats():
35
  """Get processing statistics."""
36
  state = get_global_state()
37
  return {"stats": state["processing_stats"], "vector_store_loaded": state["vector_store_loaded"]}
38
 
39
 
40
+ @router.get("/chat-history")
41
  async def get_chat_history():
42
  """Get chat history."""
43
  state = get_global_state()
backend/routes/store_routes.py CHANGED
@@ -11,7 +11,7 @@ from utils import get_processor, get_global_state, update_global_state
11
  router = APIRouter()
12
 
13
 
14
- @router.post("/api/save-vector-store")
15
  async def save_vector_store():
16
  """Save the current vector store."""
17
  try:
@@ -29,7 +29,7 @@ async def save_vector_store():
29
  raise HTTPException(status_code=500, detail=str(e))
30
 
31
 
32
- @router.post("/api/load-vector-store")
33
  async def load_vector_store():
34
  """Load a previously saved vector store."""
35
  try:
 
11
  router = APIRouter()
12
 
13
 
14
+ @router.post("/save-vector-store")
15
  async def save_vector_store():
16
  """Save the current vector store."""
17
  try:
 
29
  raise HTTPException(status_code=500, detail=str(e))
30
 
31
 
32
+ @router.post("/load-vector-store")
33
  async def load_vector_store():
34
  """Load a previously saved vector store."""
35
  try:
backend/routes/upload_routes.py CHANGED
@@ -16,7 +16,7 @@ from utils import (
16
  router = APIRouter()
17
 
18
 
19
- @router.post("/api/upload-files")
20
  async def upload_files(files: List[UploadFile] = File(...)):
21
  """Upload and process multiple files."""
22
  try:
@@ -69,7 +69,7 @@ async def upload_files(files: List[UploadFile] = File(...)):
69
  raise HTTPException(status_code=500, detail=str(e))
70
 
71
 
72
- @router.post("/api/process-directory")
73
  async def process_directory(directory_path: str = Form(...)):
74
  """Process documents from a directory."""
75
  try:
 
16
  router = APIRouter()
17
 
18
 
19
+ @router.post("/upload-files")
20
  async def upload_files(files: List[UploadFile] = File(...)):
21
  """Upload and process multiple files."""
22
  try:
 
69
  raise HTTPException(status_code=500, detail=str(e))
70
 
71
 
72
+ @router.post("/process-directory")
73
  async def process_directory(directory_path: str = Form(...)):
74
  """Process documents from a directory."""
75
  try:
frontend/script.js CHANGED
@@ -1,5 +1,4 @@
1
  // Global variables
2
- let apiBaseUrl = '/api';
3
  let vectorStoreLoaded = false;
4
  let processingStats = {};
5
  let chatHistory = [];
@@ -83,7 +82,7 @@ async function setApiKey() {
83
 
84
  try {
85
  showLoading(true);
86
- const response = await fetch(`${apiBaseUrl}/set-api-key`, {
87
  method: 'POST',
88
  headers: {
89
  'Content-Type': 'application/json',
@@ -132,7 +131,7 @@ async function uploadFiles() {
132
  try {
133
  showProcessingModal('Processing uploaded documents...');
134
 
135
- const response = await fetch(`${apiBaseUrl}/upload-files`, {
136
  method: 'POST',
137
  body: formData
138
  });
@@ -173,7 +172,7 @@ async function processDirectory() {
173
  const formData = new FormData();
174
  formData.append('directory_path', directoryPath);
175
 
176
- const response = await fetch(`${apiBaseUrl}/process-directory`, {
177
  method: 'POST',
178
  body: formData
179
  });
@@ -201,7 +200,7 @@ async function saveVectorStore() {
201
  try {
202
  showLoading(true);
203
 
204
- const response = await fetch(`${apiBaseUrl}/save-vector-store`, {
205
  method: 'POST'
206
  });
207
 
@@ -223,7 +222,7 @@ async function loadVectorStore() {
223
  try {
224
  showLoading(true);
225
 
226
- const response = await fetch(`${apiBaseUrl}/load-vector-store`, {
227
  method: 'POST'
228
  });
229
 
@@ -261,7 +260,7 @@ async function sendMessage() {
261
  sendBtn.disabled = true;
262
 
263
  try {
264
- const response = await fetch(`${apiBaseUrl}/chat`, {
265
  method: 'POST',
266
  headers: {
267
  'Content-Type': 'application/json',
@@ -293,7 +292,7 @@ async function clearChatHistory() {
293
  }
294
 
295
  // Call the backend API to clear chat history
296
- const response = await fetch(`${apiBaseUrl}/clear-chat`, {
297
  method: 'DELETE',
298
  });
299
 
@@ -456,7 +455,7 @@ function createThemesSection(themes) {
456
  // Stats Management
457
  async function loadStats() {
458
  try {
459
- const response = await fetch(`${apiBaseUrl}/stats`);
460
  const data = await response.json();
461
 
462
  if (response.ok) {
 
1
  // Global variables
 
2
  let vectorStoreLoaded = false;
3
  let processingStats = {};
4
  let chatHistory = [];
 
82
 
83
  try {
84
  showLoading(true);
85
+ const response = await fetch(`/set-api-key`, {
86
  method: 'POST',
87
  headers: {
88
  'Content-Type': 'application/json',
 
131
  try {
132
  showProcessingModal('Processing uploaded documents...');
133
 
134
+ const response = await fetch(`/upload-files`, {
135
  method: 'POST',
136
  body: formData
137
  });
 
172
  const formData = new FormData();
173
  formData.append('directory_path', directoryPath);
174
 
175
+ const response = await fetch(`/process-directory`, {
176
  method: 'POST',
177
  body: formData
178
  });
 
200
  try {
201
  showLoading(true);
202
 
203
+ const response = await fetch(`/save-vector-store`, {
204
  method: 'POST'
205
  });
206
 
 
222
  try {
223
  showLoading(true);
224
 
225
+ const response = await fetch(`/load-vector-store`, {
226
  method: 'POST'
227
  });
228
 
 
260
  sendBtn.disabled = true;
261
 
262
  try {
263
+ const response = await fetch(`/chat`, {
264
  method: 'POST',
265
  headers: {
266
  'Content-Type': 'application/json',
 
292
  }
293
 
294
  // Call the backend API to clear chat history
295
+ const response = await fetch(`/clear-chat`, {
296
  method: 'DELETE',
297
  });
298
 
 
455
  // Stats Management
456
  async function loadStats() {
457
  try {
458
+ const response = await fetch(`/stats`);
459
  const data = await response.json();
460
 
461
  if (response.ok) {