55using System . Text . RegularExpressions ;
66using Microsoft . Extensions . Logging ;
77using Microsoft . Extensions . Options ;
8+ using TNO . Core . Exceptions ;
89using TNO . Core . Extensions ;
910using TNO . Services . AutoClipper . Azure ;
1011using TNO . Services . AutoClipper . Config ;
@@ -71,7 +72,7 @@ public async Task<IReadOnlyList<ClipDefinition>> GenerateClipsAsync(IReadOnlyLis
7172 var payload = new
7273 {
7374 model = string . IsNullOrWhiteSpace ( settings ? . ModelOverride ) ? _options . LlmDefaultModel : settings ! . ModelOverride ! ,
74- temperature = _options . LlmTemperature ,
75+ temperature = settings ! . TemperatureOverride ,
7576 messages = new object [ ]
7677 {
7778 new { role = "system" , content = systemPrompt } ,
@@ -87,16 +88,25 @@ public async Task<IReadOnlyList<ClipDefinition>> GenerateClipsAsync(IReadOnlyLis
8788
8889 using var response = await _httpClient . SendAsync ( request , cancellationToken ) ;
8990 var body = await response . Content . ReadAsStringAsync ( cancellationToken ) ;
90- response . EnsureSuccessStatusCode ( ) ;
9191
92- var clipDefinitions = ParseResponse ( body , transcript , settings , heuristicHits ) ;
93- if ( clipDefinitions . Count == 0 )
92+ if ( response . IsSuccessStatusCode )
9493 {
95- _logger . LogWarning ( "LLM segmentation did not return any clips." ) ;
94+
95+ var clipDefinitions = ParseResponse ( body , transcript , settings , heuristicHits ) ;
96+ if ( clipDefinitions . Count == 0 )
97+ {
98+ _logger . LogWarning ( "LLM segmentation did not return any clips." ) ;
99+ return [ ] ;
100+ }
101+
102+ return clipDefinitions ;
103+ }
104+ else
105+ {
106+ var responseException = new HttpClientRequestException ( response ) ;
107+ _logger . LogError ( responseException , "Failed to segment transcript with LLM. Error: {Details}" , body ) ;
96108 return [ ] ;
97109 }
98-
99- return clipDefinitions ;
100110 }
101111 catch ( Exception ex )
102112 {
0 commit comments