Skip to content

Commit

Permalink
[NOID] fix compile errors and format changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vga91 committed Dec 18, 2024
1 parent c154331 commit 166312e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions full/src/main/java/apoc/ml/OpenAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Objects;
import java.util.function.BiFunction;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -117,7 +118,7 @@ public Stream<EmbeddingResult> getEmbedding(
*/
boolean failOnError = isFailOnError(configuration);
if (checkNullInput(texts, failOnError)) return Stream.empty();
texts = texts.stream().filter(StringUtils::isNotBlank).toList();
texts = texts.stream().filter(StringUtils::isNotBlank).collect(Collectors.toList());
if (checkEmptyInput(texts, failOnError)) return Stream.empty();
return getEmbeddingResult(texts, apiKey, configuration, apocConfig, (map, text) -> {
Long index = (Long) map.get("index");
Expand Down Expand Up @@ -183,7 +184,7 @@ public Stream<MapResult> chatCompletion(
throws Exception {
boolean failOnError = isFailOnError(configuration);
if (checkNullInput(messages, failOnError)) return Stream.empty();
messages = messages.stream().filter(MapUtils::isNotEmpty).toList();
messages = messages.stream().filter(MapUtils::isNotEmpty).collect(Collectors.toList());
if (checkEmptyInput(messages, failOnError)) return Stream.empty();
String model = (String) configuration.putIfAbsent("model", "gpt-4o");
return executeRequest(apiKey, configuration, "chat/completions", model, "messages", messages, "$", apocConfig)
Expand Down
7 changes: 4 additions & 3 deletions full/src/test/java/apoc/ml/OpenAIIT.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package apoc.ml;

import static apoc.ml.MLUtil.ERROR_NULL_INPUT;
import static apoc.ml.OpenAI.FAIL_ON_ERROR_CONF;
import static apoc.ml.OpenAITestResultUtils.assertChatCompletion;
import static apoc.util.TestUtil.testCall;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand Down Expand Up @@ -147,13 +148,13 @@ public void embeddingsNull() {
assertNullInputFails(
db,
"CALL apoc.ml.openai.embedding(null, $apiKey, $conf)",
Map.of("apiKey", openaiKey, "conf", emptyMap()));
Map.of("apiKey", openaiKey, "conf", Map.of()));
}

@Test
public void chatNull() {
assertNullInputFails(
db, "CALL apoc.ml.openai.chat(null, $apiKey, $conf)", Map.of("apiKey", openaiKey, "conf", emptyMap()));
db, "CALL apoc.ml.openai.chat(null, $apiKey, $conf)", Map.of("apiKey", openaiKey, "conf", Map.of()));
}

@Test
Expand All @@ -175,7 +176,7 @@ public void embeddingsReturnsEmptyIfFailOnErrorFalse() {
@Test
public void chatWithEmptyFails() {
assertNullInputFails(
db, "CALL apoc.ml.openai.chat([], $apiKey, $conf)", Map.of("apiKey", openaiKey, "conf", emptyMap()));
db, "CALL apoc.ml.openai.chat([], $apiKey, $conf)", Map.of("apiKey", openaiKey, "conf", Map.of()));
}

@Test
Expand Down

0 comments on commit 166312e

Please sign in to comment.