write a simple fastapi server, make it do something useful please
- User
write a simple fastapi server, make it do something useful please
- Assistant
Certainly! Here's an example of a simple FastAPI server that calculates the square of a number:
from fastapi import FastAPI app = FastAPI() @app.get("/square/{number}") def calculate_square(number: int): square = number ** 2 return {"result": square}To run the server, save the code in a file (e.g.,
main.py) and execute it with the following command:uvicorn main:app --reloadNow, you can access the server at
http://localhost:8000/square/{number}, where{number}is the number you want to calculate the square of.For example, if you open
http://localhost:8000/square/5in your browser or send a GET request to that URL, you should receive the following response:{"result": 25}Feel free to modify the code to perform any other useful computations or implement additional endpoints.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.