add docstring to this import time from fastapi import FastAPI, Request app = FastAPI()…
- User
add docstring to this import time
from fastapi import FastAPI, Request
app = FastAPI()
@app.middleware("http") async def add_process_time_header(request: Request, call_next): start_time = time.time() response = await call_next(request) process_time = time.time() - start_time response.headers["X-Process-Time"] = str(process_time) return response
Assistant
Here's an example of how you could add a docstring to the function:
import time from fastapi import FastAPI, Request app = FastAPI() @app.middleware("http") async def add_process_time_header(request: Request, call_next: Request): """ Middleware function that adds a X-Process-Time header to the HTTP response. Args: request (Request): The incoming HTTP request. call_next (Request): The next middleware function to be called. Returns: The HTTP response with the added X-Process-Time header. """ start_time = time.time() response = await call_next(request) process_time = time.time() - start_time response.headers["X-Process-Time"] = str(process_time) return response
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.