mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
1.6 KiB
1.6 KiB
Task: Build a Language-Dispatching Router for a New Endpoint
Context
You are adding a new code_review endpoint to the codeflash-internal aiservice backend. The existing optimization and testgen endpoints both follow the same pattern: a Django-Ninja router that dispatches to language-specific handlers based on a data.language field. Imports are kept lazy (inside the function body) to avoid circular dependencies.
The endpoint should be registered at /ai/code_review and follow the same conventions as the existing 12 endpoints in aiservice/urls.py.
Task
-
Write a Django-Ninja router module
code_review_router.pythat:- Creates a
NinjaAPIinstance namedcode_review_api - Has a single
POST /endpoint that isasync def - Accepts an
AuthenticatedRequestand a request body schema - Dispatches by
data.language:"javascript"or"typescript"calls a JS/TS handler"java"calls a Java handler- Default (Python) calls a Python handler
- Uses lazy imports inside the function body
- Returns typed response schemas:
response={200: SuccessSchema, 400: ErrorSchema, 500: ErrorSchema}
- Creates a
-
Write a request schema
CodeReviewSchema(inheriting fromninja.Schema) that includes:source_code: strtrace_id: strlanguage: strwith a default of"python"review_depth: strwith a default of"standard"
-
Show how this endpoint would be registered in
aiservice/urls.pyalongside the existing endpoints.
Expected Outputs
- A
code_review_router.pymodule following the codeflash conventions - A
CodeReviewSchemaclass - A URL registration snippet