write a simple fastapi server, make it do something useful please
- User
write a simple fastapi server, make it do something useful please
Assistant
Here's a simple FastAPI server that exposes an endpoint to calculate the factorial of a given number. You can install FastAPI using the command
pip install fastapiif you haven't already.pythonfrom fastapi import FastAPI from typing import Optional app = FastAPI() def factorial(n: int) -> int: if n == 0: return 1 else: return n * factorial(n - 1) @app.get("/factorial") def calculate_factorial(n: Optional[int] = None) -> dict: if n is None: return {"error": "Please provide a number"} elif n < 0: return {"error": "Number should be non-negative"} else: return {"factorial": factorial(n)}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.