3434import org .junit .jupiter .api .condition .EnabledIfEnvironmentVariable ;
3535import org .springframework .ai .anthropic .AnthropicChatModel ;
3636import org .springframework .ai .anthropic .AnthropicChatOptions ;
37- import org .springframework .ai .anthropic .api .AnthropicApi ;
3837
3938/**
4039 * Integration tests with real Anthropic API.
@@ -53,10 +52,14 @@ void testSimpleAgentWithRealAnthropicApi() throws InterruptedException {
5352 Thread .sleep (2000 );
5453
5554 // Create Anthropic model using Spring AI's builder pattern
56- AnthropicApi anthropicApi =
57- AnthropicApi .builder ().apiKey (System .getenv ("ANTHROPIC_API_KEY" )).build ();
58- AnthropicChatModel anthropicModel =
59- AnthropicChatModel .builder ().anthropicApi (anthropicApi ).build ();
55+ var options =
56+ AnthropicChatOptions .builder ()
57+ .model (CLAUDE_MODEL )
58+ .maxTokens (1024 )
59+ .apiKey (System .getenv ("ANTHROPIC_API_KEY" ))
60+ .build ();
61+
62+ AnthropicChatModel anthropicModel = AnthropicChatModel .builder ().options (options ).build ();
6063
6164 // Wrap with SpringAI
6265 SpringAI springAI = new SpringAI (anthropicModel , CLAUDE_MODEL );
@@ -92,10 +95,14 @@ void testStreamingWithRealAnthropicApi() throws InterruptedException {
9295 // Add delay to avoid rapid requests
9396 Thread .sleep (2000 );
9497
95- AnthropicApi anthropicApi =
96- AnthropicApi .builder ().apiKey (System .getenv ("ANTHROPIC_API_KEY" )).build ();
97- AnthropicChatModel anthropicModel =
98- AnthropicChatModel .builder ().anthropicApi (anthropicApi ).build ();
98+ var options =
99+ AnthropicChatOptions .builder ()
100+ .model (CLAUDE_MODEL )
101+ .maxTokens (1024 )
102+ .apiKey (System .getenv ("ANTHROPIC_API_KEY" ))
103+ .build ();
104+
105+ AnthropicChatModel anthropicModel = AnthropicChatModel .builder ().options (options ).build ();
99106
100107 SpringAI springAI = new SpringAI (anthropicModel , CLAUDE_MODEL );
101108
@@ -134,10 +141,14 @@ void testStreamingWithRealAnthropicApi() throws InterruptedException {
134141
135142 @ Test
136143 void testAgentWithToolsAndRealApi () {
137- AnthropicApi anthropicApi =
138- AnthropicApi .builder ().apiKey (System .getenv ("ANTHROPIC_API_KEY" )).build ();
139- AnthropicChatModel anthropicModel =
140- AnthropicChatModel .builder ().anthropicApi (anthropicApi ).build ();
144+ var options =
145+ AnthropicChatOptions .builder ()
146+ .model (CLAUDE_MODEL )
147+ .maxTokens (1024 )
148+ .apiKey (System .getenv ("ANTHROPIC_API_KEY" ))
149+ .build ();
150+
151+ AnthropicChatModel anthropicModel = AnthropicChatModel .builder ().options (options ).build ();
141152
142153 LlmAgent agent =
143154 LlmAgent .builder ()
@@ -175,10 +186,13 @@ void testAgentWithToolsAndRealApi() {
175186 @ Test
176187 void testDirectComparisonNonStreamingVsStreaming () throws InterruptedException {
177188 // Test both non-streaming and streaming with the same model to compare behavior
178- AnthropicApi anthropicApi =
179- AnthropicApi .builder ().apiKey (System .getenv ("ANTHROPIC_API_KEY" )).build ();
180- AnthropicChatModel anthropicModel =
181- AnthropicChatModel .builder ().anthropicApi (anthropicApi ).build ();
189+ var options =
190+ AnthropicChatOptions .builder ()
191+ .model (CLAUDE_MODEL )
192+ .maxTokens (1024 )
193+ .apiKey (System .getenv ("ANTHROPIC_API_KEY" ))
194+ .build ();
195+ AnthropicChatModel anthropicModel = AnthropicChatModel .builder ().options (options ).build ();
182196
183197 SpringAI springAI = new SpringAI (anthropicModel , CLAUDE_MODEL );
184198
@@ -271,13 +285,13 @@ void testDirectComparisonNonStreamingVsStreaming() throws InterruptedException {
271285 @ Test
272286 void testConfigurationOptions () {
273287 // Test with custom configuration
274- AnthropicChatOptions options =
275- AnthropicChatOptions .builder (). model ( CLAUDE_MODEL ). temperature ( 0.7 ). maxTokens ( 100 ). build ();
276-
277- AnthropicApi anthropicApi =
278- AnthropicApi . builder (). apiKey (System .getenv ("ANTHROPIC_API_KEY" )). build ();
279- AnthropicChatModel anthropicModel =
280- AnthropicChatModel .builder ().anthropicApi ( anthropicApi ). defaultOptions (options ).build ();
288+ var options =
289+ AnthropicChatOptions .builder ()
290+ . model ( CLAUDE_MODEL )
291+ . maxTokens ( 1024 )
292+ . apiKey (System .getenv ("ANTHROPIC_API_KEY" ))
293+ . build ();
294+ AnthropicChatModel anthropicModel = AnthropicChatModel .builder ().options (options ).build ();
281295
282296 SpringAI springAI = new SpringAI (anthropicModel , CLAUDE_MODEL );
283297
0 commit comments