From 77219d497bd2d7904fb6210948558f7e1ecd7303 Mon Sep 17 00:00:00 2001 From: Theo Kanning Date: Fri, 19 Aug 2022 09:44:38 -0500 Subject: [PATCH] Add user to CompletionRequest (#23) Fixes https://github.com/TheoKanning/openai-java/issues/19 --- .../com/theokanning/openai/completion/CompletionRequest.java | 5 +++++ .../src/test/java/com/theokanning/openai/CompletionTest.java | 1 + example/src/main/java/example/OpenAiApiExample.java | 1 + 3 files changed, 7 insertions(+) diff --git a/api/src/main/java/com/theokanning/openai/completion/CompletionRequest.java b/api/src/main/java/com/theokanning/openai/completion/CompletionRequest.java index f6c80bc..f6187f7 100644 --- a/api/src/main/java/com/theokanning/openai/completion/CompletionRequest.java +++ b/api/src/main/java/com/theokanning/openai/completion/CompletionRequest.java @@ -108,4 +108,9 @@ public class CompletionRequest { * best_of must be greater than n. */ Integer bestOf; + + /** + * A unique identifier representing your end-user, which will help OpenAI to monitor and detect abuse. + */ + String user; } diff --git a/client/src/test/java/com/theokanning/openai/CompletionTest.java b/client/src/test/java/com/theokanning/openai/CompletionTest.java index 00cf8ea..de4f214 100644 --- a/client/src/test/java/com/theokanning/openai/CompletionTest.java +++ b/client/src/test/java/com/theokanning/openai/CompletionTest.java @@ -19,6 +19,7 @@ public class CompletionTest { CompletionRequest completionRequest = CompletionRequest.builder() .prompt("Somebody once told me the world is gonna roll me") .echo(true) + .user("testing") .build(); List choices = service.createCompletion("ada", completionRequest).getChoices(); diff --git a/example/src/main/java/example/OpenAiApiExample.java b/example/src/main/java/example/OpenAiApiExample.java index bd9d9a0..7d231eb 100644 --- a/example/src/main/java/example/OpenAiApiExample.java +++ b/example/src/main/java/example/OpenAiApiExample.java @@ -23,6 +23,7 @@ class OpenAiApiExample { CompletionRequest completionRequest = CompletionRequest.builder() .prompt("Somebody once told me the world is gonna roll me") .echo(true) + .user("testing") .build(); service.createCompletion("ada", completionRequest).getChoices().forEach(System.out::println);