@@ -136,89 +136,6 @@ public static IEnumerable<IGrouping<uint, CommitPredictionWithData>> GetClusters
136136 return results . GroupBy ( x => x . PredictedClusterId ) . OrderBy ( g => g . Key ) ;
137137 }
138138
139- public static async Task < Dictionary < uint , string > > PredictClusterNamesAsync ( IEnumerable < IGrouping < uint , CommitPredictionWithData > > clusters , string labelsFilePath , string modelName = "gemini-2.5-flash" )
140- {
141- if ( File . Exists ( labelsFilePath ) )
142- {
143- var json = File . ReadAllText ( labelsFilePath ) ;
144- var dict = JsonSerializer . Deserialize < Dictionary < string , string > > ( json ) ;
145- if ( dict != null && dict . Count > 0 )
146- {
147- Console . WriteLine ( $ "Loaded cluster names from { labelsFilePath } .") ;
148- return dict . ToDictionary ( k => uint . Parse ( k . Key ) , v => v . Value ) ;
149- }
150- }
151-
152- var apiKey = Environment . GetEnvironmentVariable ( "GEMINI_API_KEY" ) ;
153- if ( string . IsNullOrEmpty ( apiKey ) )
154- {
155- Console . WriteLine ( "GEMINI_API_KEY environment variable not found. Using default cluster numeric names." ) ;
156- return clusters . ToDictionary ( g => g . Key , g => $ "Cluster { g . Key } ") ;
157- }
158-
159- var clusterNames = new System . Collections . Generic . Dictionary < uint , string > ( ) ;
160- using var httpClient = new System . Net . Http . HttpClient ( ) ;
161-
162- Console . WriteLine ( "\n Predicting cluster names using Gemini API..." ) ;
163- foreach ( var cluster in clusters )
164- {
165- var commitsToUse = cluster . Take ( 10 ) . Select ( c => c . CommitName ) . ToList ( ) ;
166- var prompt = "Based on the following git commit messages, provide a short 1-3 word category name for this cluster.\n \n " +
167- "Commits:\n " + string . Join ( "\n " , commitsToUse ) + "\n \n Category name:" ;
168-
169- var requestBody = new
170- {
171- contents = new [ ]
172- {
173- new
174- {
175- parts = new [ ] { new { text = prompt } }
176- }
177- }
178- } ;
179-
180- var url = $ "https://generativelanguage.googleapis.com/v1beta/models/{ modelName } :generateContent?key={ apiKey } ";
181- var jsonContent = new System . Net . Http . StringContent ( JsonSerializer . Serialize ( requestBody ) , System . Text . Encoding . UTF8 , "application/json" ) ;
182-
183- try
184- {
185- var response = await httpClient . PostAsync ( url , jsonContent ) ;
186- if ( response . IsSuccessStatusCode )
187- {
188- var responseString = await response . Content . ReadAsStringAsync ( ) ;
189- using var doc = JsonDocument . Parse ( responseString ) ;
190- var text = doc . RootElement
191- . GetProperty ( "candidates" ) [ 0 ]
192- . GetProperty ( "content" )
193- . GetProperty ( "parts" ) [ 0 ]
194- . GetProperty ( "text" ) . GetString ( ) ;
195-
196- var cleanedName = text ? . Trim ( ) . TrimEnd ( '\r ' , '\n ' , '.' , '\" ' , '\' ' )
197- . Replace ( "'" , "" ) ; // Additional cleanup for single quotes
198- clusterNames [ cluster . Key ] = string . IsNullOrWhiteSpace ( cleanedName ) ? $ "Cluster { cluster . Key } " : cleanedName ;
199- Console . WriteLine ( $ "Cluster { cluster . Key } predicted as: { clusterNames [ cluster . Key ] } ") ;
200- }
201- else
202- {
203- Console . WriteLine ( $ "Failed to predict name for Cluster { cluster . Key } . Status: { response . StatusCode } ") ;
204- clusterNames [ cluster . Key ] = $ "Cluster { cluster . Key } ";
205- }
206- }
207- catch ( System . Exception ex )
208- {
209- Console . WriteLine ( $ "Error predicting name for Cluster { cluster . Key } : { ex . Message } ") ;
210- clusterNames [ cluster . Key ] = $ "Cluster { cluster . Key } ";
211- }
212- }
213-
214- // Save for future runs
215- var saveFormat = clusterNames . ToDictionary ( k => k . Key . ToString ( ) , v => v . Value ) ;
216- var jsonOut = JsonSerializer . Serialize ( saveFormat , new JsonSerializerOptions { WriteIndented = true } ) ;
217- File . WriteAllText ( labelsFilePath , jsonOut ) ;
218-
219- return clusterNames ;
220- }
221-
222139 public static void PrintClusterExamples ( IEnumerable < IGrouping < uint , CommitPredictionWithData > > clusters , Dictionary < uint , string > clusterNames = null )
223140 {
224141 Console . WriteLine ( "\n --- Cluster Examples ---" ) ;
0 commit comments