

chore: improve api docs
@b29e0ba26b152110d52626a92e7f61fc51498ad8
--- faster_whisper_server/main.py
+++ faster_whisper_server/main.py
... | ... | @@ -104,7 +104,10 @@ |
104 | 104 |
|
105 | 105 |
|
106 | 106 |
@app.get("/v1/models/{model_name:path}") |
107 |
-def get_model(model_name: Annotated[str, Path()]) -> ModelObject: |
|
107 |
+# NOTE: `examples` doesn't work https://github.com/tiangolo/fastapi/discussions/10537 |
|
108 |
+def get_model( |
|
109 |
+ model_name: Annotated[str, Path(example="Systran/faster-distil-whisper-large-v3")], |
|
110 |
+) -> ModelObject: |
|
108 | 111 |
models = list( |
109 | 112 |
huggingface_hub.list_models(model_name=model_name, library="ctranslate2") |
110 | 113 |
) |
... | ... | @@ -148,7 +151,10 @@ |
148 | 151 |
ModelName = Annotated[str, AfterValidator(handle_default_openai_model)] |
149 | 152 |
|
150 | 153 |
|
151 |
-@app.post("/v1/audio/translations") |
|
154 |
+@app.post( |
|
155 |
+ "/v1/audio/translations", |
|
156 |
+ response_model=str | TranscriptionJsonResponse | TranscriptionVerboseJsonResponse, |
|
157 |
+) |
|
152 | 158 |
def translate_file( |
153 | 159 |
file: Annotated[UploadFile, Form()], |
154 | 160 |
model: Annotated[ModelName, Form()] = config.whisper.model, |
... | ... | @@ -156,6 +162,11 @@ |
156 | 162 |
response_format: Annotated[ResponseFormat, Form()] = config.default_response_format, |
157 | 163 |
temperature: Annotated[float, Form()] = 0.0, |
158 | 164 |
stream: Annotated[bool, Form()] = False, |
165 |
+) -> ( |
|
166 |
+ str |
|
167 |
+ | TranscriptionJsonResponse |
|
168 |
+ | TranscriptionVerboseJsonResponse |
|
169 |
+ | StreamingResponse |
|
159 | 170 |
): |
160 | 171 |
start = time.perf_counter() |
161 | 172 |
whisper = load_model(model) |
... | ... | @@ -201,7 +212,10 @@ |
201 | 212 |
|
202 | 213 |
# https://platform.openai.com/docs/api-reference/audio/createTranscription |
203 | 214 |
# https://github.com/openai/openai-openapi/blob/master/openapi.yaml#L8915 |
204 |
-@app.post("/v1/audio/transcriptions") |
|
215 |
+@app.post( |
|
216 |
+ "/v1/audio/transcriptions", |
|
217 |
+ response_model=str | TranscriptionJsonResponse | TranscriptionVerboseJsonResponse, |
|
218 |
+) |
|
205 | 219 |
def transcribe_file( |
206 | 220 |
file: Annotated[UploadFile, Form()], |
207 | 221 |
model: Annotated[ModelName, Form()] = config.whisper.model, |
... | ... | @@ -214,6 +228,11 @@ |
214 | 228 |
Form(alias="timestamp_granularities[]"), |
215 | 229 |
] = ["segment"], |
216 | 230 |
stream: Annotated[bool, Form()] = False, |
231 |
+) -> ( |
|
232 |
+ str |
|
233 |
+ | TranscriptionJsonResponse |
|
234 |
+ | TranscriptionVerboseJsonResponse |
|
235 |
+ | StreamingResponse |
|
217 | 236 |
): |
218 | 237 |
start = time.perf_counter() |
219 | 238 |
whisper = load_model(model) |
--- faster_whisper_server/server_models.py
+++ faster_whisper_server/server_models.py
... | ... | @@ -130,8 +130,6 @@ |
130 | 130 |
|
131 | 131 |
|
132 | 132 |
class ModelObject(BaseModel): |
133 |
- model_config = ConfigDict(populate_by_name=True) |
|
134 |
- |
|
135 | 133 |
id: str |
136 | 134 |
"""The model identifier, which can be referenced in the API endpoints.""" |
137 | 135 |
created: int |
... | ... | @@ -140,3 +138,29 @@ |
140 | 138 |
"""The object type, which is always "model".""" |
141 | 139 |
owned_by: str |
142 | 140 |
"""The organization that owns the model.""" |
141 |
+ |
|
142 |
+ model_config = ConfigDict( |
|
143 |
+ populate_by_name=True, |
|
144 |
+ json_schema_extra={ |
|
145 |
+ "examples": [ |
|
146 |
+ { |
|
147 |
+ "id": "Systran/faster-whisper-large-v3", |
|
148 |
+ "created": 1700732060, |
|
149 |
+ "object": "model", |
|
150 |
+ "owned_by": "Systran", |
|
151 |
+ }, |
|
152 |
+ { |
|
153 |
+ "id": "Systran/faster-distil-whisper-large-v3", |
|
154 |
+ "created": 1711378296, |
|
155 |
+ "object": "model", |
|
156 |
+ "owned_by": "Systran", |
|
157 |
+ }, |
|
158 |
+ { |
|
159 |
+ "id": "bofenghuang/whisper-large-v2-cv11-french-ct2", |
|
160 |
+ "created": 1687968011, |
|
161 |
+ "object": "model", |
|
162 |
+ "owned_by": "bofenghuang", |
|
163 |
+ }, |
|
164 |
+ ] |
|
165 |
+ }, |
|
166 |
+ ) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?