Skip to content

Commit

Permalink
Fixes #4169: $path configuration parameter adds terminating slash (#4191
Browse files Browse the repository at this point in the history
)
  • Loading branch information
vga91 authored Oct 7, 2024
1 parent 65cc9b7 commit 0e6969a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion extended/src/main/java/apoc/ml/OpenAIRequestHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public String getEndpoint(Map<String, Object> procConfig, ApocConfig apocConfig)
public String getFullUrl(String method, Map<String, Object> procConfig, ApocConfig apocConfig) {
return Stream.of(getEndpoint(procConfig, apocConfig), method, getApiVersion(procConfig, apocConfig))
.filter(StringUtils::isNotBlank)
.collect(Collectors.joining("/"));
.collect(Collectors.joining("/"))
.replaceAll("/\\?", "?"); // Remove terminating endpoint
}

enum Type {
Expand Down
14 changes: 14 additions & 0 deletions extended/src/test/java/apoc/ml/OpenAIAzureIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.stream.Stream;

import static apoc.ml.OpenAI.API_TYPE_CONF_KEY;
import static apoc.ml.OpenAI.PATH_CONF_KEY;
import static apoc.ml.MLUtil.*;
import static apoc.ml.OpenAITestResultUtils.CHAT_COMPLETION_QUERY;
import static apoc.ml.OpenAITestResultUtils.COMPLETION_QUERY;
Expand Down Expand Up @@ -63,6 +64,19 @@ public void embedding() {
OpenAITestResultUtils::assertEmbeddings);
}

@Test
public void embeddingFixPath() {
Map<String, Object> params = Map.of("apiKey", OPENAI_KEY,
"conf", Map.of(ENDPOINT_CONF_KEY, OPENAI_EMBEDDING_URL,
API_TYPE_CONF_KEY, OpenAIRequestHandler.Type.AZURE.name(),
API_VERSION_CONF_KEY, OPENAI_AZURE_API_VERSION,
PATH_CONF_KEY, "openai/deployments/text-embedding-ada-002/embeddings"
));
testCall(db, EMBEDDING_QUERY,
params,
OpenAITestResultUtils::assertEmbeddings);
}


@Test
@Ignore("It returns wrong answers sometimes")
Expand Down

0 comments on commit 0e6969a

Please sign in to comment.