Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$path configuration parameter adds terminating slash #4169

Closed
bprager opened this issue Aug 14, 2024 · 2 comments
Closed

$path configuration parameter adds terminating slash #4169

bprager opened this issue Aug 14, 2024 · 2 comments

Comments

@bprager
Copy link

bprager commented Aug 14, 2024

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

//Insert here a set of Cypher statements that helps us to reproduce the problem
          CALL apoc.ml.openai.embedding(
            [chunk.text],
            $openAiApiKey,
            {
              endpoint: "*endpoint*,
              apiVersion: "*version*",
              apiType: "AZURE",
              path: "*path*"
            }
          )

Steps (Mandatory)

Screenshots (where it's possibile)

image

Specifications (Mandatory)

https://neo4j.com/labs/apoc/5/ml/openai/

Currently used versions
5.20.0

Versions

  • OS: Windows 11
  • Neo4j: 5.20.0
  • Neo4j-Apoc: 5.20.0
@bprager
Copy link
Author

bprager commented Aug 16, 2024

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.

@bprager
Copy link
Author

bprager commented Aug 16, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

3 participants