From 9ed5ea31d78ef4f6837a8048c47f8523e2e41970 Mon Sep 17 00:00:00 2001 From: EdgeNeko Date: Thu, 2 May 2024 22:09:49 +0800 Subject: [PATCH] Better config file template --- app/Services/authentication.py | 2 +- app/config.py | 2 +- config/default.env | 89 ++++++++++++++++++++++------------ 3 files changed, 60 insertions(+), 33 deletions(-) diff --git a/app/Services/authentication.py b/app/Services/authentication.py index e8143b7..74a55e3 100644 --- a/app/Services/authentication.py +++ b/app/Services/authentication.py @@ -7,7 +7,7 @@ def verify_access_token(token: str | None) -> bool: - return (not config.access_protected) or (token is not None and token == config.access_token) + return (not config.access_protected) or (token and token == config.access_token) def permissive_access_token_verify( diff --git a/app/config.py b/app/config.py index 40999da..09dac63 100644 --- a/app/config.py +++ b/app/config.py @@ -75,7 +75,7 @@ class Config(BaseSettings): admin_token: str = '' access_protected: bool = False - access_token: str = 'default-access-token' + access_token: str = '' model_config = SettingsConfigDict(env_prefix="app_", env_nested_delimiter='__', env_file=('config/default.env', 'config/local.env'), diff --git a/config/default.env b/config/default.env index 90a8cfa..8377e1f 100644 --- a/config/default.env +++ b/config/default.env @@ -1,51 +1,78 @@ +# This is an example configuration file for the app. +# All the value below are the default values. To change the value, uncomment the line and set the value you want. +# You can also use environment variables or docker secrets to set these values (the key should correspond to the key below). +# Checkout https://docs.pydantic.dev/latest/concepts/pydantic_settings/ for more information. + # Vector Database Configuration -APP_QDRANT__HOST="localhost" -APP_QDRANT__PORT=6333 -APP_QDRANT__GRPC_PORT=6334 -# Set to True if you want to use gRPC instead of HTTP -APP_QDRANT__PREFER_GRPC=True -# Uncomment and add your API key here if you have set one, otherwise leave it None +# Hostname or IP address of the Qdrant server +# APP_QDRANT__HOST="localhost" +# Port number for the Qdrant HTTP server +# APP_QDRANT__PORT=6333 +# Port number for the Qdrant gRPC server +# APP_QDRANT__GRPC_PORT=6334 +# Set to True if you want to use gRPC for qdrant connection instead of HTTP +# APP_QDRANT__PREFER_GRPC=True +# Set your API key here if you have set one, otherwise leave it None # APP_QDRANT__API_KEY= -APP_QDRANT__COLL="NekoImg" +# Collection name to use in Qdrant +# APP_QDRANT__COLL="NekoImg" -# DEVICE Configuration -APP_DEVICE="auto" +# Inference device Configuration +# Setting this to "auto" allows the system to automatically detect and use available devices, otherwise specify the device name +# APP_DEVICE="auto" # CLIP Configuration -APP_CLIP__MODEL="openai/clip-vit-large-patch14" +# Model used for CLIP embeddings +# APP_CLIP__MODEL="openai/clip-vit-large-patch14" # BERT Configuration -APP_OCR_SEARCH__ENABLE=True -APP_OCR_SEARCH__OCR_MODULE="easypaddleocr" -APP_OCR_SEARCH__BERT_MODEL="bert-base-chinese" -APP_OCR_SEARCH__OCR_MIN_CONFIDENCE=1e-2 +# Enable OCR search functionality +# APP_OCR_SEARCH__ENABLE=True +# OCR module to use for text extraction +# APP_OCR_SEARCH__OCR_MODULE="easypaddleocr" +# BERT model to use for text embedding +# APP_OCR_SEARCH__BERT_MODEL="bert-base-chinese" +# Minimum confidence level required for OCR results to be considered +# APP_OCR_SEARCH__OCR_MIN_CONFIDENCE=1e-2 +# List of languages supported by the OCR module # APP_OCR_SEARCH__OCR_LANGUAGE=["ch_sim", "en"] # Server Configuration -APP_CORS_ORIGINS=["*"] +# List of allowed origins for CORS (Cross-Origin Resource Sharing) +# APP_CORS_ORIGINS=["*"] -# Set to False will completely disable admin API -APP_ADMIN_API_ENABLE=False +# Set to True to enable admin API, this allows you to access the admin API using the token specified below. +# APP_ADMIN_API_ENABLE=False -# Uncomment the line below if you enabled admin api. Use this token to access admin API. +# Uncomment the line below if you enabled admin API. Use this token to access admin API. For security reasons, the admin token is always required if you want to use admin API. # APP_ADMIN_TOKEN="your-super-secret-admin-token" - -APP_ACCESS_PROTECTED=False -# Uncomment the line below if you want to enable access token protection. Use this token to access the API. +# Access Protection Configuration +# Set to True to enable access protection using tokens +# APP_ACCESS_PROTECTED=False +# Use this token to access the API. This is required if you enabled access protection. # APP_ACCESS_TOKEN="your-super-secret-access-token" -# Storage Settings - Global, currently can be "local" or "s3" -APP_STORAGE__METHOD="local" +# Storage Settings - Global +# Method for storing files, options includes "local", "s3" and "disabled" +# APP_STORAGE__METHOD="local" # Storage Settings - local -APP_STORAGE__LOCAL__PATH="./static" +# Path where files will be stored locally +# APP_STORAGE__LOCAL__PATH="./static" # Storage Settings - S3 -APP_STORAGE__S3__BUCKET="your-s3-bucket-name" -APP_STORAGE__S3__PATH="./static" -APP_STORAGE__S3__REGION="your-s3-region" -APP_STORAGE__S3__ENDPOINT_URL="your-s3-endpoint-url" -APP_STORAGE__S3__ACCESS_KEY_ID="your-s3-access-key-id" -APP_STORAGE__S3__SECRET_ACCESS_KEY="your-s3-secret-access-key" -APP_STORAGE__S3__SESSION_TOKEN="your-s3-session-token" \ No newline at end of file +# Name of the S3 bucket +# APP_STORAGE__S3__BUCKET="your-s3-bucket-name" +# Path where files will be stored in the S3 bucket +# APP_STORAGE__S3__PATH="./static" +# Region where the S3 bucket is located +# APP_STORAGE__S3__REGION="your-s3-region" +# Endpoint URL for the S3 service +# APP_STORAGE__S3__ENDPOINT_URL="your-s3-endpoint-url" +# Access key ID for accessing the S3 bucket +# APP_STORAGE__S3__ACCESS_KEY_ID="your-s3-access-key-id" +# Secret access key for accessing the S3 bucket +# APP_STORAGE__S3__SECRET_ACCESS_KEY="your-s3-secret-access-key" +# Session token for accessing the S3 bucket (optional) +# APP_STORAGE__S3__SESSION_TOKEN="your-s3-session-token"