[object Object]

← back to Exo

Fix the /v1/models API to output proper OpenAI compatible endpoint

627bfcae7cc4a34474eb5374d74d453d6cc6ddca · 2025-01-06 01:20:30 -0700 · Carsen Klock

Modify the `/v1/models` API to output a proper OpenAI compatible endpoint with an object and a `data` object containing the models list.

* Change the `handle_get_models` method in `exo/api/chatgpt_api.py` to wrap the models list in an object with a `data` field.
* Add an `object` field with the value "list" to the response format.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/metaspartan/exo?shareId=XXXX-XXXX-XXXX-XXXX).

Files touched

Diff

commit 627bfcae7cc4a34474eb5374d74d453d6cc6ddca
Author: Carsen Klock <carsenk@gmail.com>
Date:   Mon Jan 6 01:20:30 2025 -0700

    Fix the /v1/models API to output proper OpenAI compatible endpoint
    
    Modify the `/v1/models` API to output a proper OpenAI compatible endpoint with an object and a `data` object containing the models list.
    
    * Change the `handle_get_models` method in `exo/api/chatgpt_api.py` to wrap the models list in an object with a `data` field.
    * Add an `object` field with the value "list" to the response format.
    
    ---
    
    For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/metaspartan/exo?shareId=XXXX-XXXX-XXXX-XXXX).
---
 exo/api/chatgpt_api.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/exo/api/chatgpt_api.py b/exo/api/chatgpt_api.py
index ef963400..82068921 100644
--- a/exo/api/chatgpt_api.py
+++ b/exo/api/chatgpt_api.py
@@ -291,7 +291,8 @@ class ChatGPTAPI:
         )
 
   async def handle_get_models(self, request):
-    return web.json_response([{"id": model_name, "object": "model", "owned_by": "exo", "ready": True} for model_name, _ in model_cards.items()])
+    models_list = [{"id": model_name, "object": "model", "owned_by": "exo", "ready": True} for model_name, _ in model_cards.items()]
+    return web.json_response({"object": "list", "data": models_list})
 
   async def handle_post_chat_token_encode(self, request):
     data = await request.json()

← 29244c63 fix args for ensure_shard  ·  back to Exo  ·  add phi 3.5, phi 4 c5875933 →