@@ -49,7 +49,7 @@ public async Task<ChatResponse> GetResponseAsync(IEnumerable<ChatMessage> messag
4949 GenerateContentResponse generateResult = await this . _models . GenerateContentAsync ( modelId ! , contents , config ) . ConfigureAwait ( false ) ;
5050
5151 // Create the response.
52- ChatResponse chatResponse = new ( new ChatMessage ( ChatRole . Assistant , new List < AIContent > ( ) ) )
52+ ChatResponse chatResponse = new ( new ChatMessage ( ChatRole . Assistant , [ ] ) )
5353 {
5454 CreatedAt = generateResult . CreateTime is { } dt ? new DateTimeOffset ( dt ) : null ,
5555 ModelId = ! string . IsNullOrWhiteSpace ( generateResult . ModelVersion ) ? generateResult . ModelVersion : modelId ,
@@ -82,7 +82,7 @@ public async IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(IEnu
8282 await foreach ( GenerateContentResponse generateResult in this . _models . GenerateContentStreamAsync ( modelId ! , contents , config ) . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
8383 {
8484 // Create a response update for each result in the stream.
85- ChatResponseUpdate responseUpdate = new ( ChatRole . Assistant , new List < AIContent > ( ) )
85+ ChatResponseUpdate responseUpdate = new ( ChatRole . Assistant , [ ] )
8686 {
8787 CreatedAt = generateResult . CreateTime is { } dt ? new DateTimeOffset ( dt ) : null ,
8888 ModelId = ! string . IsNullOrWhiteSpace ( generateResult . ModelVersion ) ? generateResult . ModelVersion : modelId ,
@@ -148,7 +148,7 @@ void IDisposable.Dispose() { /* nop */ }
148148 // create the request instance, allowing the caller to populate it with GenAI-specific options. Otherwise, create
149149 // a new instance directly.
150150 string ? model = this . _defaultModelId ;
151- List < Content > contents = new ( ) ;
151+ List < Content > contents = [ ] ;
152152 GenerateContentConfig config = options ? . RawRepresentationFactory ? . Invoke ( this ) as GenerateContentConfig ?? new ( ) ;
153153
154154 if ( options is not null )
@@ -160,7 +160,7 @@ void IDisposable.Dispose() { /* nop */ }
160160
161161 if ( options . Instructions is { } instructions )
162162 {
163- ( ( config . SystemInstruction ??= new ( ) ) . Parts ??= new ( ) ) . Add ( new ( ) { Text = instructions } ) ;
163+ ( ( config . SystemInstruction ??= new ( ) ) . Parts ??= [ ] ) . Add ( new ( ) { Text = instructions } ) ;
164164 }
165165
166166 if ( options . MaxOutputTokens is { } maxOutputTokens )
@@ -185,7 +185,7 @@ void IDisposable.Dispose() { /* nop */ }
185185
186186 if ( options . StopSequences is { } stopSequences )
187187 {
188- ( config . StopSequences ??= new ( ) ) . AddRange ( stopSequences ) ;
188+ ( config . StopSequences ??= [ ] ) . AddRange ( stopSequences ) ;
189189 }
190190
191191 if ( options . Temperature is { } temperature )
@@ -213,7 +213,7 @@ void IDisposable.Dispose() { /* nop */ }
213213 switch ( tool )
214214 {
215215 case AIFunctionDeclaration af :
216- functionDeclarations ??= new ( ) ;
216+ functionDeclarations ??= [ ] ;
217217 functionDeclarations . Add ( new ( )
218218 {
219219 Name = af . Name ,
@@ -223,15 +223,15 @@ void IDisposable.Dispose() { /* nop */ }
223223 break ;
224224
225225 case HostedCodeInterpreterTool :
226- ( config . Tools ??= new ( ) ) . Add ( new ( ) { CodeExecution = new ( ) } ) ;
226+ ( config . Tools ??= [ ] ) . Add ( new ( ) { CodeExecution = new ( ) } ) ;
227227 break ;
228228
229229 case HostedFileSearchTool :
230- ( config . Tools ??= new ( ) ) . Add ( new ( ) { Retrieval = new ( ) } ) ;
230+ ( config . Tools ??= [ ] ) . Add ( new ( ) { Retrieval = new ( ) } ) ;
231231 break ;
232232
233233 case HostedWebSearchTool :
234- ( config . Tools ??= new ( ) ) . Add ( new ( ) { GoogleSearch = new ( ) } ) ;
234+ ( config . Tools ??= [ ] ) . Add ( new ( ) { GoogleSearch = new ( ) } ) ;
235235 break ;
236236 }
237237 }
@@ -240,8 +240,8 @@ void IDisposable.Dispose() { /* nop */ }
240240 if ( functionDeclarations is { Count : > 0 } )
241241 {
242242 Tool functionTools = new ( ) ;
243- ( functionTools . FunctionDeclarations ??= new ( ) ) . AddRange ( functionDeclarations ) ;
244- ( config . Tools ??= new ( ) ) . Add ( functionTools ) ;
243+ ( functionTools . FunctionDeclarations ??= [ ] ) . AddRange ( functionDeclarations ) ;
244+ ( config . Tools ??= [ ] ) . Add ( functionTools ) ;
245245 }
246246
247247 // Transfer over the tool mode if there are any tools.
@@ -261,7 +261,7 @@ void IDisposable.Dispose() { /* nop */ }
261261 config . ToolConfig = new ( ) { FunctionCallingConfig = new ( ) { Mode = FunctionCallingConfigMode . ANY } } ;
262262 if ( required . RequiredFunctionName is not null )
263263 {
264- ( ( config . ToolConfig . FunctionCallingConfig ??= new ( ) ) . AllowedFunctionNames ??= new ( ) ) . Add ( required . RequiredFunctionName ) ;
264+ ( ( config . ToolConfig . FunctionCallingConfig ??= new ( ) ) . AllowedFunctionNames ??= [ ] ) . Add ( required . RequiredFunctionName ) ;
265265 }
266266 break ;
267267 }
@@ -287,14 +287,14 @@ void IDisposable.Dispose() { /* nop */ }
287287 string instruction = message . Text ;
288288 if ( ! string . IsNullOrWhiteSpace ( instruction ) )
289289 {
290- ( ( config . SystemInstruction ??= new ( ) ) . Parts ??= new ( ) ) . Add ( new ( ) { Text = instruction } ) ;
290+ ( ( config . SystemInstruction ??= new ( ) ) . Parts ??= [ ] ) . Add ( new ( ) { Text = instruction } ) ;
291291 }
292292
293293 continue ;
294294 }
295295
296296 Content content = new ( ) { Role = message . Role == ChatRole . Assistant ? "model" : "user" } ;
297- content . Parts ??= new ( ) ;
297+ content . Parts ??= [ ] ;
298298 AddPartsForAIContents ( ref callIdToFunctionNames , message . Contents , content . Parts ) ;
299299
300300 contents . Add ( content ) ;
@@ -367,7 +367,7 @@ private static void AddPartsForAIContents(ref Dictionary<string, string>? callId
367367 break ;
368368
369369 case FunctionCallContent functionCallContent :
370- ( callIdToFunctionNames ??= new ( ) ) [ functionCallContent . CallId ] = functionCallContent . Name ;
370+ ( callIdToFunctionNames ??= [ ] ) [ functionCallContent . CallId ] = functionCallContent . Name ;
371371 callIdToFunctionNames [ "" ] = functionCallContent . Name ; // track last function name in case calls don't have IDs
372372
373373 part = new ( )
@@ -480,22 +480,22 @@ private static void AddAIContentsForParts(List<Part> parts, IList<AIContent> con
480480 {
481481 foreach ( var citation in citations )
482482 {
483- textContent . Annotations = new List < AIAnnotation > ( )
484- {
485- new CitationAnnotation ( )
486- {
487- Title = citation . Title ,
488- Url = Uri . TryCreate ( citation . Uri , UriKind . Absolute , out Uri ? uri ) ? uri : null ,
489- AnnotatedRegions = new List < AnnotatedRegion > ( )
490- {
491- new TextSpanAnnotatedRegion ( )
492- {
493- StartIndex = citation . StartIndex ,
494- EndIndex = citation . EndIndex ,
495- }
496- } ,
497- }
498- } ;
483+ textContent . Annotations =
484+ [
485+ new CitationAnnotation ( )
486+ {
487+ Title = citation . Title ,
488+ Url = Uri . TryCreate ( citation . Uri , UriKind . Absolute , out Uri ? uri ) ? uri : null ,
489+ AnnotatedRegions =
490+ [
491+ new TextSpanAnnotatedRegion ( )
492+ {
493+ StartIndex = citation . StartIndex ,
494+ EndIndex = citation . EndIndex ,
495+ }
496+ ] ,
497+ }
498+ ] ;
499499 }
500500 }
501501 }
@@ -551,7 +551,7 @@ void AddIfPresent(string key, int? value)
551551 {
552552 if ( value is int i )
553553 {
554- ( details . AdditionalCounts ??= new ( ) ) [ key ] = i ;
554+ ( details . AdditionalCounts ??= [ ] ) [ key ] = i ;
555555 }
556556 }
557557 }
0 commit comments