|
11 | 11 | from fastapi.openapi.utils import get_openapi |
12 | 12 | from fastapi.responses import HTMLResponse, RedirectResponse |
13 | 13 | from fastapi.responses import PlainTextResponse |
| 14 | +from textwrap import dedent |
14 | 15 | from warnings import warn |
15 | 16 |
|
16 | 17 | from .utils import _jupyter_nb |
@@ -105,10 +106,12 @@ def pin_url(): |
105 | 106 |
|
106 | 107 | @app.get("/ping", include_in_schema=True) |
107 | 108 | async def ping(): |
| 109 | + """Ping endpoint for health check""" |
108 | 110 | return {"ping": "pong"} |
109 | 111 |
|
110 | 112 | @app.get("/metadata") |
111 | 113 | async def get_metadata(): |
| 114 | + """Get metadata from model""" |
112 | 115 | return self.model.metadata.to_dict() |
113 | 116 |
|
114 | 117 | self.vetiver_post( |
@@ -183,13 +186,21 @@ def vetiver_post(self, endpoint_fx: Callable, endpoint_name: str = None, **kw): |
183 | 186 | if not endpoint_name: |
184 | 187 | endpoint_name = endpoint_fx.__name__ |
185 | 188 |
|
| 189 | + if endpoint_fx.__doc__ is not None: |
| 190 | + api_desc = dedent(endpoint_fx.__doc__) |
| 191 | + else: |
| 192 | + api_desc = None |
| 193 | + |
186 | 194 | if self.check_prototype is True: |
187 | 195 |
|
188 | | - @self.app.post(urljoin("/", endpoint_name), name=endpoint_name) |
| 196 | + @self.app.post( |
| 197 | + urljoin("/", endpoint_name), |
| 198 | + name=endpoint_name, |
| 199 | + description=api_desc, |
| 200 | + ) |
189 | 201 | async def custom_endpoint(input_data: List[self.model.prototype]): |
190 | 202 | _to_frame = api_data_to_frame(input_data) |
191 | 203 | predictions = endpoint_fx(_to_frame, **kw) |
192 | | - |
193 | 204 | if isinstance(predictions, List): |
194 | 205 | return {endpoint_name: predictions} |
195 | 206 | else: |
|
0 commit comments