-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
John Dutchover
committed
Feb 15, 2024
1 parent
48fcea2
commit dd0e0c7
Showing
1 changed file
with
12 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |