mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-10 00:20:06 +08:00
ee50b573e1
* [NEW] utils: Endpoint Toxic Roberta * [NEW] Constants API URL * [NEW] Git ignore venv * [NEW] Lint * [NEW] Backend default args * [NEW] HUGGINGFACE_API_ERROR * [NEW] Requests package * [NEW] Get Toxicity Endpoint * [NEW] Schema: ToxicityClassification [NEW] Constants module [FIX] Module * [FIX] Test Key HF * [NEW] settings: HUGGING_FACE_API_KEY * [NEW] Remove requests * [NEW] HuggingFace client * [NEW] Cleaning code
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from typing import Any, Dict, List, Optional, Union
|
|
|
|
from pydantic import AnyHttpUrl, BaseSettings, PostgresDsn, validator
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
PROJECT_NAME: str = "open-assistant backend"
|
|
API_V1_STR: str = "/api/v1"
|
|
|
|
POSTGRES_HOST: str = "localhost"
|
|
POSTGRES_PORT: str = "5432"
|
|
POSTGRES_USER: str = "postgres"
|
|
POSTGRES_PASSWORD: str = "postgres"
|
|
POSTGRES_DB: str = "postgres"
|
|
DATABASE_URI: Optional[PostgresDsn] = None
|
|
|
|
RATE_LIMIT: bool = True
|
|
REDIS_HOST: str = "localhost"
|
|
REDIS_PORT: str = "6379"
|
|
|
|
DEBUG_ALLOW_ANY_API_KEY: bool = False
|
|
DEBUG_SKIP_API_KEY_CHECK: bool = False
|
|
DEBUG_USE_SEED_DATA: bool = False
|
|
|
|
HUGGING_FACE_API_KEY: str = ""
|
|
|
|
@validator("DATABASE_URI", pre=True)
|
|
def assemble_db_connection(cls, v: Optional[str], values: Dict[str, Any]) -> Any:
|
|
if isinstance(v, str):
|
|
return v
|
|
return PostgresDsn.build(
|
|
scheme="postgresql",
|
|
user=values.get("POSTGRES_USER"),
|
|
password=values.get("POSTGRES_PASSWORD"),
|
|
host=values.get("POSTGRES_HOST"),
|
|
port=values.get("POSTGRES_PORT"),
|
|
path=f"/{values.get('POSTGRES_DB') or ''}",
|
|
)
|
|
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
UPDATE_ALEMBIC: bool = True
|
|
|
|
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
elif isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
|
|
settings = Settings(_env_file=".env")
|