[model-gateway] fix v1/models response format to be oai compatible (#13693)
Co-authored-by: Simo Lin <linsimo.mark@gmail.com>
This commit is contained in:
@@ -277,8 +277,7 @@ The SmartHome Mini is a compact smart home assistant available in black or white
|
|||||||
|
|
||||||
def test_model_list(self):
|
def test_model_list(self):
|
||||||
client = openai.Client(api_key=self.api_key, base_url=self.base_url)
|
client = openai.Client(api_key=self.api_key, base_url=self.base_url)
|
||||||
# TODO: Update the logic here when router /v1/models response format matching the openai api standard
|
models = list(client.models.list().data)
|
||||||
models = list(client.models.list().models)
|
|
||||||
assert len(models) == 1
|
assert len(models) == 1
|
||||||
# assert isinstance(getattr(models[0], "max_model_len", None), int)
|
# assert isinstance(getattr(models[0], "max_model_len", None), int)
|
||||||
|
|
||||||
|
|||||||
@@ -70,8 +70,7 @@ class TestToolChoiceLlama32(CustomTestCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = openai.Client(base_url=self.base_url, api_key=self.api_key)
|
self.client = openai.Client(base_url=self.base_url, api_key=self.api_key)
|
||||||
# TODO: Update the logic here when router /v1/models response format matching the openai api standard
|
self.model_name = self.client.models.list().data[0].id
|
||||||
self.model_name = self.client.models.list().models[0]
|
|
||||||
|
|
||||||
def _is_flaky_test(self):
|
def _is_flaky_test(self):
|
||||||
"""Check if the current test is marked as flaky for this class"""
|
"""Check if the current test is marked as flaky for this class"""
|
||||||
|
|||||||
@@ -334,14 +334,30 @@ impl RouterTrait for RouterManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn get_models(&self, _req: Request<Body>) -> Response {
|
async fn get_models(&self, _req: Request<Body>) -> Response {
|
||||||
let models = self.worker_registry.get_models();
|
let model_names = self.worker_registry.get_models();
|
||||||
|
|
||||||
if models.is_empty() {
|
if model_names.is_empty() {
|
||||||
(StatusCode::SERVICE_UNAVAILABLE, "No models available").into_response()
|
(StatusCode::SERVICE_UNAVAILABLE, "No models available").into_response()
|
||||||
} else {
|
} else {
|
||||||
|
// Convert model names to OpenAI-compatible model objects
|
||||||
|
let models: Vec<Value> = model_names
|
||||||
|
.iter()
|
||||||
|
.map(|name| {
|
||||||
|
serde_json::json!({
|
||||||
|
"id": name,
|
||||||
|
"object": "model",
|
||||||
|
"owned_by": "local"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
(
|
(
|
||||||
StatusCode::OK,
|
StatusCode::OK,
|
||||||
serde_json::json!({ "models": models }).to_string(),
|
serde_json::json!({
|
||||||
|
"object": "list",
|
||||||
|
"data": models
|
||||||
|
})
|
||||||
|
.to_string(),
|
||||||
)
|
)
|
||||||
.into_response()
|
.into_response()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user