Skip to content

Commit c7f48ba

Browse files
aricshowBlaizzy
andauthored
/v1/models - format output to match OpenAI styling (#34)
* feat: /v1/models - Make OpenAI Compliant * doc: README.md - /v1/models * fix: Run pre-commit --------- Co-authored-by: Prince Canuma <[email protected]>
1 parent cd199d8 commit c7f48ba

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@
288288

289289
Please note that while streaming is available for regular text generation, the streaming implementation for function calling is still in development and does not yet fully comply with the OpenAI specification.
290290

291-
5. **Listing Available Models**
291+
5. **List Supported Models**
292292

293293
To see all vision and language models supported by MLX:
294294

@@ -300,7 +300,7 @@
300300
print(response.json())
301301
```
302302

303-
6. **List Available Models**
303+
6. **Add Available Model**
304304

305305
You can add new models to the API:
306306

@@ -316,9 +316,9 @@
316316
print(response.json())
317317
```
318318

319-
7. **Listing Available Models**
319+
7. **List Available Models**
320320

321-
To see all available models:
321+
Provides the list of available models that have been added in a OpenAI compliant format:
322322

323323
```python
324324
import requests

fastmlx/fastmlx.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import argparse
99
import asyncio
1010
import os
11+
import time
1112
from typing import Any, Dict, List
1213
from urllib.parse import unquote
1314

@@ -269,12 +270,20 @@ async def get_supported_models():
269270
@app.get("/v1/models")
270271
async def list_models():
271272
"""
272-
List all available (loaded) models.
273-
274-
Returns:
275-
dict (dict): A dictionary containing the list of available models.
273+
Get list of models - provided in OpenAI API compliant format.
276274
"""
277-
return {"models": await model_provider.get_available_models()}
275+
models = await model_provider.get_available_models()
276+
models_data = []
277+
for model in models:
278+
models_data.append(
279+
{
280+
"id": model,
281+
"object": "model",
282+
"created": int(time.time()),
283+
"owned_by": "system",
284+
}
285+
)
286+
return {"object": "list", "data": models_data}
278287

279288

280289
@app.post("/v1/models")

0 commit comments

Comments
 (0)