@@ -55,6 +55,7 @@ public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync
5555 var autoInvoke = kernel is not null && chatParameters . ToolCallBehavior ? . MaximumAutoInvokeAttempts > 0 ;
5656 for ( var it = 1 ; ; it ++ )
5757 {
58+ var chatParametersTools = chatParameters . Tools ? . ToList ( ) ;
5859 var response = await _dashScopeClient . GetTextCompletionAsync (
5960 new ModelRequest < TextGenerationInput , ITextGenerationParameters >
6061 {
@@ -83,14 +84,14 @@ public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync
8384
8485 foreach ( var call in message . ToolCalls )
8586 {
86- if ( call . Type is not ToolTypes . Function || call . Function is null )
87+ if ( call . Type is not ToolTypes . Function )
8788 {
8889 AddResponseMessage ( chat , null , "Error: Tool call was not a function call." , call . Id ) ;
8990 continue ;
9091 }
9192
9293 // ensure not calling function that was not included in request list.
93- if ( chatParameters . Tools ? . Any (
94+ if ( chatParametersTools ? . Any (
9495 x => string . Equals ( x . Function ? . Name , call . Function . Name , StringComparison . OrdinalIgnoreCase ) )
9596 != true )
9697 {
@@ -133,7 +134,7 @@ public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync
133134 AddResponseMessage ( chat , stringResult , null , call . Id ) ;
134135 }
135136
136- chatParameters . Tools ? . Clear ( ) ;
137+ chatParameters . Tools = [ ] ;
137138 chatParameters . ToolCallBehavior ? . ConfigureOptions ( kernel , chatParameters ) ;
138139 if ( it >= chatParameters . ToolCallBehavior ! . MaximumAutoInvokeAttempts )
139140 {
@@ -273,7 +274,7 @@ private void LogToolCalls(IReadOnlyCollection<ToolCall>? calls)
273274 {
274275 _logger . LogTrace (
275276 "Function call requests: {Requests}" ,
276- string . Join ( ", " , calls . Select ( ftc => $ "{ ftc . Function ? . Name } ({ ftc . Function ? . Arguments } )") ) ) ;
277+ string . Join ( ", " , calls . Select ( ftc => $ "{ ftc . Function . Name } ({ ftc . Function . Arguments } )") ) ) ;
277278 }
278279 }
279280
0 commit comments