@@ -145,16 +145,16 @@ private static void PopulateToolCallsInfo(IList<AIContent> contents, ISpan span)
145145
146146 private static string FormatAvailableTools ( IList < AITool > tools )
147147 {
148- return FormatAsJsonList ( tools , tool => new
148+ return JsonSerializer . Serialize ( tools . Select ( tool => new
149149 {
150150 name = tool . Name ,
151151 description = tool . Description
152- } ) ;
152+ } ) ) ;
153153 }
154154
155155 private static string FormatRequestMessage ( ChatMessage [ ] messages )
156156 {
157- return FormatAsJsonList ( messages , message =>
157+ return JsonSerializer . Serialize ( messages . Select ( message =>
158158 {
159159 var content = message . Role == ChatRole . Tool ? FunctionResultToObject ( message . Contents ) : message . Text ;
160160
@@ -163,7 +163,7 @@ private static string FormatRequestMessage(ChatMessage[] messages)
163163 role = message . Role ,
164164 content
165165 } ;
166- } ) ;
166+ } ) ) ;
167167
168168 object FunctionResultToObject ( IList < AIContent > toolContents )
169169 {
@@ -189,7 +189,7 @@ object FunctionResultToObject(IList<AIContent> toolContents)
189189
190190 private static string FormatFunctionCallContent ( FunctionCallContent [ ] content )
191191 {
192- return FormatAsJsonList ( content , c =>
192+ return JsonSerializer . Serialize ( content . Select ( c =>
193193 {
194194 string argumentsJson ;
195195 try
@@ -207,11 +207,6 @@ private static string FormatFunctionCallContent(FunctionCallContent[] content)
207207 type = "function_call" ,
208208 arguments = argumentsJson
209209 } ;
210- } ) ;
211- }
212-
213- private static string FormatAsJsonList < T > ( IEnumerable < T > items , Func < T , object > selector )
214- {
215- return JsonSerializer . Serialize ( items . Select ( selector ) ) ;
210+ } ) ) ;
216211 }
217212}
0 commit comments