From ef8a00e68230667d15288db5445fc8381eac3b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6pf?= Date: Thu, 19 Jan 2023 12:48:26 +0100 Subject: [PATCH] add GET /api/v1/admin/backend_settings/{full/public} endpoint for api-clients (#830) * add GET /api/v1/admin/backend_settings endpoint for trusted api-clients * add backend_settings/public for untrusted api_clients --- backend/oasst_backend/api/v1/admin.py | 32 ++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/backend/oasst_backend/api/v1/admin.py b/backend/oasst_backend/api/v1/admin.py index fc04c272..e171e6a1 100644 --- a/backend/oasst_backend/api/v1/admin.py +++ b/backend/oasst_backend/api/v1/admin.py @@ -4,6 +4,7 @@ import pydantic from fastapi import APIRouter, Depends from loguru import logger from oasst_backend.api import deps +from oasst_backend.config import Settings, settings from oasst_backend.models.api_client import ApiClient from oasst_backend.prompt_repository import PromptRepository from oasst_backend.tree_manager import TreeManager @@ -21,7 +22,7 @@ class CreateApiClientRequest(pydantic.BaseModel): admin_email: str | None = None -@router.post("/api_client") +@router.post("/api_client", response_model=str) async def create_api_client( request: CreateApiClientRequest, root_token: str = Depends(deps.get_root_token), @@ -39,6 +40,35 @@ async def create_api_client( return api_client.api_key +@router.get("/backend_settings/full", response_model=Settings) +async def get_backend_settings_full(api_client: ApiClient = Depends(deps.get_trusted_api_client)) -> Settings: + logger.info( + f"Backend settings requested by trusted api_client {api_client.id} (admin_email: {api_client.admin_email}, frontend_type: {api_client.frontend_type})" + ) + return settings + + +class PublicSettings(pydantic.BaseModel): + """Subset of backend settings which can be retrieved by untrusted API clients.""" + + PROJECT_NAME: str + API_V1_STR: str + DEBUG_USE_SEED_DATA: bool + DEBUG_ALLOW_SELF_LABELING: bool + DEBUG_SKIP_EMBEDDING_COMPUTATION: bool + DEBUG_SKIP_TOXICITY_CALCULATION: bool + DEBUG_DATABASE_ECHO: bool + USER_STATS_INTERVAL_DAY: int + USER_STATS_INTERVAL_WEEK: int + USER_STATS_INTERVAL_MONTH: int + USER_STATS_INTERVAL_TOTAL: int + + +@router.get("/backend_settings/public", response_model=PublicSettings) +async def get_backend_settings_public(api_client: ApiClient = Depends(deps.get_api_client)) -> PublicSettings: + return PublicSettings(**settings.dict()) + + class PurgeResultModel(pydantic.BaseModel): before: SystemStats after: SystemStats