Skip to content

Commit 493e2ea

Browse files
committed
✅ add simple test to verify feature
1 parent 2b276ef commit 493e2ea

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

models/spring-ai-azure-openai/src/test/java/org/springframework/ai/azure/openai/function/AzureOpenAiChatClientFunctionCallIT.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,31 @@ void functionCallTest() {
7575
assertThat(response.getResult().getOutput().getContent()).containsAnyOf("15.0", "15");
7676
}
7777

78+
@Test
79+
void functionCallWithoutCompleteRoundTrip() {
80+
81+
UserMessage userMessage = new UserMessage("What's the weather like in San Francisco?");
82+
83+
List<Message> messages = new ArrayList<>(List.of(userMessage));
84+
85+
final var spyingMockWeatherService = new SpyingMockWeatherService();
86+
var promptOptions = AzureOpenAiChatOptions.builder()
87+
.withDeploymentName("gpt-4-0125-preview")
88+
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(spyingMockWeatherService)
89+
.withName("getCurrentWeather")
90+
.withDescription("Get the current weather in a given location")
91+
.withResponseConverter((response) -> "" + response.temp() + response.unit())
92+
.build()))
93+
.withCompleteRoundTrip(false)
94+
.build();
95+
96+
ChatResponse response = chatClient.call(new Prompt(messages, promptOptions));
97+
98+
logger.info("Response: {}", response);
99+
final var interceptedRequest = spyingMockWeatherService.getInterceptedRequest();
100+
assertThat(interceptedRequest.location()).containsIgnoringCase("San Francisco");
101+
}
102+
78103
@SpringBootConfiguration
79104
public static class TestConfiguration {
80105

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright 2023 - 2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.ai.azure.openai.function;
17+
18+
import java.util.function.Function;
19+
20+
public class SpyingMockWeatherService implements Function<MockWeatherService.Request, MockWeatherService.Response> {
21+
22+
private final MockWeatherService inner = new MockWeatherService();
23+
24+
private MockWeatherService.Request interceptedRequest = null;
25+
26+
@Override
27+
public MockWeatherService.Response apply(MockWeatherService.Request request) {
28+
interceptedRequest = request;
29+
return inner.apply(request);
30+
}
31+
32+
public MockWeatherService.Request getInterceptedRequest() {
33+
return interceptedRequest;
34+
}
35+
36+
}

0 commit comments

Comments
 (0)