Download app/products/web/webui/chat.py from LifeVta/Grok3API: direct link, hf CLI and curl.
- Browser
- Download file 1.28 kB
-
https://huggingface.co/spaces/LifeVta/Grok3API/resolve/main/app/products/web/webui/chat.py
- Command line
-
hf download hf://spaces/LifeVta/Grok3API/app/products/web/webui/chat.py
-
curl -L -o chat.py https://huggingface.co/spaces/LifeVta/Grok3API/resolve/main/app/products/web/webui/chat.py
1.28 kB
| """WebUI chat API routes.""" | |
| import time | |
| from fastapi import APIRouter, Depends | |
| from fastapi.responses import JSONResponse | |
| from app.control.model import registry as model_registry | |
| from app.platform.auth.middleware import verify_webui_key | |
| from app.products.openai.router import chat_completions_endpoint | |
| from app.products.openai.schemas import ChatCompletionRequest | |
| router = APIRouter(prefix="/webui/api", dependencies=[Depends(verify_webui_key)], tags=["WebUI - Chat"]) | |
| def _capability_name(spec) -> str: | |
| if spec.is_image_edit(): | |
| return "image_edit" | |
| if spec.is_image(): | |
| return "image" | |
| if spec.is_video(): | |
| return "video" | |
| return "chat" | |
| async def list_webui_models(): | |
| models = [ | |
| { | |
| "id": spec.model_name, | |
| "object": "model", | |
| "created": int(time.time()), | |
| "owned_by": "xai", | |
| "name": spec.public_name, | |
| "capability": _capability_name(spec), | |
| } | |
| for spec in model_registry.list_enabled() | |
| ] | |
| return JSONResponse({"object": "list", "data": models}) | |
| async def webui_chat_completions(req: ChatCompletionRequest): | |
| return await chat_completions_endpoint(req) | |
| __all__ = ["router"] | |