Add comprehensive error logging across API routes
- Add error logs to Ollama API endpoints - Replace logging with unified logger - Log streaming query errors - Add data query error logging - Include stack traces for debugging
This commit is contained in:
parent
0fb2925c6a
commit
b7de694f48
2 changed files with 7 additions and 3 deletions
|
|
@ -456,6 +456,7 @@ class OllamaAPI:
|
||||||
"eval_duration": eval_time,
|
"eval_duration": eval_time,
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"Ollama generate error: {str(e)}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
@self.router.post(
|
@self.router.post(
|
||||||
|
|
@ -718,4 +719,5 @@ class OllamaAPI:
|
||||||
"eval_duration": eval_time,
|
"eval_duration": eval_time,
|
||||||
}
|
}
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"Ollama chat error: {str(e)}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,11 @@ This module contains all query-related routes for the LightRAG API.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
|
||||||
from typing import Any, Dict, List, Literal, Optional
|
from typing import Any, Dict, List, Literal, Optional
|
||||||
|
|
||||||
from fastapi import APIRouter, Depends, HTTPException
|
from fastapi import APIRouter, Depends, HTTPException
|
||||||
from lightrag.base import QueryParam
|
from lightrag.base import QueryParam
|
||||||
from lightrag.api.utils_api import get_combined_auth_dependency
|
from lightrag.api.utils_api import get_combined_auth_dependency
|
||||||
|
from lightrag.utils import logger
|
||||||
from pydantic import BaseModel, Field, field_validator
|
from pydantic import BaseModel, Field, field_validator
|
||||||
|
|
||||||
router = APIRouter(tags=["query"])
|
router = APIRouter(tags=["query"])
|
||||||
|
|
@ -451,6 +450,7 @@ def create_query_routes(rag, api_key: Optional[str] = None, top_k: int = 60):
|
||||||
else:
|
else:
|
||||||
return QueryResponse(response=response_content, references=None)
|
return QueryResponse(response=response_content, references=None)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"Error processing query: {str(e)}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
|
|
@ -710,7 +710,7 @@ def create_query_routes(rag, api_key: Optional[str] = None, top_k: int = 60):
|
||||||
if chunk: # Only send non-empty content
|
if chunk: # Only send non-empty content
|
||||||
yield f"{json.dumps({'response': chunk})}\n"
|
yield f"{json.dumps({'response': chunk})}\n"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"Streaming error: {str(e)}")
|
logger.error(f"Streaming error: {str(e)}")
|
||||||
yield f"{json.dumps({'error': str(e)})}\n"
|
yield f"{json.dumps({'error': str(e)})}\n"
|
||||||
else:
|
else:
|
||||||
# Non-streaming mode: send complete response in one message
|
# Non-streaming mode: send complete response in one message
|
||||||
|
|
@ -736,6 +736,7 @@ def create_query_routes(rag, api_key: Optional[str] = None, top_k: int = 60):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"Error processing streaming query: {str(e)}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
@router.post(
|
@router.post(
|
||||||
|
|
@ -1152,6 +1153,7 @@ def create_query_routes(rag, api_key: Optional[str] = None, top_k: int = 60):
|
||||||
data={},
|
data={},
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
logger.error(f"Error processing data query: {str(e)}", exc_info=True)
|
||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue