mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-28 16:20:34 +08:00
cc03376d86
* added root tokens and endpoint for adding api keys * Change down revision to current alembic head * removed added_by_root_token * refactored description * fixed jinja errors Co-authored-by: Andreas Köpf <andreas.koepf@provisio.com>
32 lines
901 B
Python
32 lines
901 B
Python
import pydantic
|
|
from fastapi import APIRouter, Depends
|
|
from loguru import logger
|
|
from oasst_backend.api import deps
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class CreateApiClientRequest(pydantic.BaseModel):
|
|
description: str
|
|
frontend_type: str
|
|
trusted: bool | None = False
|
|
admin_email: str | None = None
|
|
|
|
|
|
@router.post("/api_client")
|
|
async def create_api_client(
|
|
request: CreateApiClientRequest,
|
|
root_token: str = Depends(deps.get_root_token),
|
|
session: deps.Session = Depends(deps.get_db),
|
|
) -> str:
|
|
logger.info(f"Creating new api client with {request=}")
|
|
api_client = deps.create_api_client(
|
|
session=session,
|
|
description=request.description,
|
|
frontend_type=request.frontend_type,
|
|
trusted=request.trusted,
|
|
admin_email=request.admin_email,
|
|
)
|
|
logger.info(f"Created api_client with key {api_client.api_key}")
|
|
return api_client.api_key
|