-
Notifications
You must be signed in to change notification settings - Fork 300
Updated tests in Spring AI, Langchain4j, deps for Spring AI and GenAISDK #1046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,6 @@ | |||||||||||||||||||||||||||||||||
| import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable; | ||||||||||||||||||||||||||||||||||
| import org.springframework.ai.anthropic.AnthropicChatModel; | ||||||||||||||||||||||||||||||||||
| import org.springframework.ai.anthropic.AnthropicChatOptions; | ||||||||||||||||||||||||||||||||||
| import org.springframework.ai.anthropic.api.AnthropicApi; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||
| * Integration tests with real Anthropic API. | ||||||||||||||||||||||||||||||||||
|
|
@@ -53,10 +52,14 @@ void testSimpleAgentWithRealAnthropicApi() throws InterruptedException { | |||||||||||||||||||||||||||||||||
| Thread.sleep(2000); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Create Anthropic model using Spring AI's builder pattern | ||||||||||||||||||||||||||||||||||
| AnthropicApi anthropicApi = | ||||||||||||||||||||||||||||||||||
| AnthropicApi.builder().apiKey(System.getenv("ANTHROPIC_API_KEY")).build(); | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel.builder().anthropicApi(anthropicApi).build(); | ||||||||||||||||||||||||||||||||||
| var options = | ||||||||||||||||||||||||||||||||||
| AnthropicChatOptions.builder() | ||||||||||||||||||||||||||||||||||
| .model(CLAUDE_MODEL) | ||||||||||||||||||||||||||||||||||
| .maxTokens(1024) | ||||||||||||||||||||||||||||||||||
| .apiKey(System.getenv("ANTHROPIC_API_KEY")) | ||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = AnthropicChatModel.builder().options(options).build(); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+55
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The logic for creating a default For example, you could add a method like this to the class: private AnthropicChatModel createDefaultAnthropicChatModel() {
var options =
AnthropicChatOptions.builder()
.model(CLAUDE_MODEL)
.maxTokens(1024)
.apiKey(System.getenv("ANTHROPIC_API_KEY"))
.build();
// Note: .withDefaultOptions() should be used instead of .options()
return AnthropicChatModel.builder().withDefaultOptions(options).build();
}Then you could replace this block in each test with: AnthropicChatModel anthropicModel = createDefaultAnthropicChatModel(); |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Wrap with SpringAI | ||||||||||||||||||||||||||||||||||
| SpringAI springAI = new SpringAI(anthropicModel, CLAUDE_MODEL); | ||||||||||||||||||||||||||||||||||
|
|
@@ -92,10 +95,14 @@ void testStreamingWithRealAnthropicApi() throws InterruptedException { | |||||||||||||||||||||||||||||||||
| // Add delay to avoid rapid requests | ||||||||||||||||||||||||||||||||||
| Thread.sleep(2000); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| AnthropicApi anthropicApi = | ||||||||||||||||||||||||||||||||||
| AnthropicApi.builder().apiKey(System.getenv("ANTHROPIC_API_KEY")).build(); | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel.builder().anthropicApi(anthropicApi).build(); | ||||||||||||||||||||||||||||||||||
| var options = | ||||||||||||||||||||||||||||||||||
| AnthropicChatOptions.builder() | ||||||||||||||||||||||||||||||||||
| .model(CLAUDE_MODEL) | ||||||||||||||||||||||||||||||||||
| .maxTokens(1024) | ||||||||||||||||||||||||||||||||||
| .apiKey(System.getenv("ANTHROPIC_API_KEY")) | ||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = AnthropicChatModel.builder().options(options).build(); | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The builder method
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SpringAI springAI = new SpringAI(anthropicModel, CLAUDE_MODEL); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -134,10 +141,14 @@ void testStreamingWithRealAnthropicApi() throws InterruptedException { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||
| void testAgentWithToolsAndRealApi() { | ||||||||||||||||||||||||||||||||||
| AnthropicApi anthropicApi = | ||||||||||||||||||||||||||||||||||
| AnthropicApi.builder().apiKey(System.getenv("ANTHROPIC_API_KEY")).build(); | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel.builder().anthropicApi(anthropicApi).build(); | ||||||||||||||||||||||||||||||||||
| var options = | ||||||||||||||||||||||||||||||||||
| AnthropicChatOptions.builder() | ||||||||||||||||||||||||||||||||||
| .model(CLAUDE_MODEL) | ||||||||||||||||||||||||||||||||||
| .maxTokens(1024) | ||||||||||||||||||||||||||||||||||
| .apiKey(System.getenv("ANTHROPIC_API_KEY")) | ||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = AnthropicChatModel.builder().options(options).build(); | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The builder method
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| LlmAgent agent = | ||||||||||||||||||||||||||||||||||
| LlmAgent.builder() | ||||||||||||||||||||||||||||||||||
|
|
@@ -175,10 +186,13 @@ void testAgentWithToolsAndRealApi() { | |||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||
| void testDirectComparisonNonStreamingVsStreaming() throws InterruptedException { | ||||||||||||||||||||||||||||||||||
| // Test both non-streaming and streaming with the same model to compare behavior | ||||||||||||||||||||||||||||||||||
| AnthropicApi anthropicApi = | ||||||||||||||||||||||||||||||||||
| AnthropicApi.builder().apiKey(System.getenv("ANTHROPIC_API_KEY")).build(); | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel.builder().anthropicApi(anthropicApi).build(); | ||||||||||||||||||||||||||||||||||
| var options = | ||||||||||||||||||||||||||||||||||
| AnthropicChatOptions.builder() | ||||||||||||||||||||||||||||||||||
| .model(CLAUDE_MODEL) | ||||||||||||||||||||||||||||||||||
| .maxTokens(1024) | ||||||||||||||||||||||||||||||||||
| .apiKey(System.getenv("ANTHROPIC_API_KEY")) | ||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = AnthropicChatModel.builder().options(options).build(); | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The builder method
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SpringAI springAI = new SpringAI(anthropicModel, CLAUDE_MODEL); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -271,13 +285,13 @@ void testDirectComparisonNonStreamingVsStreaming() throws InterruptedException { | |||||||||||||||||||||||||||||||||
| @Test | ||||||||||||||||||||||||||||||||||
| void testConfigurationOptions() { | ||||||||||||||||||||||||||||||||||
| // Test with custom configuration | ||||||||||||||||||||||||||||||||||
| AnthropicChatOptions options = | ||||||||||||||||||||||||||||||||||
| AnthropicChatOptions.builder().model(CLAUDE_MODEL).temperature(0.7).maxTokens(100).build(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| AnthropicApi anthropicApi = | ||||||||||||||||||||||||||||||||||
| AnthropicApi.builder().apiKey(System.getenv("ANTHROPIC_API_KEY")).build(); | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel.builder().anthropicApi(anthropicApi).defaultOptions(options).build(); | ||||||||||||||||||||||||||||||||||
| var options = | ||||||||||||||||||||||||||||||||||
| AnthropicChatOptions.builder() | ||||||||||||||||||||||||||||||||||
| .model(CLAUDE_MODEL) | ||||||||||||||||||||||||||||||||||
| .maxTokens(1024) | ||||||||||||||||||||||||||||||||||
| .apiKey(System.getenv("ANTHROPIC_API_KEY")) | ||||||||||||||||||||||||||||||||||
| .build(); | ||||||||||||||||||||||||||||||||||
| AnthropicChatModel anthropicModel = AnthropicChatModel.builder().options(options).build(); | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+288
to
+294
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test To fix this and restore the test's intent, you should reintroduce the custom options.
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| SpringAI springAI = new SpringAI(anthropicModel, CLAUDE_MODEL); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The builder method
.options()is incorrect forAnthropicChatModel.builder(). According to the Spring AI 2.0.0-M3 API, you should use.withDefaultOptions(). This will cause a compilation error.