@@ -18,13 +18,13 @@ namespace Microsoft.AI.Foundry.Local.OpenAI;
1818/// </summary>
1919public class ToolDefinition
2020{
21- /// <summary>The type of tool.</summary>
21+ /// <summary>The type of tool. Defaults to <see cref="ToolType.Function"/>. </summary>
2222 [ JsonPropertyName ( "type" ) ]
23- public ToolType ? Type { get ; set ; }
23+ public ToolType Type { get ; set ; } = ToolType . Function ;
2424
2525 /// <summary>The function definition.</summary>
2626 [ JsonPropertyName ( "function" ) ]
27- public FunctionDefinition ? Function { get ; set ; }
27+ public required FunctionDefinition Function { get ; set ; }
2828}
2929
3030/// <summary>
@@ -34,7 +34,7 @@ public class FunctionDefinition
3434{
3535 /// <summary>The name of the function.</summary>
3636 [ JsonPropertyName ( "name" ) ]
37- public string ? Name { get ; set ; }
37+ public required string Name { get ; set ; }
3838
3939 /// <summary>A description of what the function does.</summary>
4040 [ JsonPropertyName ( "description" ) ]
@@ -117,26 +117,35 @@ public class JsonSchema
117117
118118/// <summary>
119119/// Controls which tool the model should use.
120- /// Use static properties <see cref="None "/>, <see cref="Auto "/>, or <see cref="Required"/>
121- /// for standard choices .
120+ /// Use static methods <see cref="CreateNoneChoice "/>, <see cref="CreateAutoChoice "/>,
121+ /// <see cref="CreateRequiredChoice"/>, or <see cref="CreateFunctionChoice(string)"/> .
122122/// </summary>
123123[ JsonConverter ( typeof ( ToolChoiceConverter ) ) ]
124124public class ToolChoice
125125{
126126 /// <summary>The tool choice type.</summary>
127- public string ? Type { get ; set ; }
127+ public string ? Type { get ; internal set ; }
128128
129129 /// <summary>Specifies a particular function to call.</summary>
130- public FunctionTool ? Function { get ; set ; }
130+ public FunctionTool ? Function { get ; internal set ; }
131+
132+ /// <summary>Creates a choice indicating the model will not call any tool.</summary>
133+ public static ToolChoice CreateNoneChoice ( ) => new ( ) { Type = "none" } ;
131134
132- /// <summary>The model will not call any tool.</summary>
133- public static ToolChoice None => new ( ) { Type = "none " } ;
135+ /// <summary>Creates a choice indicating the model can choose whether to call a tool.</summary>
136+ public static ToolChoice CreateAutoChoice ( ) => new ( ) { Type = "auto " } ;
134137
135- /// <summary>The model can choose whether to call a tool .</summary>
136- public static ToolChoice Auto => new ( ) { Type = "auto " } ;
138+ /// <summary>Creates a choice indicating the model must call one or more tools .</summary>
139+ public static ToolChoice CreateRequiredChoice ( ) => new ( ) { Type = "required " } ;
137140
138- /// <summary>The model must call one or more tools.</summary>
139- public static ToolChoice Required => new ( ) { Type = "required" } ;
141+ /// <summary>Creates a choice indicating the model must call the specified function.</summary>
142+ /// <exception cref="ArgumentNullException"><paramref name="functionName"/> is null.</exception>
143+ /// <exception cref="ArgumentException"><paramref name="functionName"/> is empty.</exception>
144+ public static ToolChoice CreateFunctionChoice ( string functionName )
145+ {
146+ ArgumentNullException . ThrowIfNullOrEmpty ( functionName , nameof ( functionName ) ) ;
147+ return new ( ) { Type = "function" , Function = new FunctionTool { Name = functionName } } ;
148+ }
140149
141150 /// <summary>
142151 /// Specifies a specific function tool to call.
0 commit comments