chatkit-server-integration
This skill provides functionality to properly expose a ChatKit server via FastAPI routes. It handles the integration between FastAPI request/response cycle and the ChatKit server, with proper request processing and response handling.
When & Why to Use This Skill
The ChatKit Server Integration skill streamlines the process of exposing ChatKit functionality through FastAPI routes. It automates the complex integration between the FastAPI request/response cycle and the ChatKit server, ensuring efficient payload processing and robust support for both standard JSON and real-time streaming responses (SSE). This tool is essential for developers looking to build scalable, high-performance AI chat backends with minimal boilerplate code.
Use Cases
- Developing AI-powered chat applications that require seamless integration between a FastAPI backend and ChatKit processing logic.
- Implementing real-time streaming responses for Large Language Model (LLM) interactions to enhance user experience with low-latency feedback.
- Standardizing API endpoint structures for AI agents to ensure consistent handling of raw payloads and context-aware request processing.
- Rapidly prototyping web-based interfaces for ChatKit servers by automating route registration and response type management.
| name | chatkit-server-integration |
|---|---|
| description | This skill provides functionality to properly expose a ChatKit server via FastAPI routes. It handles the integration between FastAPI request/response cycle and the ChatKit server, with proper request processing and response handling. |
ChatKit Server Integration Skill
Description
This skill provides functionality to properly expose a ChatKit server via FastAPI routes. It handles the integration between FastAPI request/response cycle and the ChatKit server, with proper request processing and response handling.
Parameters
route_path(string): The path for the FastAPI route (default: "/chat")
Precondition
- FastAPI application instance available
- ChatKit server instance properly configured
Execution
- Creates a FastAPI POST route at the specified path
- Gets raw payload from request body
- Processes the payload using the ChatKit server with proper context
- Returns appropriate response based on result type (streaming or regular)
Example Usage
from fastapi import APIRouter
from chatkit.server import StreamingResult
from src.services.chatkit_server import chatkit_server
router = APIRouter()
@router.post("/chat", response_class=Response)
async def chat_endpoint(request: Request):
# Get raw payload
payload = await request.body()
# Process with ChatKit server
context = {"request": request}
result = await chatkit_server.process(payload, context)
# Return appropriate response
if isinstance(result, StreamingResult):
return StreamingResponse(result, media_type="text/event-stream")
return Response(content=result.json, media_type="application/json")
Postcondition
- FastAPI route is properly registered with ChatKit server integration
- Request/response cycle is properly managed between FastAPI and ChatKit
- Both streaming and regular responses are supported