|
27 | 27 | namespace Microsoft.Extensions.AI; |
28 | 28 |
|
29 | 29 | /// <summary>Provides factory methods for creating commonly-used implementations of <see cref="AIFunction"/>.</summary> |
| 30 | +/// <remarks> |
| 31 | +/// <para> |
| 32 | +/// The <see cref="AIFunctionFactory"/> class creates <see cref="AIFunction"/> instances that wrap .NET methods |
| 33 | +/// (specified as <see cref="Delegate"/> or <see cref="MethodInfo"/>). As part of this process, JSON schemas are |
| 34 | +/// automatically derived for both the function's input parameters (exposed via <see cref="AIFunctionDeclaration.JsonSchema"/>) |
| 35 | +/// and, by default, the function's return type (exposed via <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>). |
| 36 | +/// These schemas are produced using the <see cref="AIFunctionFactoryOptions.SerializerOptions"/> and |
| 37 | +/// <see cref="AIFunctionFactoryOptions.JsonSchemaCreateOptions"/>, and enable AI services to understand and |
| 38 | +/// interact with the function. Return value serialization and schema derivation behavior can be customized |
| 39 | +/// via <see cref="AIFunctionFactoryOptions.MarshalResult"/> and <see cref="AIFunctionFactoryOptions.ExcludeResultSchema"/>, |
| 40 | +/// respectively. |
| 41 | +/// </para> |
| 42 | +/// </remarks> |
30 | 43 | /// <related type="Article" href="https://learn.microsoft.com/dotnet/ai/quickstarts/use-function-calling">Invoke .NET functions using an AI model.</related> |
31 | 44 | public static partial class AIFunctionFactory |
32 | 45 | { |
@@ -98,7 +111,14 @@ public static partial class AIFunctionFactory |
98 | 111 | /// special-cased and are not serialized: the created function returns the original instance(s) directly to enable |
99 | 112 | /// callers (such as an <c>IChatClient</c>) to perform type tests and implement specialized handling. If |
100 | 113 | /// <see cref="AIFunctionFactoryOptions.MarshalResult"/> is supplied, that delegate governs the behavior instead. |
101 | | - /// Handling of return values can be overridden via <see cref="AIFunctionFactoryOptions.MarshalResult"/>. |
| 114 | + /// </para> |
| 115 | + /// <para> |
| 116 | + /// In addition to the parameter schema, a JSON schema is also derived from the method's return type and exposed via the |
| 117 | + /// returned <see cref="AIFunction"/>'s <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. For methods returning |
| 118 | + /// <see cref="void"/>, <see cref="Task"/>, or <see cref="ValueTask"/>, no return schema is produced (the property is <see langword="null"/>). |
| 119 | + /// For methods returning <see cref="Task{TResult}"/> or <see cref="ValueTask{TResult}"/>, the schema is derived from the |
| 120 | + /// unwrapped result type. Return schema generation can be excluded via <see cref="AIFunctionFactoryOptions.ExcludeResultSchema"/>, |
| 121 | + /// and its generation is governed by <paramref name="options"/>'s <see cref="AIFunctionFactoryOptions.JsonSchemaCreateOptions"/>. |
102 | 122 | /// </para> |
103 | 123 | /// </remarks> |
104 | 124 | /// <exception cref="ArgumentNullException"><paramref name="method"/> is <see langword="null"/>.</exception> |
@@ -169,6 +189,11 @@ public static AIFunction Create(Delegate method, AIFunctionFactoryOptions? optio |
169 | 189 | /// derived type of <see cref="AIContent"/>, or any type assignable from <see cref="IEnumerable{AIContent}"/> are not serialized; |
170 | 190 | /// they are returned as-is to facilitate specialized handling. |
171 | 191 | /// </para> |
| 192 | + /// <para> |
| 193 | + /// A JSON schema is also derived from the method's return type and exposed via <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. |
| 194 | + /// For methods returning <see cref="void"/>, <see cref="Task"/>, or <see cref="ValueTask"/>, no return schema is produced. |
| 195 | + /// For methods returning <see cref="Task{TResult}"/> or <see cref="ValueTask{TResult}"/>, the schema is derived from the unwrapped result type. |
| 196 | + /// </para> |
172 | 197 | /// </remarks> |
173 | 198 | /// <exception cref="ArgumentNullException"><paramref name="method"/> is <see langword="null"/>.</exception> |
174 | 199 | /// <exception cref="JsonException">A parameter to <paramref name="method"/> is not serializable.</exception> |
@@ -255,6 +280,14 @@ public static AIFunction Create(Delegate method, string? name = null, string? de |
255 | 280 | /// any type assignable from <see cref="IEnumerable{AIContent}"/> are not serialized and are instead returned directly. |
256 | 281 | /// Handling of return values can be overridden via <see cref="AIFunctionFactoryOptions.MarshalResult"/>. |
257 | 282 | /// </para> |
| 283 | + /// <para> |
| 284 | + /// In addition to the parameter schema, a JSON schema is also derived from the method's return type and exposed via the |
| 285 | + /// returned <see cref="AIFunction"/>'s <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. For methods returning |
| 286 | + /// <see cref="void"/>, <see cref="Task"/>, or <see cref="ValueTask"/>, no return schema is produced (the property is <see langword="null"/>). |
| 287 | + /// For methods returning <see cref="Task{TResult}"/> or <see cref="ValueTask{TResult}"/>, the schema is derived from the |
| 288 | + /// unwrapped result type. Return schema generation can be excluded via <see cref="AIFunctionFactoryOptions.ExcludeResultSchema"/>, |
| 289 | + /// and its generation is governed by <paramref name="options"/>'s <see cref="AIFunctionFactoryOptions.JsonSchemaCreateOptions"/>. |
| 290 | + /// </para> |
258 | 291 | /// </remarks> |
259 | 292 | /// <exception cref="ArgumentNullException"><paramref name="method"/> is <see langword="null"/>.</exception> |
260 | 293 | /// <exception cref="ArgumentNullException"><paramref name="method"/> represents an instance method but <paramref name="target"/> is null.</exception> |
@@ -334,6 +367,11 @@ public static AIFunction Create(MethodInfo method, object? target, AIFunctionFac |
334 | 367 | /// derived type of <see cref="AIContent"/>, or any type assignable from <see cref="IEnumerable{AIContent}"/> are returned |
335 | 368 | /// without serialization to enable specialized handling. |
336 | 369 | /// </para> |
| 370 | + /// <para> |
| 371 | + /// A JSON schema is also derived from the method's return type and exposed via <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. |
| 372 | + /// For methods returning <see cref="void"/>, <see cref="Task"/>, or <see cref="ValueTask"/>, no return schema is produced. |
| 373 | + /// For methods returning <see cref="Task{TResult}"/> or <see cref="ValueTask{TResult}"/>, the schema is derived from the unwrapped result type. |
| 374 | + /// </para> |
337 | 375 | /// </remarks> |
338 | 376 | /// <exception cref="ArgumentNullException"><paramref name="method"/> is <see langword="null"/>.</exception> |
339 | 377 | /// <exception cref="ArgumentNullException"><paramref name="method"/> represents an instance method but <paramref name="target"/> is null.</exception> |
@@ -433,6 +471,14 @@ public static AIFunction Create(MethodInfo method, object? target, string? name |
433 | 471 | /// assignable from <see cref="IEnumerable{AIContent}"/> are returned directly without serialization. |
434 | 472 | /// Handling of return values can be overridden via <see cref="AIFunctionFactoryOptions.MarshalResult"/>. |
435 | 473 | /// </para> |
| 474 | + /// <para> |
| 475 | + /// In addition to the parameter schema, a JSON schema is also derived from the method's return type and exposed via the |
| 476 | + /// returned <see cref="AIFunction"/>'s <see cref="AIFunctionDeclaration.ReturnJsonSchema"/>. For methods returning |
| 477 | + /// <see cref="void"/>, <see cref="Task"/>, or <see cref="ValueTask"/>, no return schema is produced (the property is <see langword="null"/>). |
| 478 | + /// For methods returning <see cref="Task{TResult}"/> or <see cref="ValueTask{TResult}"/>, the schema is derived from the |
| 479 | + /// unwrapped result type. Return schema generation can be excluded via <see cref="AIFunctionFactoryOptions.ExcludeResultSchema"/>, |
| 480 | + /// and its generation is governed by <paramref name="options"/>'s <see cref="AIFunctionFactoryOptions.JsonSchemaCreateOptions"/>. |
| 481 | + /// </para> |
436 | 482 | /// </remarks> |
437 | 483 | /// <exception cref="ArgumentNullException"><paramref name="method"/> is <see langword="null"/>.</exception> |
438 | 484 | /// <exception cref="ArgumentNullException"><paramref name="createInstanceFunc"/> is <see langword="null"/>.</exception> |
|
0 commit comments