Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -25,7 +25,40 @@ from fastapi.middleware.cors import CORSMiddleware
|
|
| 25 |
import re
|
| 26 |
import os
|
| 27 |
from langchain_core.prompts import ChatPromptTemplate
|
| 28 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
app = FastAPI()
|
| 31 |
app.include_router(document_rag_router)
|
|
@@ -157,10 +190,10 @@ def get_collection_files(collection_id: str, user_id: str) -> str:
|
|
| 157 |
if response.status_code == 200:
|
| 158 |
return response.text
|
| 159 |
else:
|
| 160 |
-
|
| 161 |
return f"Error getting files: {response.text}"
|
| 162 |
except Exception as e:
|
| 163 |
-
|
| 164 |
return f"Error getting files: {str(e)}"
|
| 165 |
|
| 166 |
def format_for_model(state):
|
|
@@ -172,7 +205,7 @@ def format_for_model(state):
|
|
| 172 |
# Get files in the collection
|
| 173 |
|
| 174 |
collection_files = get_current_files()#get_collection_files(collection_id, user_id) if collection_id and user_id else "No files available"
|
| 175 |
-
|
| 176 |
return prompt.invoke({
|
| 177 |
"collection_files": collection_files,
|
| 178 |
"messages": state["messages"]
|
|
@@ -333,6 +366,11 @@ async def chat2(input_data: ChatInput):
|
|
| 333 |
async def health_check():
|
| 334 |
return {"status": "healthy"}
|
| 335 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
if __name__ == "__main__":
|
| 337 |
import uvicorn
|
| 338 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 25 |
import re
|
| 26 |
import os
|
| 27 |
from langchain_core.prompts import ChatPromptTemplate
|
| 28 |
+
import logger
|
| 29 |
+
|
| 30 |
+
import logger.config
|
| 31 |
+
|
| 32 |
+
# Configure logger at application startup
|
| 33 |
+
logger.config.dictConfig({
|
| 34 |
+
"version": 1,
|
| 35 |
+
"disable_existing_loggers": False,
|
| 36 |
+
"formatters": {
|
| 37 |
+
"default": {
|
| 38 |
+
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
| 39 |
+
"datefmt": "%Y-%m-%d %H:%M:%S",
|
| 40 |
+
}
|
| 41 |
+
},
|
| 42 |
+
"handlers": {
|
| 43 |
+
"console": {
|
| 44 |
+
"class": "logger.StreamHandler",
|
| 45 |
+
"stream": "ext://sys.stdout",
|
| 46 |
+
"formatter": "default",
|
| 47 |
+
"level": "DEBUG",
|
| 48 |
+
}
|
| 49 |
+
},
|
| 50 |
+
"root": {
|
| 51 |
+
"level": "DEBUG",
|
| 52 |
+
"handlers": ["console"]
|
| 53 |
+
},
|
| 54 |
+
"loggers": {
|
| 55 |
+
"uvicorn": {"handlers": ["console"], "level": "DEBUG"},
|
| 56 |
+
"fastapi": {"handlers": ["console"], "level": "DEBUG"}
|
| 57 |
+
}
|
| 58 |
+
})
|
| 59 |
+
|
| 60 |
+
# Create logger instance
|
| 61 |
+
logger = logger.getLogger(__name__)
|
| 62 |
|
| 63 |
app = FastAPI()
|
| 64 |
app.include_router(document_rag_router)
|
|
|
|
| 190 |
if response.status_code == 200:
|
| 191 |
return response.text
|
| 192 |
else:
|
| 193 |
+
logger.error(f"Error from API: {response.text}")
|
| 194 |
return f"Error getting files: {response.text}"
|
| 195 |
except Exception as e:
|
| 196 |
+
logger.error(f"Error getting collection files: {str(e)}")
|
| 197 |
return f"Error getting files: {str(e)}"
|
| 198 |
|
| 199 |
def format_for_model(state):
|
|
|
|
| 205 |
# Get files in the collection
|
| 206 |
|
| 207 |
collection_files = get_current_files()#get_collection_files(collection_id, user_id) if collection_id and user_id else "No files available"
|
| 208 |
+
logger.info(f"fetching collection for userid{user_id} and collection_id {collection_id}|| Results {collection_files}")
|
| 209 |
return prompt.invoke({
|
| 210 |
"collection_files": collection_files,
|
| 211 |
"messages": state["messages"]
|
|
|
|
| 366 |
async def health_check():
|
| 367 |
return {"status": "healthy"}
|
| 368 |
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
|
| 374 |
if __name__ == "__main__":
|
| 375 |
import uvicorn
|
| 376 |
uvicorn.run(app, host="0.0.0.0", port=8000)
|