mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-30 16:40:05 +08:00
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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user