mirror of
https://github.com/codeflash-ai/codeflash-internal.git
synced 2026-05-04 18:25:18 +00:00
35 lines
1.6 KiB
Markdown
35 lines
1.6 KiB
Markdown
|
|
# 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
|
||
|
|
|
||
|
|
1. Write a Django-Ninja router module `code_review_router.py` that:
|
||
|
|
- Creates a `NinjaAPI` instance named `code_review_api`
|
||
|
|
- Has a single `POST /` endpoint that is `async def`
|
||
|
|
- Accepts an `AuthenticatedRequest` and 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}`
|
||
|
|
|
||
|
|
2. Write a request schema `CodeReviewSchema` (inheriting from `ninja.Schema`) that includes:
|
||
|
|
- `source_code: str`
|
||
|
|
- `trace_id: str`
|
||
|
|
- `language: str` with a default of `"python"`
|
||
|
|
- `review_depth: str` with a default of `"standard"`
|
||
|
|
|
||
|
|
3. Show how this endpoint would be registered in `aiservice/urls.py` alongside the existing endpoints.
|
||
|
|
|
||
|
|
## Expected Outputs
|
||
|
|
|
||
|
|
- A `code_review_router.py` module following the codeflash conventions
|
||
|
|
- A `CodeReviewSchema` class
|
||
|
|
- A URL registration snippet
|