Open bprager opened 4 weeks ago
The error is in OpenAIRequestHandler:
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("/"));
}
It will always terminate with an "/", which is wrong.
This is how a quick fix could look like:
diff --git a/extended/src/main/java/apoc/ml/OpenAIRequestHandler.java b/extended/src/main/java/apoc/ml/OpenAIRequestHandler.java
index cca7bcd54..13c1b767e 100644
--- a/extended/src/main/java/apoc/ml/OpenAIRequestHandler.java
+++ b/extended/src/main/java/apoc/ml/OpenAIRequestHandler.java
@@ -31,6 +31,7 @@ abstract class OpenAIRequestHandler {
public String getEndpoint(Map<String, Object> procConfig, ApocConfig apocConfig) {
String url = (String) procConfig.getOrDefault(ENDPOINT_CONF_KEY,
apocConfig.getString(APOC_ML_OPENAI_URL, System.getProperty(APOC_ML_OPENAI_URL)));
+
if (url == null) {
return getDefaultUrl();
}
@@ -40,7 +41,8 @@ abstract class OpenAIRequestHandler {
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("/\\?", "?"); // fix broken endpoint
Expected Behavior (Mandatory)
When I add a 'path' parameter (e.g. "text-embedding-ada-002/embeddings") I expect this actual path to be called without an additional "/" at the end.
Actual Behavior (Mandatory)
'apoc.ml.openai.embedding' adds an additional slash ('/') to the parameter, so the endpoint "text-embedding-ada-002/embeddings/?api-version=2023-12-01-preview" is called instead which causes the call to fail
Steps (Mandatory)
Screenshots (where it's possibile)
Specifications (Mandatory)
https://neo4j.com/labs/apoc/5/ml/openai/
Currently used versions 5.20.0
Versions