Skip to content

Commit 3367ae7

Browse files
committed
update tool_calls
1 parent ee702ab commit 3367ae7

File tree

10 files changed

+125
-21
lines changed

10 files changed

+125
-21
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ maven
5959
<dependency>
6060
<groupId>com.github.plexpt</groupId>
6161
<artifactId>chatgpt</artifactId>
62-
<version>4.2.0</version>
62+
<version>4.4.0</version>
6363
</dependency>
6464
```
6565

6666
gradle
6767
```
68-
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.2.0'
68+
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.4.0'
6969
```
7070

7171

README_en.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ SDK for OpenAI ChatGPT. If you find it helpful, please give it a star in the upp
3939
<dependency>
4040
<groupId>com.github.plexpt</groupId>
4141
<artifactId>chatgpt</artifactId>
42-
<version>4.2.0</version>
42+
<version>4.4.0</version>
4343
</dependency>
4444
```
4545

4646
#### gradle
4747

4848
```
49-
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.2.0'
49+
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.4.0'
5050
```
5151

5252
### Quick Start

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.github.plexpt</groupId>
77
<artifactId>chatgpt</artifactId>
8-
<version>4.3.0</version>
8+
<version>4.4.0</version>
99
<name>chatgpt</name>
1010
<description>ChatGPT4.0、 ChatGPT Java SDK.</description>
1111
<url>https://chat.plexpt.com</url>

src/main/java/com/plexpt/chatgpt/entity/chat/ChatChoice.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,25 @@
1111
@Data
1212
@JsonIgnoreProperties(ignoreUnknown = true)
1313
public class ChatChoice {
14+
// {
15+
// "index": 0,
16+
// "message": {
17+
// "role": "assistant",
18+
// "content": null,
19+
// "tool_calls": [
20+
// {
21+
// "id": "call_abc123",
22+
// "type": "function",
23+
// "function": {
24+
// "name": "get_current_weather",
25+
// "arguments": "{\n\"location\": \"Boston, MA\"\n}"
26+
// }
27+
// }
28+
// ]
29+
// },
30+
// "logprobs": null,
31+
// "finish_reason": "tool_calls"
32+
// }
1433
private long index;
1534
/**
1635
* 请求参数stream为true返回是delta

src/main/java/com/plexpt/chatgpt/entity/chat/ChatCompletion.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
import com.fasterxml.jackson.annotation.JsonInclude;
55
import com.fasterxml.jackson.annotation.JsonProperty;
66
import com.plexpt.chatgpt.util.TokensUtil;
7+
import lombok.*;
8+
import lombok.extern.slf4j.Slf4j;
79

8-
import java.io.Serializable;
910
import java.util.List;
1011
import java.util.Map;
1112

12-
import lombok.AllArgsConstructor;
13-
import lombok.Builder;
14-
import lombok.Data;
15-
import lombok.Getter;
16-
import lombok.NoArgsConstructor;
17-
import lombok.NonNull;
18-
import lombok.extern.slf4j.Slf4j;
19-
2013
/**
2114
* chat
2215
*
@@ -29,11 +22,11 @@
2922
@NoArgsConstructor(force = true)
3023
@JsonInclude(JsonInclude.Include.NON_NULL)
3124
@JsonIgnoreProperties(ignoreUnknown = true)
32-
public class ChatCompletion implements Serializable {
25+
public class ChatCompletion {
3326

3427
@NonNull
3528
@Builder.Default
36-
private String model = Model.GPT_3_5_TURBO_0613.getName();
29+
private String model = "gpt-3.5-turbo";
3730

3831
@NonNull
3932
private List<Message> messages;
@@ -60,6 +53,11 @@ public class ChatCompletion implements Serializable {
6053
*/
6154
String function_call;
6255

56+
@JsonProperty("tool_choice")
57+
String toolChoice;
58+
59+
List<ChatTool> tools;
60+
6361
List<ChatFunction> functions;
6462

6563
/**
@@ -124,13 +122,16 @@ public enum Model {
124122
*/
125123
GPT_3_5_TURBO_0301("gpt-3.5-turbo-0301"),
126124
GPT_3_5_TURBO_1106("gpt-3.5-turbo-1106"),
125+
GPT_3_5_TURBO_0125("gpt-3.5-turbo-0125"),
127126
GPT_3_5_TURBO_INSTRUCT("gpt-3.5-turbo-instruct"),
128127
/**
129128
* GPT4.0
130129
*/
131130
GPT_4("gpt-4"),
132131
GPT4Turbo("gpt-4-1106-preview"),
132+
GPT4Turbo0125("gpt-4-0125-preview"),
133133
GPT_4VP("gpt-4-vision-preview"),
134+
GPT_4V("gpt-4-vision-preview"),
134135
/**
135136
* 临时模型,不建议使用
136137
*/

src/main/java/com/plexpt/chatgpt/entity/chat/ChatCompletionResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ public class ChatCompletionResponse {
2323
private String systemFingerprint;
2424
private List<ChatChoice> choices;
2525
private Usage usage;
26+
2627
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.plexpt.chatgpt.entity.chat;
2+
3+
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
@Data
12+
@AllArgsConstructor
13+
@NoArgsConstructor
14+
@Builder
15+
@JsonInclude(JsonInclude.Include.NON_NULL)
16+
@JsonIgnoreProperties(ignoreUnknown = true)
17+
public class ChatTool {
18+
19+
/**
20+
* The name of the tool being called, only function supported for now.
21+
*/
22+
@Builder.Default
23+
String type = "function";
24+
25+
ChatToolFunction function;
26+
27+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.plexpt.chatgpt.entity.chat;
2+
3+
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import com.fasterxml.jackson.annotation.JsonInclude;
6+
import lombok.AllArgsConstructor;
7+
import lombok.Builder;
8+
import lombok.Data;
9+
import lombok.NoArgsConstructor;
10+
11+
import java.util.List;
12+
13+
@Data
14+
@AllArgsConstructor
15+
@NoArgsConstructor
16+
@Builder
17+
@JsonInclude(JsonInclude.Include.NON_NULL)
18+
@JsonIgnoreProperties(ignoreUnknown = true)
19+
public class ChatToolFunction {
20+
21+
String name;
22+
23+
String description;
24+
25+
ChatParameter parameters;
26+
27+
28+
@Data
29+
@AllArgsConstructor
30+
@NoArgsConstructor
31+
@Builder
32+
@JsonInclude(JsonInclude.Include.NON_NULL)
33+
public static class ChatParameter {
34+
35+
String type;
36+
List<String> required;
37+
Object properties;
38+
}
39+
40+
}

src/main/java/com/plexpt/chatgpt/entity/chat/Message.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
44
import com.fasterxml.jackson.annotation.JsonInclude;
55
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import lombok.*;
67

7-
import lombok.AllArgsConstructor;
8-
import lombok.Builder;
9-
import lombok.Data;
10-
import lombok.Getter;
11-
import lombok.NoArgsConstructor;
8+
import java.util.List;
129

1310
/**
1411
* @author plexpt
@@ -30,6 +27,9 @@ public class Message {
3027
@JsonProperty("function_call")
3128
private FunctionCallResult functionCall;
3229

30+
@JsonProperty("tool_calls")
31+
private List<ToolCallResult> toolCalls;
32+
3333
public Message(String role, String content) {
3434
this.role = role;
3535
this.content = content;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.plexpt.chatgpt.entity.chat;
2+
3+
4+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
5+
import lombok.Data;
6+
7+
@Data
8+
@JsonIgnoreProperties(ignoreUnknown = true)
9+
public class ToolCallResult {
10+
11+
String id;
12+
13+
String type;
14+
15+
FunctionCallResult function;
16+
}

0 commit comments

Comments
 (0)