Skip to content

Commit

Permalink
add GET /api/v1/admin/backend_settings/{full/public} endpoint for api…
Browse files Browse the repository at this point in the history
…-clients (#830)

* add GET /api/v1/admin/backend_settings endpoint for trusted api-clients

* add backend_settings/public for untrusted api_clients
  • Loading branch information
andreaskoepf committed Jan 19, 2023
1 parent 335af5d commit ef8a00e
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion backend/oasst_backend/api/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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
Expand All @@ -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),
Expand All @@ -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
Expand Down

0 comments on commit ef8a00e

Please sign in to comment.