vicuna-7b· LMSYS
Arena Human Preference 55K
write a simple fastapi server, make it do something useful please
- User
write a simple fastapi server, make it do something useful please
- Assistant
Sure, here's a simple FastAPI server that logs the number of incoming requests and responds with a message "Hello, World!":
pythonfrom fastapi import FastAPI app = FastAPI() @app.get("/") async def read_root(): return {"Hello": "World"} @app.get("/request_counter") async def read_request_counter(): request_counter = 0 async for request in app.start_server("0.0.0.0", 8000, reactor=None): request_counter += 1 return {"request_counter": request_counter}This server listens on all available network interfaces (0.0.0.0) on port 8000 and logs the number of incoming requests using an asynchronous generator. The
read_request_counterfunction returns a JSON object that contains the request counter value.To start the server, run the following command in your terminal:
codeuvicorn main:app --reloadThis will start the server and print the request counter value in the terminal. You can access the server at .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.