From 9f6ca77bbc7111a32d391c39fed170735e7fcaac Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Wed, 23 Oct 2024 20:39:36 +0200 Subject: [PATCH] Ensure unique functions in FunctionCallingOptionsBuilder - Fix issues caused by cf75640c86268fcdbd98c1849c053b8b6b8ec1b5 - Modify withFunction() to maintain unique function entries using HashSet --- .../ai/model/function/FunctionCallingOptionsBuilder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java index 28346f392..ce84c8b04 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/model/function/FunctionCallingOptionsBuilder.java @@ -61,7 +61,9 @@ public class FunctionCallingOptionsBuilder { public FunctionCallingOptionsBuilder withFunction(String function) { Assert.notNull(function, "Function must not be null"); - this.options.getFunctions().add(function); + var set = new HashSet<>(this.options.getFunctions()); + set.add(function); + this.options.setFunctions(set); return this; } @@ -131,7 +133,7 @@ public class FunctionCallingOptionsBuilder { return this.options; } - public static class PortableFunctionCallingOptions implements FunctionCallingOptions, ChatOptions { + public static class PortableFunctionCallingOptions implements FunctionCallingOptions { private List functionCallbacks = new ArrayList<>();