Skip to content

Commit 9f6ca77

Browse files
committed
Ensure unique functions in FunctionCallingOptionsBuilder
- Fix issues caused by cf75640 - Modify withFunction() to maintain unique function entries using HashSet
1 parent cf75640 commit 9f6ca77

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ public FunctionCallingOptionsBuilder withFunctions(Set<String> functions) {
6161

6262
public FunctionCallingOptionsBuilder withFunction(String function) {
6363
Assert.notNull(function, "Function must not be null");
64-
this.options.getFunctions().add(function);
64+
var set = new HashSet<>(this.options.getFunctions());
65+
set.add(function);
66+
this.options.setFunctions(set);
6567
return this;
6668
}
6769

@@ -131,7 +133,7 @@ public PortableFunctionCallingOptions build() {
131133
return this.options;
132134
}
133135

134-
public static class PortableFunctionCallingOptions implements FunctionCallingOptions, ChatOptions {
136+
public static class PortableFunctionCallingOptions implements FunctionCallingOptions {
135137

136138
private List<FunctionCallback> functionCallbacks = new ArrayList<>();
137139

0 commit comments

Comments
 (0)