Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlesDuboisSAP committed Sep 3, 2024
1 parent 788db03 commit 0616f55
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private Stream<D> parseResponse(@Nonnull final ClassicHttpResponse response)
.onClose(
() -> {
try {
inputStream.close();
br.close();
} catch (IOException e) {
log.error("Could not close HTTP input stream", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiContentFilterPromptResults;
import com.sap.ai.sdk.foundationmodels.openai.model.OpenAiEmbeddingParameters;
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Accessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.ApacheHttpClient5Cache;
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultHttpDestination;
import io.vavr.control.Try;
import java.io.IOException;
Expand Down Expand Up @@ -50,6 +51,8 @@ void setup(WireMockRuntimeInfo server) {
final DefaultHttpDestination destination =
DefaultHttpDestination.builder(server.getHttpBaseUrl()).build();
client = OpenAiClient.withCustomDestination(destination);
ApacheHttpClient5Accessor.setHttpClientCache(ApacheHttpClient5Cache.DISABLED);
ApacheHttpClient5Accessor.setHttpClientFactory(null);
}

@Test
Expand Down Expand Up @@ -162,7 +165,7 @@ void chatCompletion() throws IOException {

assert inputStream != null;
final String response = new String(inputStream.readAllBytes());
stubFor(post(anyUrl()).willReturn(okJson(response)));
stubFor(post("/chat/completions").willReturn(okJson(response)));

final var systemMessage =
new OpenAiChatMessage.OpenAiChatSystemMessage()
Expand Down Expand Up @@ -251,7 +254,7 @@ void embedding() throws IOException {

assert inputStream != null;
final String response = new String(inputStream.readAllBytes());
stubFor(post(anyUrl()).willReturn(okJson(response)));
stubFor(post("/embeddings").willReturn(okJson(response)));

final var request = new OpenAiEmbeddingParameters().setInput("Hello World");
final var result = client.embedding(request);
Expand Down

0 comments on commit 0616f55

Please sign in to comment.