@@ -55,6 +55,7 @@ public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync
55
55
var autoInvoke = kernel is not null && chatParameters . ToolCallBehavior ? . MaximumAutoInvokeAttempts > 0 ;
56
56
for ( var it = 1 ; ; it ++ )
57
57
{
58
+ var chatParametersTools = chatParameters . Tools ? . ToList ( ) ;
58
59
var response = await _dashScopeClient . GetTextCompletionAsync (
59
60
new ModelRequest < TextGenerationInput , ITextGenerationParameters >
60
61
{
@@ -83,14 +84,14 @@ public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync
83
84
84
85
foreach ( var call in message . ToolCalls )
85
86
{
86
- if ( call . Type is not ToolTypes . Function || call . Function is null )
87
+ if ( call . Type is not ToolTypes . Function )
87
88
{
88
89
AddResponseMessage ( chat , null , "Error: Tool call was not a function call." , call . Id ) ;
89
90
continue ;
90
91
}
91
92
92
93
// ensure not calling function that was not included in request list.
93
- if ( chatParameters . Tools ? . Any (
94
+ if ( chatParametersTools ? . Any (
94
95
x => string . Equals ( x . Function ? . Name , call . Function . Name , StringComparison . OrdinalIgnoreCase ) )
95
96
!= true )
96
97
{
@@ -133,7 +134,7 @@ public async Task<IReadOnlyList<ChatMessageContent>> GetChatMessageContentsAsync
133
134
AddResponseMessage ( chat , stringResult , null , call . Id ) ;
134
135
}
135
136
136
- chatParameters . Tools ? . Clear ( ) ;
137
+ chatParameters . Tools = [ ] ;
137
138
chatParameters . ToolCallBehavior ? . ConfigureOptions ( kernel , chatParameters ) ;
138
139
if ( it >= chatParameters . ToolCallBehavior ! . MaximumAutoInvokeAttempts )
139
140
{
@@ -273,7 +274,7 @@ private void LogToolCalls(IReadOnlyCollection<ToolCall>? calls)
273
274
{
274
275
_logger . LogTrace (
275
276
"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 } )") ) ) ;
277
278
}
278
279
}
279
280
0 commit comments