Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1060,8 +1060,7 @@ public List<ContentBlockStartEvent.ContentBlockToolUse> getToolContentBlocks() {
* @return True if the event is empty, false otherwise.
*/
public boolean isEmpty() {
return (this.index == null || this.id == null || this.name == null
|| !StringUtils.hasText(this.partialJson));
return (this.index == null || this.id == null || this.name == null);
}

ToolUseAggregationEvent withIndex(Integer index) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,23 @@
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.ai.anthropic.AnthropicTestConfiguration;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.model.tool.ToolCallingChatOptions;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.method.MethodToolCallback;
import org.springframework.ai.tool.support.ToolDefinitions;
Expand All @@ -39,6 +44,8 @@
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.ReflectionUtils;

import reactor.core.publisher.Flux;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

Expand Down Expand Up @@ -262,6 +269,39 @@ void toolAnnotation() {
.containsEntry("color", TestFunctionClass.LightColor.RED);
}

// https://github.com/spring-projects/spring-ai/issues/1878
@ParameterizedTest
@ValueSource(strings = { "claude-opus-4-20250514", "claude-sonnet-4-20250514", "claude-3-7-sonnet-latest" })
void streamingParameterLessTool(String modelName) {

ChatClient chatClient = ChatClient.builder(this.chatModel).build();

Flux<ChatResponse> responses = chatClient.prompt()
.options(ToolCallingChatOptions.builder().model(modelName).build())
.tools(new ParameterLessTools())
.user("Get current weather in Amsterdam")
.stream()
.chatResponse();

String content = responses.collectList()
.block()
.stream()
.filter(cr -> cr.getResult() != null)
.map(cr -> cr.getResult().getOutput().getText())
.collect(Collectors.joining());

assertThat(content).contains("20 degrees");
}

public static class ParameterLessTools {

@Tool(description = "Get the current weather forecast in Amsterdam")
String getCurrentDateTime() {
return "Weather is hot and sunny with a temperature of 20 degrees";
}

}

@Autowired
ChatModel chatModel;

Expand Down