mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
Add LLM creators endpoint and OpenAPI entry
Introduce a read endpoint for LLM model creators: add _map_creator_response serializer and an admin-only GET /llm/creators route that queries prisma.models.LlmModelCreator (ordered by name), logs results, and returns serialized creators with error handling. Also update frontend OpenAPI spec with the /api/llm/creators GET operation.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
"""Admin write API for LLM registry management.
|
||||
"""Admin API for LLM registry management.
|
||||
|
||||
Provides endpoints for creating, updating, and deleting:
|
||||
- Models
|
||||
- Providers
|
||||
Provides endpoints for:
|
||||
- Reading creators (GET)
|
||||
- Creating, updating, and deleting models
|
||||
- Creating, updating, and deleting providers
|
||||
|
||||
All endpoints require admin authentication and refresh the registry cache after mutations.
|
||||
All endpoints require admin authentication. Mutations refresh the registry cache.
|
||||
"""
|
||||
|
||||
import logging
|
||||
@@ -67,6 +68,21 @@ def _map_model_response(model: Any) -> dict[str, Any]:
|
||||
}
|
||||
|
||||
|
||||
def _map_creator_response(creator: Any) -> dict[str, Any]:
|
||||
"""Map Prisma creator model to response dict."""
|
||||
return {
|
||||
"id": creator.id,
|
||||
"name": creator.name,
|
||||
"display_name": creator.displayName,
|
||||
"description": creator.description,
|
||||
"website_url": creator.websiteUrl,
|
||||
"logo_url": creator.logoUrl,
|
||||
"metadata": dict(creator.metadata or {}),
|
||||
"created_at": creator.createdAt.isoformat() if creator.createdAt else None,
|
||||
"updated_at": creator.updatedAt.isoformat() if creator.updatedAt else None,
|
||||
}
|
||||
|
||||
|
||||
@router.post(
|
||||
"/llm/models",
|
||||
status_code=status.HTTP_201_CREATED,
|
||||
@@ -307,3 +323,25 @@ async def delete_provider(
|
||||
except Exception as e:
|
||||
logger.exception(f"Failed to delete provider: {e}")
|
||||
raise HTTPException(status_code=500, detail="Failed to delete provider")
|
||||
|
||||
|
||||
@router.get(
|
||||
"/llm/creators",
|
||||
dependencies=[Security(autogpt_libs.auth.requires_admin_user)],
|
||||
)
|
||||
async def list_creators() -> dict[str, Any]:
|
||||
"""List all LLM model creators.
|
||||
|
||||
Requires admin authentication.
|
||||
"""
|
||||
try:
|
||||
import prisma.models
|
||||
|
||||
creators = await prisma.models.LlmModelCreator.prisma().find_many(
|
||||
order={"name": "asc"}
|
||||
)
|
||||
logger.info(f"Retrieved {len(creators)} creators")
|
||||
return {"creators": [_map_creator_response(c) for c in creators]}
|
||||
except Exception as e:
|
||||
logger.exception(f"Failed to list creators: {e}")
|
||||
raise HTTPException(status_code=500, detail="Failed to list creators")
|
||||
|
||||
@@ -4603,6 +4603,32 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/llm/creators": {
|
||||
"get": {
|
||||
"tags": ["v2", "llm", "admin"],
|
||||
"summary": "List Creators",
|
||||
"description": "List all LLM model creators.\n\nRequires admin authentication.",
|
||||
"operationId": "getV2ListCreators",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"additionalProperties": true,
|
||||
"type": "object",
|
||||
"title": "Response Getv2Listcreators"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"401": {
|
||||
"$ref": "#/components/responses/HTTP401NotAuthenticatedError"
|
||||
}
|
||||
},
|
||||
"security": [{ "HTTPBearerJWT": [] }]
|
||||
}
|
||||
},
|
||||
"/api/llm/models": {
|
||||
"get": {
|
||||
"tags": ["v2", "llm", "llm"],
|
||||
|
||||
Reference in New Issue
Block a user