Skip to content

Commit

Permalink
Removed org.apache.commons.collections from OpenAI (#4304)
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 authored Dec 12, 2024
1 parent 717efc5 commit 7e3bfb7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions extended/src/main/java/apoc/ml/OpenAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import apoc.ApocConfig;
import apoc.Extended;
import apoc.result.MapResult;
import apoc.util.ExtendedMapUtils;
import apoc.util.ExtendedUtil;
import apoc.util.JsonUtil;
import apoc.util.Util;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.neo4j.graphdb.security.URLAccessChecker;
import org.neo4j.procedure.Context;
Expand Down Expand Up @@ -225,7 +225,7 @@ public Stream<MapResult> completion(@Name("prompt") String prompt, @Name("api_ke
public Stream<MapResult> chatCompletion(@Name("messages") List<Map<String, Object>> messages, @Name("api_key") String apiKey, @Name(value = "configuration", defaultValue = "{}") Map<String, Object> configuration) throws Exception {
boolean failOnError = isFailOnError(configuration);
if (checkNullInput(messages, failOnError)) return Stream.empty();
messages = messages.stream().filter(MapUtils::isNotEmpty).toList();
messages = messages.stream().filter(ExtendedMapUtils::isNotEmpty).toList();
if (checkEmptyInput(messages, failOnError)) return Stream.empty();
configuration.putIfAbsent("model", GPT_4O_MODEL);
return executeRequest(apiKey, configuration, "chat/completions", (String) configuration.get("model"), "messages", messages, "$", apocConfig, urlAccessChecker)
Expand Down
4 changes: 4 additions & 0 deletions extended/src/main/java/apoc/util/ExtendedMapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ public static int size(final Map<?, ?> map) {
public static boolean isEmpty(final Map<?,?> map) {
return map == null || map.isEmpty();
}

public static boolean isNotEmpty(final Map<?,?> map) {
return !isEmpty(map);
}
}

0 comments on commit 7e3bfb7

Please # to comment.