Properly fix the /v1/models endpoint

This commit is contained in:
oobabooga 2025-06-19 10:25:55 -07:00
parent 93cd47c948
commit 84617abdeb
2 changed files with 10 additions and 1 deletions

View file

@ -18,6 +18,15 @@ def list_models():
return {'model_names': get_available_models()}
def list_models_openai_format():
"""Returns model list in OpenAI API format"""
model_names = get_available_models()
return {
"object": "list",
"data": [model_info_dict(name) for name in model_names]
}
def model_info_dict(model_name: str) -> dict:
return {
"id": model_name,

View file

@ -180,7 +180,7 @@ async def handle_models(request: Request):
is_list = request.url.path.split('?')[0].split('#')[0] == '/v1/models'
if is_list:
response = OAImodels.list_models()['model_names']
response = OAImodels.list_models_openai_format()
else:
model_name = path[len('/v1/models/'):]
response = OAImodels.model_info_dict(model_name)