refactor(api): Code optimization based on review comments.

- Removed authentication dependency for the health check endpoint in lightrag_server.py
- Removed the authentication dependency for the entire router in ollama_api.py
- Updated the parameter list and example usage in README.md, removing authentication-related parts
- Removed neo4j and tqdm dependencies from requirements.txt
- Deleted command-line argument parsing code related to authentication from utils_api.py
This commit is contained in:
Milin
2025-03-05 20:38:05 +08:00
parent 11502fc756
commit 59e3b2eec1
5 changed files with 29 additions and 69 deletions

View File

@@ -296,7 +296,7 @@ You can not change storage implementation selection after you add documents to L
### LightRag API Server Comand Line Options ### LightRag API Server Comand Line Options
| Parameter | Default | Description | | Parameter | Default | Description |
|-------------------------|----------------|-----------------------------------------------------------------------------------------------------------------------------| |-----------|---------|-------------|
| --host | 0.0.0.0 | Server host | | --host | 0.0.0.0 | Server host |
| --port | 9621 | Server port | | --port | 9621 | Server port |
| --working-dir | ./rag_storage | Working directory for RAG storage | | --working-dir | ./rag_storage | Working directory for RAG storage |
@@ -314,13 +314,7 @@ You can not change storage implementation selection after you add documents to L
| --cosine-threshold | 0.4 | The cossine threshold for nodes and relations retrieval, works with top-k to control the retrieval of nodes and relations. | | --cosine-threshold | 0.4 | The cossine threshold for nodes and relations retrieval, works with top-k to control the retrieval of nodes and relations. |
| --llm-binding | ollama | LLM binding type (lollms, ollama, openai, openai-ollama, azure_openai) | | --llm-binding | ollama | LLM binding type (lollms, ollama, openai, openai-ollama, azure_openai) |
| --embedding-binding | ollama | Embedding binding type (lollms, ollama, openai, azure_openai) | | --embedding-binding | ollama | Embedding binding type (lollms, ollama, openai, azure_openai) |
| --auto-scan-at-startup | - | Scan input directory for new files and start indexing | | auto-scan-at-startup | - | Scan input directory for new files and start indexing |
| --auth-username | - | Enable jwt if not empty |
| --auth-password | - | Enable jwt if not empty |
| --token-secret | - | JWT key |
| --token-expire-hours | 4 | expire duration |
| --whitelist-paths | /login,/health | white list |
### Example Usage ### Example Usage
@@ -399,11 +393,11 @@ pip install lightrag-hku
LightRAG API Server implements JWT-based authentication using HS256 algorithm. To enable secure access control, the following environment variables are required: LightRAG API Server implements JWT-based authentication using HS256 algorithm. To enable secure access control, the following environment variables are required:
```bash ```bash
# For jwt auth # For jwt auth
AUTH_USERNAME=admin # login name --auth-username AUTH_USERNAME=admin # login name
AUTH_PASSWORD=admin123 # password --auth-password AUTH_PASSWORD=admin123 # password
TOKEN_SECRET=your-key # JWT key --token-secret TOKEN_SECRET=your-key # JWT key
TOKEN_EXPIRE_HOURS=4 # expire duration --token-expire-hours TOKEN_EXPIRE_HOURS=4 # expire duration
WHITELIST_PATHS=/login,/health # white list --whitelist-paths WHITELIST_PATHS=/api1,/api2 # white list. /login,/health,/docs,/redoc,/openapi.json are whitelisted by default.
``` ```
## API Endpoints ## API Endpoints

View File

@@ -400,7 +400,7 @@ def create_app(args):
"token_type": "bearer" "token_type": "bearer"
} }
@app.get("/health", dependencies=[Depends(optional_api_key), Depends(get_auth_dependency())]) @app.get("/health", dependencies=[Depends(optional_api_key)])
async def get_status(): async def get_status():
"""Get current system status""" """Get current system status"""
# Get update flags status for all namespaces # Get update flags status for all namespaces

View File

@@ -8,14 +8,12 @@ python-multipart
tenacity tenacity
tiktoken tiktoken
uvicorn uvicorn
tqdm
jiter jiter
httpcore httpcore
distro distro
httpx httpx
openai openai
asyncpg asyncpg
neo4j
pytz pytz
python-jose[cryptography] python-jose[cryptography]
passlib[bcrypt] passlib[bcrypt]

View File

@@ -1,4 +1,4 @@
from fastapi import APIRouter, HTTPException, Request, Depends from fastapi import APIRouter, HTTPException, Request
from pydantic import BaseModel from pydantic import BaseModel
from typing import List, Dict, Any, Optional from typing import List, Dict, Any, Optional
import logging import logging
@@ -11,7 +11,7 @@ import asyncio
from ascii_colors import trace_exception from ascii_colors import trace_exception
from lightrag import LightRAG, QueryParam from lightrag import LightRAG, QueryParam
from lightrag.utils import encode_string_by_tiktoken from lightrag.utils import encode_string_by_tiktoken
from ..utils_api import ollama_server_infos, get_auth_dependency from ..utils_api import ollama_server_infos
# query mode according to query prefix (bypass is not LightRAG quer mode) # query mode according to query prefix (bypass is not LightRAG quer mode)
@@ -126,7 +126,7 @@ class OllamaAPI:
self.rag = rag self.rag = rag
self.ollama_server_infos = ollama_server_infos self.ollama_server_infos = ollama_server_infos
self.top_k = top_k self.top_k = top_k
self.router = APIRouter(tags=["ollama"], dependencies=[Depends(get_auth_dependency())]) self.router = APIRouter(tags=["ollama"])
self.setup_routes() self.setup_routes()
def setup_routes(self): def setup_routes(self):

View File

@@ -312,38 +312,6 @@ def parse_args(is_uvicorn_mode: bool = False) -> argparse.Namespace:
help="Embedding binding type (default: from env or ollama)", help="Embedding binding type (default: from env or ollama)",
) )
# Authentication configuration
parser.add_argument(
"--auth-username",
type=str,
default=get_env_value("AUTH_USERNAME", ""),
help="Login username (default: from env or empty)"
)
parser.add_argument(
"--auth-password",
type=str,
default=get_env_value("AUTH_PASSWORD", ""),
help="Login password (default: from env or empty)"
)
parser.add_argument(
"--token-secret",
type=str,
default=get_env_value("TOKEN_SECRET", ""),
help="JWT signing secret (default: from env or empty)"
)
parser.add_argument(
"--token-expire-hours",
type=int,
default=get_env_value("TOKEN_EXPIRE_HOURS", 4, int),
help="Token validity in hours (default: from env or 4)"
)
parser.add_argument(
"--whitelist-paths",
type=str,
default=get_env_value("WHITELIST_PATHS", "/login,/health"),
help="Comma-separated auth-exempt paths (default: from env or /login,/health)"
)
args = parser.parse_args() args = parser.parse_args()
# If in uvicorn mode and workers > 1, force it to 1 and log warning # If in uvicorn mode and workers > 1, force it to 1 and log warning