Skip to content

Commit

Permalink
fix facts.py
Browse files Browse the repository at this point in the history
  • Loading branch information
John Dutchover committed Feb 15, 2024
1 parent 48fcea2 commit dd0e0c7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions app/routers/facts.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
from pydantic import BaseModel
from typing import Dict
import marvin
from fastapi import APIRouter

router = APIRouter()


class FormatResponse(BaseModel):
value: Dict[int, str]
value: str


@marvin.fn
def random_fact(n: int) -> Dict[int, str]:
def generate_fact_ai(n: int) -> str:
"""
Get a random fact for `n` and return it in a dictionary with `n` as the key.
Get a random fact for `n` and return only the value of dictionary in response.
Args:
n (int): The number for which a random fact is to be generated.
Returns:
dict[int, str]: A dictionary with `n` as the key and the generated fact as the value.
str: The generated fact as the value.
"""
if n == 0:
return {0: "The factorial of 0 is 1."}
else:
return {n: f"A placeholder fact for {n}."}


@router.post("/random_fact")
def get_random_fact(n: int) -> Dict[int, str]:
return random_fact(n)
@router.post("/fact_to_number", response_model=FormatResponse)
async def get_text_post(n: int) -> FormatResponse:
return FormatResponse(value=generate_fact_ai(n))


@router.get("/fact_to_number", response_model=FormatResponse)
async def get_text_get(n: int) -> FormatResponse:
return FormatResponse(value=generate_fact_ai(n))

0 comments on commit dd0e0c7

Please sign in to comment.