Skip to content

Commit 04d17ae

Browse files
committed
Address review comments.
- Renamed CommonInvokingSpec to CommonCallbackInvokingSpec and DefaultCommonInvokingSpec to DefaultCommonCallbackInvokingSpec - Simplified callback specification by removing parent spec reference - Removed cascading getter logic for description, schema type, and other properties - Minor adjustments to function callback builder and invoking specs
1 parent cd285dd commit 04d17ae

File tree

5 files changed

+18
-26
lines changed

5 files changed

+18
-26
lines changed

models/spring-ai-anthropic/src/test/java/org/springframework/ai/anthropic/client/AnthropicChatClientMethodInvokingFunctionCallbackIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ void methodGetWeatherToolContextButNonContextMethod() {
174174
assertThatThrownBy(() -> ChatClient.create(this.chatModel).prompt()
175175
.user("What's the weather like in San Francisco, Tokyo, and Paris? Use Celsius.")
176176
.functions(FunctionCallback.builder()
177-
.description("Get the weather in location")
178177
.method("getWeatherNonStatic", String.class, Unit.class)
178+
.description("Get the weather in location")
179179
.targetObject(targetObject)
180180
.build())
181181
.toolContext(Map.of("tool", "value"))

models/spring-ai-zhipuai/src/test/java/org/springframework/ai/zhipuai/chat/ZhiPuAiChatModelIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ void functionCallTest() {
231231
var promptOptions = ZhiPuAiChatOptions.builder()
232232
.withModel(ZhiPuAiApi.ChatModel.GLM_4.getValue())
233233
.withFunctionCallbacks(List.of(FunctionCallback.builder()
234-
.description("Get the weather in location")
235234
.function("getCurrentWeather", new MockWeatherService())
235+
.description("Get the weather in location")
236236
.inputType(MockWeatherService.Request.class)
237237
.build()))
238238
.build();
@@ -257,8 +257,8 @@ void streamFunctionCallTest() {
257257
var promptOptions = ZhiPuAiChatOptions.builder()
258258
.withModel(ZhiPuAiApi.ChatModel.GLM_4.getValue())
259259
.withFunctionCallbacks(List.of(FunctionCallback.builder()
260-
.description("Get the weather in location")
261260
.function("getCurrentWeather", new MockWeatherService())
261+
.description("Get the weather in location")
262262
.inputType(MockWeatherService.Request.class)
263263
.build()))
264264
.build();
Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@
88
import com.fasterxml.jackson.databind.SerializationFeature;
99
import com.fasterxml.jackson.databind.json.JsonMapper;
1010

11-
import org.springframework.ai.model.function.FunctionCallback.CommonInvokingSpec;
11+
import org.springframework.ai.model.function.FunctionCallback.CommonCallbackInvokingSpec;
1212
import org.springframework.ai.model.function.FunctionCallback.SchemaType;
1313
import org.springframework.ai.util.JacksonUtils;
1414
import org.springframework.util.Assert;
1515

16-
public class DefaultCommonInvokingSpec<B extends CommonInvokingSpec<B>> implements CommonInvokingSpec<B> {
17-
18-
protected DefaultCommonInvokingSpec<?> parentCommonInvokingSpec;
16+
public class DefaultCommonCallbackInvokingSpec<B extends CommonCallbackInvokingSpec<B>>
17+
implements CommonCallbackInvokingSpec<B> {
1918

2019
/**
2120
* The description of the function callback. Used to hint the LLM model about the
@@ -94,28 +93,23 @@ public B objectMapper(ObjectMapper objectMapper) {
9493
}
9594

9695
public String getDescription() {
97-
return (this.description != null) ? this.description
98-
: (this.parentCommonInvokingSpec != null) ? this.parentCommonInvokingSpec.getDescription() : null;
96+
return this.description;
9997
}
10098

10199
public SchemaType getSchemaType() {
102-
return (this.schemaType != null) ? this.schemaType
103-
: (this.parentCommonInvokingSpec != null) ? this.parentCommonInvokingSpec.getSchemaType() : null;
100+
return this.schemaType;
104101
}
105102

106103
public Function<Object, String> getResponseConverter() {
107-
return (this.responseConverter != null) ? this.responseConverter
108-
: (this.parentCommonInvokingSpec != null) ? this.parentCommonInvokingSpec.getResponseConverter() : null;
104+
return this.responseConverter;
109105
}
110106

111107
public String getInputTypeSchema() {
112-
return (this.inputTypeSchema != null) ? this.inputTypeSchema
113-
: (this.parentCommonInvokingSpec != null) ? this.parentCommonInvokingSpec.getInputTypeSchema() : null;
108+
return this.inputTypeSchema;
114109
}
115110

116111
public ObjectMapper getObjectMapper() {
117-
return (this.objectMapper != null) ? this.objectMapper
118-
: (this.parentCommonInvokingSpec != null) ? this.parentCommonInvokingSpec.getObjectMapper() : null;
112+
return this.objectMapper;
119113
}
120114

121115
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import org.springframework.ai.model.function.FunctionCallback.FunctionInvokingSpec;
3232
import org.springframework.ai.model.function.FunctionCallback.MethodInvokingSpec;
3333
import org.springframework.ai.model.function.FunctionCallback.SchemaType;
34-
import org.springframework.ai.util.JacksonUtils;
3534
import org.springframework.ai.util.ParsingUtils;
3635
import org.springframework.core.ParameterizedTypeReference;
3736
import org.springframework.util.Assert;
@@ -44,8 +43,7 @@
4443
* @author Christian Tzolov
4544
* @since 1.0.0
4645
*/
47-
public class DefaultFunctionCallbackBuilder extends DefaultCommonInvokingSpec<FunctionCallback.Builder>
48-
implements FunctionCallback.Builder {
46+
public class DefaultFunctionCallbackBuilder implements FunctionCallback.Builder {
4947

5048
private final static Logger logger = LoggerFactory.getLogger(DefaultFunctionCallbackBuilder.class);
5149

@@ -89,7 +87,7 @@ private String generateDescription(String fromName) {
8987
return generatedDescription;
9088
}
9189

92-
final class DefaultFunctionInvokingSpec<I, O> extends DefaultCommonInvokingSpec<FunctionInvokingSpec<I, O>>
90+
final class DefaultFunctionInvokingSpec<I, O> extends DefaultCommonCallbackInvokingSpec<FunctionInvokingSpec<I, O>>
9391
implements FunctionInvokingSpec<I, O> {
9492

9593
private final String name;
@@ -160,7 +158,7 @@ private String getDescriptionExt() {
160158

161159
}
162160

163-
final class DefaultMethodInvokingSpec extends DefaultCommonInvokingSpec<MethodInvokingSpec>
161+
final class DefaultMethodInvokingSpec extends DefaultCommonCallbackInvokingSpec<MethodInvokingSpec>
164162
implements FunctionCallback.MethodInvokingSpec {
165163

166164
private String name;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ enum SchemaType {
116116
* <li>{@link MethodInvokingSpec} - The method invoking builder interface.
117117
* </ul>
118118
*/
119-
interface Builder extends CommonInvokingSpec<Builder> {
119+
interface Builder {
120120

121121
/**
122122
* Builds a {@link Function} invoking {@link FunctionCallback} instance.
@@ -145,7 +145,7 @@ interface Builder extends CommonInvokingSpec<Builder> {
145145

146146
}
147147

148-
interface CommonInvokingSpec<B extends CommonInvokingSpec<B>> {
148+
interface CommonCallbackInvokingSpec<B extends CommonCallbackInvokingSpec<B>> {
149149

150150
/**
151151
* Function description. This description is used by the model do decide if the
@@ -186,7 +186,7 @@ interface CommonInvokingSpec<B extends CommonInvokingSpec<B>> {
186186
* @param <I> Function input type.
187187
* @param <O> Function output type.
188188
*/
189-
interface FunctionInvokingSpec<I, O> extends CommonInvokingSpec<FunctionInvokingSpec<I, O>> {
189+
interface FunctionInvokingSpec<I, O> extends CommonCallbackInvokingSpec<FunctionInvokingSpec<I, O>> {
190190

191191
/**
192192
* Function input type. The input type is used to validate the function input
@@ -211,7 +211,7 @@ interface FunctionInvokingSpec<I, O> extends CommonInvokingSpec<FunctionInvoking
211211
/**
212212
* Method invoking builder interface.
213213
*/
214-
interface MethodInvokingSpec extends CommonInvokingSpec<MethodInvokingSpec> {
214+
interface MethodInvokingSpec extends CommonCallbackInvokingSpec<MethodInvokingSpec> {
215215

216216
/**
217217
* Optional function name. If not provided the method name is used as the

0 commit comments

Comments
 (0)