-
Notifications
You must be signed in to change notification settings - Fork 0
/
router.py
79 lines (70 loc) · 2.22 KB
/
router.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from enum import Enum
from fastapi import FastAPI, Body, Depends, APIRouter
from fastapi.openapi.docs import get_redoc_html
from fastapi.security import HTTPBearer
from fastapi.responses import HTMLResponse
from pydantic import BaseModel, Field
router = APIRouter()
class Foo(BaseModel):
test_1: str = Field(description="""\n
- aaa
- bbb
""")
class Bar(BaseModel):
array_1: list[int] =Field(description="""
- ccc
- ccc
""")
class ModelId(str, Enum):
alexnet1 = "alexnet"
resnet2 = "resnet"
lenet3 = "lenet"
@router.post(
"/{model_id}:predict",
summary="Create an item",
response_model=Bar,
tags=["xyz"],
response_description="The created item",
)
async def index(
model_id: ModelId,
# authorization: HTTPAuthorizationCredentials = Depends(HTTPBearer(description="ローカル開発では`abc`や`123`のような任意のテキストで良い。サービスではエンコード済みのJWT tokenを使う")),
foo: Foo = Body(
examples={
"normal": {
"summary": "A normal example",
"description": "A **normal** item works correctly.",
"value": {
"name": "Fooo",
"description": "A very nice Item",
"price": 35.4,
"tax": 3.2,
},
},
"converted": {
"summary": "An example with converted data",
"description": "FastAPI can convert price `strings` to actual `numbers` automatically",
"value": {
"name": "Barr",
"price": "35.4",
},
},
"invalid": {
"summary": "Invalid data is rejected with an error",
"value": {
"name": "Baz",
"price": "thirty five point four",
},
},
},
),
):
"""
Create an item with all the information:
- **name**: each item must have a name
- **description**: a long description
- **price**: required
- **tax**: if the item doesn't have tax, you can omit this
- **tags**: a set of unique tag strings for this item
"""
return 123