Skip to content

Commit

Permalink
Revert "Removed org.apache.commons.collections from OpenAI (#4304)" (#…
Browse files Browse the repository at this point in the history
…4305)

This reverts commit 7e3bfb7.
  • Loading branch information
vga91 authored Dec 12, 2024
1 parent 7e3bfb7 commit d453d5e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 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(ExtendedMapUtils::isNotEmpty).toList();
messages = messages.stream().filter(MapUtils::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: 0 additions & 4 deletions extended/src/main/java/apoc/util/ExtendedMapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,4 @@ 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 d453d5e

Please sign in to comment.