From 00e1132799cad2884a6fab80fa84459abcacd2af Mon Sep 17 00:00:00 2001 From: Sashir Estela Date: Wed, 24 Apr 2024 03:44:04 +0000 Subject: [PATCH 1/2] Enable ChatCompletions to handle ToolCall streaming --- .../io/github/sashirestela/openai/domain/chat/Choice.java | 2 ++ .../sashirestela/openai/domain/chat/message/ChatMsg.java | 4 ++++ .../openai/domain/chat/message/ChatMsgResponse.java | 2 ++ .../openai/domain/chat/tool/ChatFunctionCall.java | 2 ++ .../sashirestela/openai/domain/chat/tool/ChatToolCall.java | 4 ++++ .../sashirestela/openai/domain/chat/ChatDomainTest.java | 1 + 6 files changed, 15 insertions(+) diff --git a/src/main/java/io/github/sashirestela/openai/domain/chat/Choice.java b/src/main/java/io/github/sashirestela/openai/domain/chat/Choice.java index a089618e..4a5ddb15 100644 --- a/src/main/java/io/github/sashirestela/openai/domain/chat/Choice.java +++ b/src/main/java/io/github/sashirestela/openai/domain/chat/Choice.java @@ -6,10 +6,12 @@ import io.github.sashirestela.openai.domain.chat.message.ChatMsgResponse; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import lombok.ToString; @NoArgsConstructor @Getter +@Setter @ToString @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class Choice { diff --git a/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsg.java b/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsg.java index 57b0392a..d5bac8dd 100644 --- a/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsg.java +++ b/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsg.java @@ -10,4 +10,8 @@ public Role getRole() { return role; } + public void setRole(Role role) { + this.role = role; + } + } diff --git a/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsgResponse.java b/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsgResponse.java index 67fa82bb..7de5de99 100644 --- a/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsgResponse.java +++ b/src/main/java/io/github/sashirestela/openai/domain/chat/message/ChatMsgResponse.java @@ -5,11 +5,13 @@ import io.github.sashirestela.openai.domain.chat.tool.ChatToolCall; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; import java.util.List; @NoArgsConstructor @Getter +@Setter @JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class) public class ChatMsgResponse extends ChatMsg { diff --git a/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatFunctionCall.java b/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatFunctionCall.java index 004aabd1..02d1f131 100644 --- a/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatFunctionCall.java +++ b/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatFunctionCall.java @@ -4,10 +4,12 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; @NoArgsConstructor @AllArgsConstructor @Getter +@Setter public class ChatFunctionCall { @Required diff --git a/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatToolCall.java b/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatToolCall.java index 9194432e..d133bdd9 100644 --- a/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatToolCall.java +++ b/src/main/java/io/github/sashirestela/openai/domain/chat/tool/ChatToolCall.java @@ -4,12 +4,16 @@ import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; +import lombok.Setter; @NoArgsConstructor @AllArgsConstructor @Getter +@Setter public class ChatToolCall { + private Integer index; + @Required private String id; diff --git a/src/test/java/io/github/sashirestela/openai/domain/chat/ChatDomainTest.java b/src/test/java/io/github/sashirestela/openai/domain/chat/ChatDomainTest.java index 22222b58..dc48c12f 100644 --- a/src/test/java/io/github/sashirestela/openai/domain/chat/ChatDomainTest.java +++ b/src/test/java/io/github/sashirestela/openai/domain/chat/ChatDomainTest.java @@ -158,6 +158,7 @@ void testChatCompletionsCreateWithFunctionAnswer() throws IOException { .message(new ChatMsgSystem("You are an expert in Mathematics")) .message(new ChatMsgUser("What is the product of 123 and 456?")) .message(new ChatMsgAssistant(null, List.of(new ChatToolCall( + 0, "call_tAoX6VHyjQVLnM9CZvEsTEwW", ChatToolType.FUNCTION, new ChatFunctionCall("product", "{\"multiplicand\":123,\"multiplier\":456}"))))) From 380dabfaae03b7024838faa506c70d2b08b685ba Mon Sep 17 00:00:00 2001 From: Sashir Estela Date: Wed, 24 Apr 2024 03:44:54 +0000 Subject: [PATCH 2/2] Deploy release 2.3.2 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 22536c1d..47dd89cd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ io.github.sashirestela simple-openai - 2.3.1 + 2.3.2 jar simple-openai