Skip to content

Commit

Permalink
update tool_calls
Browse files Browse the repository at this point in the history
  • Loading branch information
PlexPt committed Mar 29, 2024
1 parent ee702ab commit 3367ae7
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 21 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ maven
<dependency>
<groupId>com.github.plexpt</groupId>
<artifactId>chatgpt</artifactId>
<version>4.2.0</version>
<version>4.4.0</version>
</dependency>
```

gradle
```
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.2.0'
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.4.0'
```


Expand Down
4 changes: 2 additions & 2 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ SDK for OpenAI ChatGPT. If you find it helpful, please give it a star in the upp
<dependency>
<groupId>com.github.plexpt</groupId>
<artifactId>chatgpt</artifactId>
<version>4.2.0</version>
<version>4.4.0</version>
</dependency>
```

#### gradle

```
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.2.0'
implementation group: 'com.github.plexpt', name: 'chatgpt', version: '4.4.0'
```

### Quick Start
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.plexpt</groupId>
<artifactId>chatgpt</artifactId>
<version>4.3.0</version>
<version>4.4.0</version>
<name>chatgpt</name>
<description>ChatGPT4.0、 ChatGPT Java SDK.</description>
<url>https://chat.plexpt.com</url>
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/com/plexpt/chatgpt/entity/chat/ChatChoice.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,25 @@
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ChatChoice {
// {
// "index": 0,
// "message": {
// "role": "assistant",
// "content": null,
// "tool_calls": [
// {
// "id": "call_abc123",
// "type": "function",
// "function": {
// "name": "get_current_weather",
// "arguments": "{\n\"location\": \"Boston, MA\"\n}"
// }
// }
// ]
// },
// "logprobs": null,
// "finish_reason": "tool_calls"
// }
private long index;
/**
* 请求参数stream为true返回是delta
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/com/plexpt/chatgpt/entity/chat/ChatCompletion.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,12 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.plexpt.chatgpt.util.TokensUtil;
import lombok.*;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;

/**
* chat
*
Expand All @@ -29,11 +22,11 @@
@NoArgsConstructor(force = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ChatCompletion implements Serializable {
public class ChatCompletion {

@NonNull
@Builder.Default
private String model = Model.GPT_3_5_TURBO_0613.getName();
private String model = "gpt-3.5-turbo";

@NonNull
private List<Message> messages;
Expand All @@ -60,6 +53,11 @@ public class ChatCompletion implements Serializable {
*/
String function_call;

@JsonProperty("tool_choice")
String toolChoice;

List<ChatTool> tools;

List<ChatFunction> functions;

/**
Expand Down Expand Up @@ -124,13 +122,16 @@ public enum Model {
*/
GPT_3_5_TURBO_0301("gpt-3.5-turbo-0301"),
GPT_3_5_TURBO_1106("gpt-3.5-turbo-1106"),
GPT_3_5_TURBO_0125("gpt-3.5-turbo-0125"),
GPT_3_5_TURBO_INSTRUCT("gpt-3.5-turbo-instruct"),
/**
* GPT4.0
*/
GPT_4("gpt-4"),
GPT4Turbo("gpt-4-1106-preview"),
GPT4Turbo0125("gpt-4-0125-preview"),
GPT_4VP("gpt-4-vision-preview"),
GPT_4V("gpt-4-vision-preview"),
/**
* 临时模型,不建议使用
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public class ChatCompletionResponse {
private String systemFingerprint;
private List<ChatChoice> choices;
private Usage usage;

}
27 changes: 27 additions & 0 deletions src/main/java/com/plexpt/chatgpt/entity/chat/ChatTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.plexpt.chatgpt.entity.chat;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ChatTool {

/**
* The name of the tool being called, only function supported for now.
*/
@Builder.Default
String type = "function";

ChatToolFunction function;

}
40 changes: 40 additions & 0 deletions src/main/java/com/plexpt/chatgpt/entity/chat/ChatToolFunction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.plexpt.chatgpt.entity.chat;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ChatToolFunction {

String name;

String description;

ChatParameter parameters;


@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class ChatParameter {

String type;
List<String> required;
Object properties;
}

}
10 changes: 5 additions & 5 deletions src/main/java/com/plexpt/chatgpt/entity/chat/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.*;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import java.util.List;

/**
* @author plexpt
Expand All @@ -30,6 +27,9 @@ public class Message {
@JsonProperty("function_call")
private FunctionCallResult functionCall;

@JsonProperty("tool_calls")
private List<ToolCallResult> toolCalls;

public Message(String role, String content) {
this.role = role;
this.content = content;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/plexpt/chatgpt/entity/chat/ToolCallResult.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.plexpt.chatgpt.entity.chat;


import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class ToolCallResult {

String id;

String type;

FunctionCallResult function;
}

0 comments on commit 3367ae7

Please sign in to comment.