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

[NOID] Fixes #4122: Test if gemini-flash and gpt-4o work (#4158) #4267

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/asciidoc/modules/ROOT/pages/ml/openai.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
|===
Expand Down
13 changes: 13 additions & 0 deletions full/src/test/java/apoc/ml/OpenAIIT.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +17,7 @@
import org.neo4j.test.rule.ImpermanentDbmsRule;

public class OpenAIIT {
public static final String GPT_35_MODEL = "gpt-3.5-turbo";

private String openaiKey;

Expand Down Expand Up @@ -73,6 +75,17 @@ public void completion() {
});
}

@Test
public void chatCompletionGpt35Turbo() {
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));
}

@Test
public void chatCompletion() {
testCall(
Expand Down
Loading