From d5b64850fa8d8091853d3e3084a2da491b4c621d Mon Sep 17 00:00:00 2001 From: Giuseppe Villani Date: Tue, 30 Jul 2024 10:49:48 +0200 Subject: [PATCH 1/2] [NOID] Fixes #4122: Test if gemini-flash and gpt-4o work (#4158) --- .../modules/ROOT/pages/ml/openai.adoc | 32 +++++++++++++++++++ full/src/test/java/apoc/ml/OpenAIIT.java | 10 +++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/docs/asciidoc/modules/ROOT/pages/ml/openai.adoc b/docs/asciidoc/modules/ROOT/pages/ml/openai.adoc index e63bba7e10..07e86bb8a8 100644 --- a/docs/asciidoc/modules/ROOT/pages/ml/openai.adoc +++ b/docs/asciidoc/modules/ROOT/pages/ml/openai.adoc @@ -167,6 +167,38 @@ usage={completion_tokens=2, prompt_tokens=26, total_tokens=28}, choices=[{finish_reason="stop", index=0, message={role="assistant", content="Earth."}}]} ---- +.Chat Completion Call with custom model +[source,cypher] +---- +CALL apoc.ml.openai.chat([ +{role:"user", content:"Which athletes won the gold medal in mixed doubles's curling at the 2022 Winter Olympics?"} +], $apiKey, { model: "gpt-3.5-turbo" }) yield value +---- + +.Chat Completion Response with custom model +---- +{ + "created" : 1721902606, + "usage" : { + "total_tokens" : 59, + "completion_tokens" : 32, + "prompt_tokens" : 27 + }, + "model" : "gpt-3.5-turbo-2024-05-13", + "id" : "chatcmpl-9opocM1gj9AMXIh7oSWWfoumJOTRC", + "choices" : [ { + "index" : 0, + "finish_reason" : "stop", + "message" : { + "content" : "The gold medal in mixed doubles curling at the 2022 Winter Olympics was won by the Italian team, consisting of Stefania Constantini and Amos Mosaner.", + "role" : "assistant" + } + } ], + "system_fingerprint" : "fp_400f27fa1f", + "object" : "chat.completion" +} +---- + .Parameters [%autowidth, opts=header] |=== diff --git a/full/src/test/java/apoc/ml/OpenAIIT.java b/full/src/test/java/apoc/ml/OpenAIIT.java index 843ccb275b..f73c53702e 100644 --- a/full/src/test/java/apoc/ml/OpenAIIT.java +++ b/full/src/test/java/apoc/ml/OpenAIIT.java @@ -1,5 +1,6 @@ package apoc.ml; +import static apoc.ml.OpenAITestResultUtils.assertChatCompletion; import static apoc.util.TestUtil.testCall; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -16,7 +17,8 @@ import org.neo4j.test.rule.ImpermanentDbmsRule; public class OpenAIIT { - + public static final String GPT_35_MODEL = "gpt-3.5-turbo"; + private String openaiKey; @Rule @@ -73,6 +75,12 @@ public void completion() { }); } + @Test + public void chatCompletionGpt35Turbo() { + testCall(db, CHAT_COMPLETION_QUERY, Map.of("apiKey",openaiKey, "conf", Map.of("model", GPT_35_MODEL)), + (row) -> assertChatCompletion(row, GPT_35_MODEL)); + } + @Test public void chatCompletion() { testCall( From 3ef6f00eb212a34b8bee75ff74c2d2b31826ccf5 Mon Sep 17 00:00:00 2001 From: vga91 Date: Wed, 4 Dec 2024 17:38:44 +0100 Subject: [PATCH 2/2] [NOID] fix compile --- full/src/test/java/apoc/ml/OpenAIIT.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/full/src/test/java/apoc/ml/OpenAIIT.java b/full/src/test/java/apoc/ml/OpenAIIT.java index f73c53702e..012e6ba0b0 100644 --- a/full/src/test/java/apoc/ml/OpenAIIT.java +++ b/full/src/test/java/apoc/ml/OpenAIIT.java @@ -18,7 +18,7 @@ public class OpenAIIT { public static final String GPT_35_MODEL = "gpt-3.5-turbo"; - + private String openaiKey; @Rule @@ -77,7 +77,12 @@ public void completion() { @Test public void chatCompletionGpt35Turbo() { - testCall(db, CHAT_COMPLETION_QUERY, Map.of("apiKey",openaiKey, "conf", Map.of("model", GPT_35_MODEL)), + testCall( + db, + "CALL apoc.ml.openai.chat([\n" + "{role:\"system\", content:\"Only answer with a single word\"},\n" + + "{role:\"user\", content:\"What planet do humans live on?\"}\n" + + "], $apiKey, $conf)\n", + Map.of("apiKey", openaiKey, "conf", Map.of("model", GPT_35_MODEL)), (row) -> assertChatCompletion(row, GPT_35_MODEL)); }