11namespace MaIN . Domain . Models ;
22
3- public struct Model
3+ public class Model
44{
5- public string Name { get ; set ; }
6- public string FileName { get ; set ; }
7- public string DownloadUrl { get ; set ; }
8- public string Description { get ; set ; }
9- public string Path { get ; set ; }
5+ public required string Name { get ; init ; }
6+ public required string FileName { get ; init ; }
7+ public string ? DownloadUrl { get ; set ; }
8+ public string ? Description { get ; set ; }
9+ public string ? Path { get ; set ; }
1010}
1111
1212public struct KnownModels
1313{
14- internal static Dictionary < string , Model > Models => new ( StringComparer . OrdinalIgnoreCase )
14+ internal static List < Model > Models => new ( )
1515 {
16- {
17- KnownModelNames . Gemma2_2b , new Model ( )
16+
17+ new Model ( )
1818 {
1919 Description = string . Empty ,
2020 Name = KnownModelNames . Gemma2_2b ,
2121 FileName = "gemma2-2b.gguf" ,
2222 DownloadUrl = "https://huggingface.co/TheBloke/gemma2-2b-quantized/resolve/main/gemma2-2b-quantized.bin" ,
23- }
24- } ,
25- {
26- KnownModelNames . Llama3_2_3b , new Model ( )
23+ } ,
24+ new Model ( )
2725 {
2826 Description = string . Empty ,
2927 Name = KnownModelNames . Llama3_2_3b ,
3028 FileName = "Llama3.2-3b.gguf" ,
3129 DownloadUrl = string . Empty
32- }
33- } ,
34- {
35- KnownModelNames . Llama3_1_8b , new Model ( )
30+ } ,
31+ new Model ( )
3632 {
3733 Description = string . Empty ,
3834 Name = KnownModelNames . Llama3_1_8b ,
3935 FileName = "Llama3.1-8b.gguf" ,
4036 DownloadUrl = string . Empty
41- }
42- } ,
43- {
44- KnownModelNames . Llava_7b , new Model ( )
37+ } ,
38+ new Model ( )
4539 {
4640 Description = string . Empty ,
4741 Name = KnownModelNames . Llava_7b ,
4842 FileName = "Llava.gguf" ,
4943 DownloadUrl = string . Empty ,
50- }
51- } ,
52- {
53- KnownModelNames . Phi_mini , new Model ( )
44+ } ,
45+ new Model ( )
5446 {
5547 Description = string . Empty ,
5648 Name = KnownModelNames . Phi_mini ,
5749 FileName = "phi3.5.gguf" ,
5850 DownloadUrl = string . Empty
59- }
60- } ,
61- {
62- KnownModelNames . Qwen2_5_0_5b , new Model ( )
51+ } ,
52+ new Model ( )
6353 {
6454 Description = string . Empty ,
6555 Name = KnownModelNames . Qwen2_5_0_5b ,
6656 FileName = "Qwen2.5.gguf" ,
6757 DownloadUrl = string . Empty
68- }
69- } ,
70- {
71- KnownModelNames . DeepSeek_R1_8b , new Model ( )
58+ } ,
59+ new Model ( )
7260 {
7361 Description = string . Empty ,
7462 Name = KnownModelNames . DeepSeek_R1_8b ,
7563 FileName = "DeepSeekR1-8b.gguf" ,
7664 DownloadUrl = string . Empty
77- }
78- } ,
79- {
80- KnownModelNames . Fox_1_6b , new Model ( )
65+ } ,
66+ new Model ( )
8167 {
8268 Description = string . Empty ,
8369 Name = KnownModelNames . Fox_1_6b ,
8470 FileName = "Fox-1.6b.gguf" ,
8571 DownloadUrl = string . Empty
8672 }
87- } ,
8873 } ;
8974
9075 public static Model GetEmbeddingModel ( ) =>
@@ -96,27 +81,28 @@ public static Model GetEmbeddingModel() =>
9681 DownloadUrl = string . Empty ,
9782 } ;
9883
99- public static Model GetModel ( string ? path , string name )
84+ public static Model GetModel ( string path , string name )
10085 {
101- var isPresent = Models . TryGetValue ( name , out var model ) ;
102- if ( ! isPresent )
86+ var model = Models . FirstOrDefault ( x => x . Name . Equals ( name , StringComparison . InvariantCultureIgnoreCase )
87+ || x . Name . Replace ( ':' , '-' ) . Equals ( name ,
88+ StringComparison . InvariantCultureIgnoreCase ) ) ;
89+ if ( model is null )
10390 {
10491 //todo support domain specific exceptions
10592 throw new Exception ( $ "Model { name } is not supported") ;
10693 }
10794
10895 if ( File . Exists ( Path . Combine ( path , model . FileName ) ) )
10996 {
110- return Models [ name ] ;
97+ return model ;
11198 }
11299
113100 throw new Exception ( $ "Model { name } is not downloaded") ;
114101 }
115102
116103 public static Model ? GetModelByFileName ( string path , string fileName )
117104 {
118- var models = Models . Values . ToList ( ) ;
119- var isPresent = models . Exists ( x => x . FileName == fileName ) ;
105+ var isPresent = Models . Exists ( x => x . FileName == fileName ) ;
120106 if ( ! isPresent )
121107 {
122108 //todo support domain specific exceptions
@@ -126,15 +112,15 @@ public static Model GetModel(string? path, string name)
126112
127113 if ( File . Exists ( Path . Combine ( path , fileName ) ) )
128114 {
129- return models . First ( x => x . FileName == fileName ) ;
115+ return Models . First ( x => x . FileName == fileName ) ;
130116 }
131117
132118 throw new Exception ( $ "Model { fileName } is not downloaded") ;
133119 }
134120
135121 public static void AddModel ( string model , string path )
136122 {
137- Models . Add ( model , new Model ( )
123+ Models . Add ( new Model ( )
138124 {
139125 Description = string . Empty ,
140126 DownloadUrl = string . Empty ,
@@ -154,6 +140,6 @@ public struct KnownModelNames
154140 public const string Phi_mini = "phi3:mini" ;
155141 public const string Llava_7b = "llava:7b" ;
156142 public const string Qwen2_5_0_5b = "qwen2.5:0.5b" ;
157- public const string DeepSeek_R1_8b = "deepseek:r1_8b " ;
143+ public const string DeepSeek_R1_8b = "deepseekR1-8b " ;
158144 public const string Fox_1_6b = "fox:1.6b" ;
159145}
0 commit comments