From e1c5d58a77cd52f5d2b301d639b8857eaa0becab Mon Sep 17 00:00:00 2001 From: LookforFPS <36205340+LookforFPS@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:28:36 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=94=A7=20modified=20ResponseFormat=20?= =?UTF-8?q?of=20ChatCompletion=20due=20API=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../oja/chatcompletion/ChatCompletionService.java | 4 +--- .../config/ChatCompletionConfiguration.java | 10 +++++++++- .../model/natives/request/ResponseFormat.java | 11 +++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/me/lookforfps/oja/chatcompletion/ChatCompletionService.java b/src/main/java/me/lookforfps/oja/chatcompletion/ChatCompletionService.java index fae88b2..972f303 100644 --- a/src/main/java/me/lookforfps/oja/chatcompletion/ChatCompletionService.java +++ b/src/main/java/me/lookforfps/oja/chatcompletion/ChatCompletionService.java @@ -153,9 +153,7 @@ private byte[] buildRequest() throws IOException { requestDto.setMax_tokens(config.getMaxTokens()); requestDto.setN(config.getChoices()); requestDto.setPresence_penalty(config.getPresencePenalty()); - if(config.getResponseType() != null) { - requestDto.setResponse_format(new ResponseFormat(config.getResponseType().getIdentifier())); - } + requestDto.setResponse_format(config.getResponseFormat()); requestDto.setSeed(config.getSeed()); if(config.getServiceTier() != null) { requestDto.setService_tier(config.getServiceTier().getIdentifier()); diff --git a/src/main/java/me/lookforfps/oja/chatcompletion/config/ChatCompletionConfiguration.java b/src/main/java/me/lookforfps/oja/chatcompletion/config/ChatCompletionConfiguration.java index 13e54ae..1e4a870 100644 --- a/src/main/java/me/lookforfps/oja/chatcompletion/config/ChatCompletionConfiguration.java +++ b/src/main/java/me/lookforfps/oja/chatcompletion/config/ChatCompletionConfiguration.java @@ -2,6 +2,7 @@ import lombok.Data; import lombok.EqualsAndHashCode; +import me.lookforfps.oja.chatcompletion.model.natives.request.ResponseFormat; import me.lookforfps.oja.chatcompletion.model.natives.request.ResponseType; import me.lookforfps.oja.chatcompletion.model.natives.request.ServiceTier; import me.lookforfps.oja.chatcompletion.model.natives.tools.Tool; @@ -111,7 +112,7 @@ public class ChatCompletionConfiguration extends Configuration { *

* Setting to { "type": "json_object" } enables JSON mode, which guarantees the message the model generates is valid JSON. */ - private ResponseType responseType; + private ResponseFormat responseFormat; /** * What sampling temperature to use, between 0 and 2. * Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.
@@ -163,4 +164,11 @@ public void removeTool(Tool tool) { public void removeTool(int toolIndex) { tools.remove(toolIndex); } + + public void setResponseFormat(ResponseType responsetype) { + this.responseFormat = new ResponseFormat(responsetype.getIdentifier()); + } + public void setResponseFormat(String jsonSchema) { + this.responseFormat = new ResponseFormat("json_schema", jsonSchema); + } } diff --git a/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/request/ResponseFormat.java b/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/request/ResponseFormat.java index 2290783..6372fec 100644 --- a/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/request/ResponseFormat.java +++ b/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/request/ResponseFormat.java @@ -1,12 +1,19 @@ package me.lookforfps.oja.chatcompletion.model.natives.request; -import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; @Data -@AllArgsConstructor @NoArgsConstructor public class ResponseFormat { private String type; + private String json_schema; + + public ResponseFormat(String type, String jsonSchema) { + this.type = type; + this.json_schema = jsonSchema; + } + public ResponseFormat(String type) { + this(type, null); + } } From 21ba29622db2e031993ac6be8e12d9fe5f911a02 Mon Sep 17 00:00:00 2001 From: LookforFPS <36205340+LookforFPS@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:29:39 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=94=A7=20modified=20AssistantMessage?= =?UTF-8?q?=20and=20Delta=20of=20ChatCompletion=20due=20API=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/natives/message/AssistantMessage.java | 7 ++++++- .../oja/chatcompletion/model/streaming/choice/Delta.java | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/message/AssistantMessage.java b/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/message/AssistantMessage.java index 0bf6360..51ce3a5 100644 --- a/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/message/AssistantMessage.java +++ b/src/main/java/me/lookforfps/oja/chatcompletion/model/natives/message/AssistantMessage.java @@ -14,15 +14,20 @@ public class AssistantMessage extends Message { private String content; private String name; + private String refusal; private List tool_calls; - public AssistantMessage(String content, String name, List tool_calls) { + public AssistantMessage(String content, String name, String refusal, List tool_calls) { super(MessageRole.ASSISTANT); this.content = content; this.name = name; + this.refusal = refusal; this.tool_calls = tool_calls; } + public AssistantMessage(String content, String name, List tool_calls) { + this(content, name, null, tool_calls); + } public AssistantMessage(String content, List tool_calls) { this(content, null, tool_calls); } diff --git a/src/main/java/me/lookforfps/oja/chatcompletion/model/streaming/choice/Delta.java b/src/main/java/me/lookforfps/oja/chatcompletion/model/streaming/choice/Delta.java index 51c5f27..812d048 100644 --- a/src/main/java/me/lookforfps/oja/chatcompletion/model/streaming/choice/Delta.java +++ b/src/main/java/me/lookforfps/oja/chatcompletion/model/streaming/choice/Delta.java @@ -10,5 +10,6 @@ public class Delta { private String role; private String content; + private String refusal; private List tool_calls; } From e71bf2525087cbb15dba23272b4c030734a496b1 Mon Sep 17 00:00:00 2001 From: LookforFPS <36205340+LookforFPS@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:31:48 +0200 Subject: [PATCH 3/4] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20upgraded=20dependencie?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle/libs.versions.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b692886..fb17731 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,8 +1,8 @@ [versions] -com-fasterxml-jackson-core-jackson-databind = "2.17.0" -org-projectlombok-lombok = "1.18.32" -org-slf4j-slf4j-api = "2.0.13" +com-fasterxml-jackson-core-jackson-databind = "2.17.2" +org-projectlombok-lombok = "1.18.34" +org-slf4j-slf4j-api = "2.0.16" [libraries] com-fasterxml-jackson-core-jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind", version.ref = "com-fasterxml-jackson-core-jackson-databind" } From 0fcd3aaffe42f44f2357baf16692bc13bb37428a Mon Sep 17 00:00:00 2001 From: LookforFPS <36205340+LookforFPS@users.noreply.github.com> Date: Wed, 14 Aug 2024 22:32:04 +0200 Subject: [PATCH 4/4] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20upgraded=20project=20v?= =?UTF-8?q?ersion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2523855..57e443b 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ plugins { project.group = 'me.lookforfps' project.description = "OpenAI Java API" -project.version = new Version("1", "0", "0", "preview") +project.version = new Version("1", "0", "1") java { sourceCompatibility = JavaVersion.VERSION_1_8