Fixed linting
This commit is contained in:
@@ -38,8 +38,9 @@ def get_default_host(binding_type: str) -> str:
|
|||||||
binding_type, "http://localhost:11434"
|
binding_type, "http://localhost:11434"
|
||||||
) # fallback to ollama if unknown
|
) # fallback to ollama if unknown
|
||||||
|
|
||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
import os
|
|
||||||
|
|
||||||
def get_env_value(env_key: str, default: Any, value_type: type = str) -> Any:
|
def get_env_value(env_key: str, default: Any, value_type: type = str) -> Any:
|
||||||
"""
|
"""
|
||||||
@@ -58,12 +59,13 @@ def get_env_value(env_key: str, default: Any, value_type: type = str) -> Any:
|
|||||||
return default
|
return default
|
||||||
|
|
||||||
if value_type == bool:
|
if value_type == bool:
|
||||||
return value.lower() in ('true', '1', 'yes')
|
return value.lower() in ("true", "1", "yes")
|
||||||
try:
|
try:
|
||||||
return value_type(value)
|
return value_type(value)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return default
|
return default
|
||||||
|
|
||||||
|
|
||||||
def display_splash_screen(args: argparse.Namespace) -> None:
|
def display_splash_screen(args: argparse.Namespace) -> None:
|
||||||
"""
|
"""
|
||||||
Display a colorful splash screen showing LightRAG server configuration
|
Display a colorful splash screen showing LightRAG server configuration
|
||||||
@@ -81,61 +83,61 @@ def display_splash_screen(args: argparse.Namespace) -> None:
|
|||||||
|
|
||||||
# Server Configuration
|
# Server Configuration
|
||||||
ASCIIColors.magenta("\n📡 Server Configuration:")
|
ASCIIColors.magenta("\n📡 Server Configuration:")
|
||||||
ASCIIColors.white(f" ├─ Host: ", end="")
|
ASCIIColors.white(" ├─ Host: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.host}")
|
ASCIIColors.yellow(f"{args.host}")
|
||||||
ASCIIColors.white(f" ├─ Port: ", end="")
|
ASCIIColors.white(" ├─ Port: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.port}")
|
ASCIIColors.yellow(f"{args.port}")
|
||||||
ASCIIColors.white(f" ├─ SSL Enabled: ", end="")
|
ASCIIColors.white(" ├─ SSL Enabled: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.ssl}")
|
ASCIIColors.yellow(f"{args.ssl}")
|
||||||
if args.ssl:
|
if args.ssl:
|
||||||
ASCIIColors.white(f" ├─ SSL Cert: ", end="")
|
ASCIIColors.white(" ├─ SSL Cert: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.ssl_certfile}")
|
ASCIIColors.yellow(f"{args.ssl_certfile}")
|
||||||
ASCIIColors.white(f" └─ SSL Key: ", end="")
|
ASCIIColors.white(" └─ SSL Key: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.ssl_keyfile}")
|
ASCIIColors.yellow(f"{args.ssl_keyfile}")
|
||||||
|
|
||||||
# Directory Configuration
|
# Directory Configuration
|
||||||
ASCIIColors.magenta("\n📂 Directory Configuration:")
|
ASCIIColors.magenta("\n📂 Directory Configuration:")
|
||||||
ASCIIColors.white(f" ├─ Working Directory: ", end="")
|
ASCIIColors.white(" ├─ Working Directory: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.working_dir}")
|
ASCIIColors.yellow(f"{args.working_dir}")
|
||||||
ASCIIColors.white(f" └─ Input Directory: ", end="")
|
ASCIIColors.white(" └─ Input Directory: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.input_dir}")
|
ASCIIColors.yellow(f"{args.input_dir}")
|
||||||
|
|
||||||
# LLM Configuration
|
# LLM Configuration
|
||||||
ASCIIColors.magenta("\n🤖 LLM Configuration:")
|
ASCIIColors.magenta("\n🤖 LLM Configuration:")
|
||||||
ASCIIColors.white(f" ├─ Binding: ", end="")
|
ASCIIColors.white(" ├─ Binding: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.llm_binding}")
|
ASCIIColors.yellow(f"{args.llm_binding}")
|
||||||
ASCIIColors.white(f" ├─ Host: ", end="")
|
ASCIIColors.white(" ├─ Host: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.llm_binding_host}")
|
ASCIIColors.yellow(f"{args.llm_binding_host}")
|
||||||
ASCIIColors.white(f" └─ Model: ", end="")
|
ASCIIColors.white(" └─ Model: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.llm_model}")
|
ASCIIColors.yellow(f"{args.llm_model}")
|
||||||
|
|
||||||
# Embedding Configuration
|
# Embedding Configuration
|
||||||
ASCIIColors.magenta("\n📊 Embedding Configuration:")
|
ASCIIColors.magenta("\n📊 Embedding Configuration:")
|
||||||
ASCIIColors.white(f" ├─ Binding: ", end="")
|
ASCIIColors.white(" ├─ Binding: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.embedding_binding}")
|
ASCIIColors.yellow(f"{args.embedding_binding}")
|
||||||
ASCIIColors.white(f" ├─ Host: ", end="")
|
ASCIIColors.white(" ├─ Host: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.embedding_binding_host}")
|
ASCIIColors.yellow(f"{args.embedding_binding_host}")
|
||||||
ASCIIColors.white(f" ├─ Model: ", end="")
|
ASCIIColors.white(" ├─ Model: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.embedding_model}")
|
ASCIIColors.yellow(f"{args.embedding_model}")
|
||||||
ASCIIColors.white(f" └─ Dimensions: ", end="")
|
ASCIIColors.white(" └─ Dimensions: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.embedding_dim}")
|
ASCIIColors.yellow(f"{args.embedding_dim}")
|
||||||
|
|
||||||
# RAG Configuration
|
# RAG Configuration
|
||||||
ASCIIColors.magenta("\n⚙️ RAG Configuration:")
|
ASCIIColors.magenta("\n⚙️ RAG Configuration:")
|
||||||
ASCIIColors.white(f" ├─ Max Async Operations: ", end="")
|
ASCIIColors.white(" ├─ Max Async Operations: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.max_async}")
|
ASCIIColors.yellow(f"{args.max_async}")
|
||||||
ASCIIColors.white(f" ├─ Max Tokens: ", end="")
|
ASCIIColors.white(" ├─ Max Tokens: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.max_tokens}")
|
ASCIIColors.yellow(f"{args.max_tokens}")
|
||||||
ASCIIColors.white(f" └─ Max Embed Tokens: ", end="")
|
ASCIIColors.white(" └─ Max Embed Tokens: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.max_embed_tokens}")
|
ASCIIColors.yellow(f"{args.max_embed_tokens}")
|
||||||
|
|
||||||
# System Configuration
|
# System Configuration
|
||||||
ASCIIColors.magenta("\n🛠️ System Configuration:")
|
ASCIIColors.magenta("\n🛠️ System Configuration:")
|
||||||
ASCIIColors.white(f" ├─ Log Level: ", end="")
|
ASCIIColors.white(" ├─ Log Level: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.log_level}")
|
ASCIIColors.yellow(f"{args.log_level}")
|
||||||
ASCIIColors.white(f" ├─ Timeout: ", end="")
|
ASCIIColors.white(" ├─ Timeout: ", end="")
|
||||||
ASCIIColors.yellow(f"{args.timeout if args.timeout else 'None (infinite)'}")
|
ASCIIColors.yellow(f"{args.timeout if args.timeout else 'None (infinite)'}")
|
||||||
ASCIIColors.white(f" └─ API Key: ", end="")
|
ASCIIColors.white(" └─ API Key: ", end="")
|
||||||
ASCIIColors.yellow("Set" if args.key else "Not Set")
|
ASCIIColors.yellow("Set" if args.key else "Not Set")
|
||||||
|
|
||||||
# Server Status
|
# Server Status
|
||||||
@@ -206,7 +208,6 @@ def display_splash_screen(args: argparse.Namespace) -> None:
|
|||||||
ASCIIColors.green("Server is ready to accept connections! 🚀\n")
|
ASCIIColors.green("Server is ready to accept connections! 🚀\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def parse_args() -> argparse.Namespace:
|
def parse_args() -> argparse.Namespace:
|
||||||
"""
|
"""
|
||||||
Parse command line arguments with environment variable fallback
|
Parse command line arguments with environment variable fallback
|
||||||
@@ -240,13 +241,13 @@ def parse_args() -> argparse.Namespace:
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--host",
|
"--host",
|
||||||
default=get_env_value("HOST", "0.0.0.0"),
|
default=get_env_value("HOST", "0.0.0.0"),
|
||||||
help="Server host (default: from env or 0.0.0.0)"
|
help="Server host (default: from env or 0.0.0.0)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--port",
|
"--port",
|
||||||
type=int,
|
type=int,
|
||||||
default=get_env_value("PORT", 9621, int),
|
default=get_env_value("PORT", 9621, int),
|
||||||
help="Server port (default: from env or 9621)"
|
help="Server port (default: from env or 9621)",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Directory configuration
|
# Directory configuration
|
||||||
@@ -262,7 +263,9 @@ def parse_args() -> argparse.Namespace:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# LLM Model configuration
|
# LLM Model configuration
|
||||||
default_llm_host = get_env_value("LLM_BINDING_HOST", get_default_host(temp_args.llm_binding))
|
default_llm_host = get_env_value(
|
||||||
|
"LLM_BINDING_HOST", get_default_host(temp_args.llm_binding)
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--llm-binding-host",
|
"--llm-binding-host",
|
||||||
default=default_llm_host,
|
default=default_llm_host,
|
||||||
@@ -276,7 +279,9 @@ def parse_args() -> argparse.Namespace:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Embedding model configuration
|
# Embedding model configuration
|
||||||
default_embedding_host = get_env_value("EMBEDDING_BINDING_HOST", get_default_host(temp_args.embedding_binding))
|
default_embedding_host = get_env_value(
|
||||||
|
"EMBEDDING_BINDING_HOST", get_default_host(temp_args.embedding_binding)
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--embedding-binding-host",
|
"--embedding-binding-host",
|
||||||
default=default_embedding_host,
|
default=default_embedding_host,
|
||||||
@@ -306,7 +311,7 @@ def parse_args() -> argparse.Namespace:
|
|||||||
"--max-async",
|
"--max-async",
|
||||||
type=int,
|
type=int,
|
||||||
default=get_env_value("MAX_ASYNC", 4, int),
|
default=get_env_value("MAX_ASYNC", 4, int),
|
||||||
help="Maximum async operations (default: from env or 4)"
|
help="Maximum async operations (default: from env or 4)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--max-tokens",
|
"--max-tokens",
|
||||||
@@ -347,7 +352,7 @@ def parse_args() -> argparse.Namespace:
|
|||||||
"--ssl",
|
"--ssl",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
default=get_env_value("SSL", False, bool),
|
default=get_env_value("SSL", False, bool),
|
||||||
help="Enable HTTPS (default: from env or False)"
|
help="Enable HTTPS (default: from env or False)",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--ssl-certfile",
|
"--ssl-certfile",
|
||||||
@@ -629,7 +634,6 @@ def create_app(args):
|
|||||||
else:
|
else:
|
||||||
logging.warning(f"No content extracted from file: {file_path}")
|
logging.warning(f"No content extracted from file: {file_path}")
|
||||||
|
|
||||||
|
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
"""Lifespan context manager for startup and shutdown events"""
|
"""Lifespan context manager for startup and shutdown events"""
|
||||||
|
@@ -9,6 +9,7 @@ ollama
|
|||||||
openai
|
openai
|
||||||
pipmaster
|
pipmaster
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
python-dotenv
|
||||||
python-multipart
|
python-multipart
|
||||||
tenacity
|
tenacity
|
||||||
tiktoken
|
tiktoken
|
||||||
@@ -16,4 +17,3 @@ torch
|
|||||||
tqdm
|
tqdm
|
||||||
transformers
|
transformers
|
||||||
uvicorn
|
uvicorn
|
||||||
python-dotenv
|
|
Reference in New Issue
Block a user