@@ -21,6 +21,7 @@ export const removeModelSuffix = (id: string) => {
21
21
. replace ( / _ l l a m a f i l e _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } / , "" )
22
22
. replace ( / _ o l l a m a 2 _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } / , "" )
23
23
. replace ( / _ l l a m a c p p _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } / , "" )
24
+ . replace ( / _ v l l m _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } / , "" )
24
25
}
25
26
export const isLMStudioModel = ( model : string ) => {
26
27
const lmstudioModelRegex =
@@ -39,6 +40,11 @@ export const isLLamaCppModel = (model: string) => {
39
40
return llamaCppModelRegex . test ( model )
40
41
}
41
42
43
+ export const isVLLMModel = ( model : string ) => {
44
+ const vllmModelRegex = / _ v l l m _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } /
45
+ return vllmModelRegex . test ( model )
46
+ }
47
+
42
48
export const isOllamaModel = ( model : string ) => {
43
49
const ollamaModelRegex =
44
50
/ _ o l l a m a 2 _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } /
@@ -98,6 +104,20 @@ export const getLLamaCppModelId = (
98
104
return null
99
105
}
100
106
107
+ export const getVLLMModelId = (
108
+ model : string
109
+ ) : { model_id : string ; provider_id : string } => {
110
+ const vllmModelRegex =
111
+ / _ v l l m _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } /
112
+ const match = model . match ( vllmModelRegex )
113
+ if ( match ) {
114
+ const modelId = match [ 0 ]
115
+ const providerId = match [ 0 ] . replace ( "_vllm_openai-" , "" )
116
+ return { model_id : modelId , provider_id : providerId }
117
+ }
118
+ return null
119
+ }
120
+
101
121
export const isCustomModel = ( model : string ) => {
102
122
if ( isLMStudioModel ( model ) ) {
103
123
return true
@@ -115,6 +135,10 @@ export const isCustomModel = (model: string) => {
115
135
return true
116
136
}
117
137
138
+ if ( isVLLMModel ( model ) ) {
139
+ return true
140
+ }
141
+
118
142
const customModelRegex =
119
143
/ _ m o d e l - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 , 4 } - [ a - f 0 - 9 ] { 4 } /
120
144
return customModelRegex . test ( model )
@@ -258,7 +282,7 @@ export const getModelInfo = async (id: string) => {
258
282
if ( isLLamaCppModel ( id ) ) {
259
283
const llamaCppId = getLLamaCppModelId ( id )
260
284
if ( ! llamaCppId ) {
261
- throw new Error ( "Invalid LMStudio model ID" )
285
+ throw new Error ( "Invalid llamaCPP model ID" )
262
286
}
263
287
264
288
return {
@@ -274,6 +298,24 @@ export const getModelInfo = async (id: string) => {
274
298
}
275
299
}
276
300
301
+ if ( isVLLMModel ( id ) ) {
302
+ const vllmId = getVLLMModelId ( id )
303
+ if ( ! vllmId ) {
304
+ throw new Error ( "Invalid Vllm model ID" )
305
+ }
306
+ return {
307
+ model_id : id . replace (
308
+ / _ v l l m _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } / ,
309
+ ""
310
+ ) ,
311
+ provider_id : `openai-${ vllmId . provider_id } ` ,
312
+ name : id . replace (
313
+ / _ v l l m _ o p e n a i - [ a - f 0 - 9 ] { 4 } - [ a - f 0 - 9 ] { 3 } - [ a - f 0 - 9 ] { 4 } / ,
314
+ ""
315
+ )
316
+ }
317
+ }
318
+
277
319
278
320
if ( isOllamaModel ( id ) ) {
279
321
const ollamaId = getOllamaModelId ( id )
@@ -388,6 +430,30 @@ export const dynamicFetchLLamaCpp = async ({
388
430
return llamaCppModels
389
431
}
390
432
433
+
434
+ export const dynamicFetchVLLM = async ( {
435
+ baseUrl,
436
+ providerId,
437
+ customHeaders = [ ]
438
+ } : {
439
+ baseUrl : string
440
+ providerId : string
441
+ customHeaders ?: { key : string ; value : string } [ ]
442
+ } ) => {
443
+ const models = await getAllOpenAIModels ( { baseUrl, customHeaders } )
444
+ const vllmModels = models . map ( ( e ) => {
445
+ return {
446
+ name : e ?. name || e ?. id ,
447
+ id : `${ e ?. id } _vllm_${ providerId } ` ,
448
+ provider : providerId ,
449
+ lookup : `${ e ?. id } _${ providerId } ` ,
450
+ provider_id : providerId
451
+ }
452
+ } )
453
+
454
+ return vllmModels
455
+ }
456
+
391
457
export const dynamicFetchOllama2 = async ( {
392
458
baseUrl,
393
459
providerId,
@@ -459,6 +525,10 @@ export const ollamaFormatAllCustomModels = async (
459
525
( model ) => model . provider === "llamacpp"
460
526
)
461
527
528
+ const vllmProviders = allProviders . filter (
529
+ ( model ) => model . provider === "vllm"
530
+ )
531
+
462
532
const lmModelsPromises = lmstudioProviders . map ( ( provider ) =>
463
533
dynamicFetchLMStudio ( {
464
534
baseUrl : provider . baseUrl ,
@@ -489,6 +559,13 @@ export const ollamaFormatAllCustomModels = async (
489
559
customHeaders : provider . headers
490
560
} ) )
491
561
562
+ const vllmModelsPromises = vllmProviders . map ( ( provider ) =>
563
+ dynamicFetchVLLM ( {
564
+ baseUrl : provider . baseUrl ,
565
+ providerId : provider . id ,
566
+ customHeaders : provider . headers
567
+ } ) )
568
+
492
569
const lmModelsFetch = await Promise . all ( lmModelsPromises )
493
570
494
571
const llamafileModelsFetch = await Promise . all ( llamafileModelsPromises )
@@ -497,6 +574,8 @@ export const ollamaFormatAllCustomModels = async (
497
574
498
575
const llamacppModelsFetch = await Promise . all ( llamacppModelsPromises )
499
576
577
+ const vllmModelsFetch = await Promise . all ( vllmModelsPromises )
578
+
500
579
const lmModels = lmModelsFetch . flat ( )
501
580
502
581
const llamafileModels = llamafileModelsFetch . flat ( )
@@ -505,6 +584,8 @@ export const ollamaFormatAllCustomModels = async (
505
584
506
585
const llamacppModels = llamacppModelsFetch . flat ( )
507
586
587
+ const vllmModels = vllmModelsFetch . flat ( )
588
+
508
589
// merge allModels and lmModels
509
590
const allModlesWithLMStudio = [
510
591
...( modelType !== "all"
@@ -513,7 +594,8 @@ export const ollamaFormatAllCustomModels = async (
513
594
...lmModels ,
514
595
...llamafileModels ,
515
596
...ollama2Models ,
516
- ...llamacppModels
597
+ ...llamacppModels ,
598
+ ...vllmModels
517
599
]
518
600
519
601
const ollamaModels = allModlesWithLMStudio . map ( ( model ) => {
0 commit comments