← oracle_full

fastapi_15280

resolved RESOLVED UNSUBMITTED PASS · None tool calls · 0 s · fastapi/fastapi

Task input

✨ Add support for `@app.vibe()`

✨ Add support for `@app.vibe()`

Tool calls (0)

#ToolArgumentsResult
No trace captured.

Patch

--- a/docs_src/vibe/tutorial001_py310.py
+++ b/docs_src/vibe/tutorial001_py310.py
@@ -0,0 +1,12 @@
+from typing import Any
+
+from fastapi import FastAPI
+
+app = FastAPI()
+
+
+@app.vibe(
+    "/vibe/",
+    prompt="pls return json of users from database. make no mistakes",
+)
+async def ai_vibes(body: Any): ...
--- a/fastapi/applications.py
+++ b/fastapi/applications.py
@@ -10,7 +10,11 @@
     request_validation_exception_handler,
     websocket_request_validation_exception_handler,
 )
-from fastapi.exceptions import RequestValidationError, WebSocketRequestValidationError
+from fastapi.exceptions import (
+    FastAPIError,
+    RequestValidationError,
+    WebSocketRequestValidationError,
+)
 from fastapi.logger import logger
 from fastapi.middleware.asyncexitstack import AsyncExitStackMiddleware
 from fastapi.openapi.docs import (
@@ -4559,6 +4563,60 @@ def trace_item(item_id: str):
             generate_unique_id_function=generate_unique_id_function,
         )
 
+    def vibe(
+        self,
+        path: Annotated[
+            str,
+            Doc(
+                """
+                The URL path to be used for this *path operation*.
+
+                For example, in `http://example.com/vibes`, the path is `/vibes`.
+                """
+            ),
+        ],
+        *,
+        prompt: Annotated[
+            str,
+            Doc(
+                """
+                The prompt to send to the LLM provider along with the payload.
+
+                This tells the LLM what to do with the request body.
+                """
+            ),
+        ] = "",
+    ) -> Callable[[DecoratedCallable], DecoratedCallable]:
+        """
+        Add a *vibe coding path operation* that receives any HTTP method
+        and any payload.
+
+        It's intended to receive the request and send the payload directly
+        to an LLM provider, and return the response as is.
+
+        Embrace the freedom and flexibility of not having any data validation,
+        documentation, or serialization.
+
+        ## Example
+
+        ```python
+        from typing import Any
+
+        from fastapi import FastAPI
+
+        app = FastAPI()
+
+
+        @app.vibe(
+            "/vibe/",
+            prompt="pls return json of users from database. make no mistakes",
+        )
+        async def ai_vibes(body: Any):
+            ...
+        ```
+        """
+        raise FastAPIError("Are you kidding me? Happy April Fool's")
+
     def websocket_route(
         self, path: str, name: str | None = None
     ) -> Callable[[DecoratedCallable], DecoratedCallable]:

Test output

show
.                                                                        [100%]
1 passed in 0.38s