Skip to content

Commit d3c8fce

Browse files
author
Milder Hernandez Cagua
committed
Add additional FunctionChoiceBehavior creators
1 parent d39be65 commit d3c8fce

File tree

3 files changed

+51
-9
lines changed

3 files changed

+51
-9
lines changed

semantickernel-api/src/main/java/com/microsoft/semantickernel/functionchoice/FunctionChoiceBehavior.java

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,22 @@ public static FunctionChoiceBehavior auto(boolean autoInvoke) {
6666
return new AutoFunctionChoiceBehavior(autoInvoke, null, null);
6767
}
6868

69+
/**
70+
* Gets an instance of the FunctionChoiceBehavior that provides either all the Kernel's plugins functions to the AI model to call or specific functions.
71+
*
72+
* @param autoInvoke Enable or disable auto-invocation.
73+
* If auto-invocation is enabled, the model may request that the Semantic Kernel
74+
* invoke the kernel functions and return the value to the model.
75+
* @param functions Functions to provide to the model. If null, all the Kernel's plugins' functions are provided to the model.
76+
* If empty, no functions are provided to the model, which is equivalent to disabling function calling.
77+
*
78+
* @return A new FunctionChoiceBehavior instance with all kernel functions allowed.
79+
*/
80+
public static FunctionChoiceBehavior auto(boolean autoInvoke,
81+
@Nullable List<KernelFunction<?>> functions) {
82+
return new AutoFunctionChoiceBehavior(autoInvoke, functions, null);
83+
}
84+
6985
/**
7086
* Gets an instance of the FunctionChoiceBehavior that provides either all the Kernel's plugins functions to the AI model to call or specific functions.
7187
*
@@ -79,11 +95,25 @@ public static FunctionChoiceBehavior auto(boolean autoInvoke) {
7995
* @return A new FunctionChoiceBehavior instance with all kernel functions allowed.
8096
*/
8197
public static FunctionChoiceBehavior auto(boolean autoInvoke,
82-
List<KernelFunction<?>> functions,
83-
@Nullable FunctionChoiceBehaviorOptions options) {
98+
@Nullable List<KernelFunction<?>> functions,
99+
@Nullable FunctionChoiceBehaviorOptions options) {
84100
return new AutoFunctionChoiceBehavior(autoInvoke, functions, options);
85101
}
86102

103+
/**
104+
* Gets an instance of the FunctionChoiceBehavior that provides either all the Kernel's plugins functions to the AI model to call or specific functions.
105+
* <p>
106+
* This behavior forces the model to call the provided functions.
107+
* SK connectors will invoke a requested function or multiple requested functions if the model requests multiple ones in one request,
108+
* while handling the first request, and stop advertising the functions for the following requests to prevent the model from repeatedly calling the same function(s).
109+
*
110+
* @return A new FunctionChoiceBehavior instance with the required function.
111+
*/
112+
public static FunctionChoiceBehavior required(boolean autoInvoke,
113+
@Nullable List<KernelFunction<?>> functions) {
114+
return new RequiredFunctionChoiceBehavior(autoInvoke, functions, null);
115+
}
116+
87117
/**
88118
* Gets an instance of the FunctionChoiceBehavior that provides either all the Kernel's plugins functions to the AI model to call or specific functions.
89119
* <p>
@@ -96,11 +126,20 @@ public static FunctionChoiceBehavior auto(boolean autoInvoke,
96126
* @return A new FunctionChoiceBehavior instance with the required function.
97127
*/
98128
public static FunctionChoiceBehavior required(boolean autoInvoke,
99-
List<KernelFunction<?>> functions,
100-
@Nullable FunctionChoiceBehaviorOptions options) {
129+
@Nullable List<KernelFunction<?>> functions,
130+
@Nullable FunctionChoiceBehaviorOptions options) {
101131
return new RequiredFunctionChoiceBehavior(autoInvoke, functions, options);
102132
}
103133

134+
/**
135+
* Gets an instance of the FunctionChoiceBehavior that provides either all the Kernel's plugins functions to the AI model to call or specific functions.
136+
* <p>
137+
* This behavior is useful if the user should first validate what functions the model will use.
138+
*/
139+
public static FunctionChoiceBehavior none() {
140+
return new NoneFunctionChoiceBehavior(null, null);
141+
}
142+
104143
/**
105144
* Gets an instance of the FunctionChoiceBehavior that provides either all the Kernel's plugins functions to the AI model to call or specific functions.
106145
* <p>
@@ -109,7 +148,7 @@ public static FunctionChoiceBehavior required(boolean autoInvoke,
109148
* @param functions Functions to provide to the model. If null, all the Kernel's plugins' functions are provided to the model.
110149
* If empty, no functions are provided to the model, which is equivalent to disabling function calling.
111150
*/
112-
public static FunctionChoiceBehavior none(List<KernelFunction<?>> functions,
151+
public static FunctionChoiceBehavior none(@Nullable List<KernelFunction<?>> functions,
113152
@Nullable FunctionChoiceBehaviorOptions options) {
114153
return new NoneFunctionChoiceBehavior(functions, options);
115154
}

semantickernel-api/src/main/java/com/microsoft/semantickernel/functionchoice/NoneFunctionChoiceBehavior.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33

44
import com.microsoft.semantickernel.semanticfunctions.KernelFunction;
55

6+
import javax.annotation.Nullable;
67
import java.util.List;
78

89
public class NoneFunctionChoiceBehavior extends FunctionChoiceBehavior {
910

1011
/**
1112
* Create a new instance of NoneFunctionChoiceBehavior.
1213
*/
13-
public NoneFunctionChoiceBehavior(List<KernelFunction<?>> functions,
14-
FunctionChoiceBehaviorOptions options) {
14+
public NoneFunctionChoiceBehavior(@Nullable List<KernelFunction<?>> functions,
15+
@Nullable FunctionChoiceBehaviorOptions options) {
1516
super(functions, options);
1617
}
1718
}

semantickernel-api/src/main/java/com/microsoft/semantickernel/functionchoice/RequiredFunctionChoiceBehavior.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import com.microsoft.semantickernel.semanticfunctions.KernelFunction;
55

6+
import javax.annotation.Nullable;
67
import java.util.List;
78

89
public class RequiredFunctionChoiceBehavior extends AutoFunctionChoiceBehavior {
@@ -14,8 +15,9 @@ public class RequiredFunctionChoiceBehavior extends AutoFunctionChoiceBehavior {
1415
* @param functions A set of functions to advertise to the model.
1516
* @param options Options for the function choice behavior.
1617
*/
17-
public RequiredFunctionChoiceBehavior(boolean autoInvoke, List<KernelFunction<?>> functions,
18-
FunctionChoiceBehaviorOptions options) {
18+
public RequiredFunctionChoiceBehavior(boolean autoInvoke,
19+
@Nullable List<KernelFunction<?>> functions,
20+
@Nullable FunctionChoiceBehaviorOptions options) {
1921
super(autoInvoke, functions, options);
2022
}
2123
}

0 commit comments

Comments
 (0)