@@ -44,7 +44,7 @@ impl Server {
44
44
Self { config, port }
45
45
}
46
46
47
- pub async fn build_router ( & self ) -> anyhow:: Result < Router > {
47
+ pub async fn build_router ( & self ) -> anyhow:: Result < Router < ( ) > > {
48
48
let api_key = self . config . general . as_ref ( ) . and_then ( |g| g. api_key . clone ( ) ) ;
49
49
50
50
let mut services = HashMap :: new ( ) ;
@@ -77,9 +77,13 @@ impl Server {
77
77
let app_state = Arc :: new ( AppState { api_key, services } ) ;
78
78
79
79
let stt_router = self . build_stt_router ( app_state. clone ( ) ) . await ;
80
-
81
- let app = Router :: new ( )
80
+ let other_router = Router :: new ( )
82
81
. route ( "/health" , axum:: routing:: get ( health) )
82
+ . route ( "/models" , axum:: routing:: get ( list_models) )
83
+ . route ( "/v1/models" , axum:: routing:: get ( list_models) )
84
+ . with_state ( app_state. clone ( ) ) ;
85
+
86
+ let app = other_router
83
87
. merge ( stt_router)
84
88
// .layer(middleware::from_fn_with_state(
85
89
// app_state.clone(),
@@ -125,7 +129,7 @@ impl Server {
125
129
Ok ( addr. port ( ) )
126
130
}
127
131
128
- async fn build_stt_router ( & self , app_state : Arc < AppState > ) -> Router {
132
+ async fn build_stt_router ( & self , app_state : Arc < AppState > ) -> Router < ( ) > {
129
133
Router :: new ( )
130
134
. route ( "/listen" , axum:: routing:: any ( handle_transcription) )
131
135
. route ( "/v1/listen" , axum:: routing:: any ( handle_transcription) )
@@ -249,6 +253,34 @@ async fn health() -> &'static str {
249
253
"OK"
250
254
}
251
255
256
+ #[ derive( serde:: Serialize ) ]
257
+ struct ModelInfo {
258
+ id : String ,
259
+ object : String ,
260
+ }
261
+
262
+ #[ derive( serde:: Serialize ) ]
263
+ struct ModelsResponse {
264
+ object : String ,
265
+ data : Vec < ModelInfo > ,
266
+ }
267
+
268
+ async fn list_models ( State ( state) : State < Arc < AppState > > ) -> axum:: Json < ModelsResponse > {
269
+ let models: Vec < ModelInfo > = state
270
+ . services
271
+ . keys ( )
272
+ . map ( |id| ModelInfo {
273
+ id : id. clone ( ) ,
274
+ object : "model" . to_string ( ) ,
275
+ } )
276
+ . collect ( ) ;
277
+
278
+ axum:: Json ( ModelsResponse {
279
+ object : "list" . to_string ( ) ,
280
+ data : models,
281
+ } )
282
+ }
283
+
252
284
async fn auth_middleware (
253
285
State ( state) : State < Arc < AppState > > ,
254
286
token_header : Option < TypedHeader < Authorization < Token > > > ,
0 commit comments