Skip to content

Commit 47eac82

Browse files
authored
Merge pull request #172 from Grt1228/1.0.14
1.0.14
2 parents 9ecfd94 + e659000 commit 47eac82

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+707
-58
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ WebSocket参考:[OpenAIWebSocketEventSourceListener](https://github.com/Grt122
6464
- 支持自定义ApiKey的获取策略
6565
- 支持余额查询
6666
- 支持个人账户信息查询
67-
- 支持GPT3、GPT3.5、GPT4.0
67+
- 支持GPT3、GPT3.5、GPT4.0、GPT3.5—0614、GPT4.0—0614...
6868
- 支持全部OpenAI的Api
6969

7070
# 📑 更新日志
71-
- [ ] 1.0.14 升级支持最新版0614模型,支持function-calling
71+
- [x] 1.0.14 升级支持最新版Gpt-3.5—0614、Gpt-4.0—0614等模型, 支持function-calling完整使用案例参考:[OpenAiClientFunctionTest](https://github.com/Grt1228/chatgpt-java/blob/1.0.14/src/test/java/com/unfbx/chatgpt/OpenAiClientFunctionTest.java)
7272
- [x] 1.0.13 支持当key异常(失效、过期、封禁)时,自定义动态处理key,参考实现[DynamicKeyOpenAiAuthInterceptor](https://github.com/Grt1228/chatgpt-java/blob/main/src/main/java/com/unfbx/chatgpt/interceptor/DynamicKeyOpenAiAuthInterceptor.java) ,支持key异常时的告警处理(钉钉、飞书、email、企业微信等等需要自定义开发)
7373
- [x] 1.0.12 tokens计算优化、删除模型接口修改、语音接口更新支持官方最新参数
7474
- [x] 1.0.11 增加新的余额查询接口参考:[OpenAiClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientTest.java)[OpenAiStreamClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiStreamClientTest.java) ,修复tokens计算慢的问题,
@@ -86,9 +86,10 @@ WebSocket参考:[OpenAIWebSocketEventSourceListener](https://github.com/Grt122
8686

8787
# 🚀 快速开始
8888
本项目支持**默认输出****流式输出**。完整SDK测试案例参考:
89-
SDK测试案例 | Tokens测试案例 |
90-
---|---|
91-
[OpenAiClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientTest.java)[OpenAiStreamClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiStreamClientTest.java) | Tokens计算参考:[TikTokensTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/TikTokensTest.java)|
89+
90+
SDK测试案例 | Tokens计算测试案例 | 完整Function-Call调用案例
91+
---| --- | ---
92+
[OpenAiClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientTest.java)[OpenAiStreamClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiStreamClientTest.java) | Tokens计算参考:[TikTokensTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/TikTokensTest.java) | [OpenAiClientFunctionTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientFunctionTest.java)
9293

9394
## 方式一
9495

@@ -97,7 +98,7 @@ SDK测试案例 | Tokens测试案例 |
9798
<dependency>
9899
<groupId>com.unfbx</groupId>
99100
<artifactId>chatgpt-java</artifactId>
100-
<version>1.0.13</version>
101+
<version>1.0.14-beta1</version>
101102
</dependency>
102103
```
103104
### 2、流式客户端使用示例:

README_EN.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ WebSocket Reference:[OpenAIWebSocketEventSourceListener](https://github.com/Gr
6161
- Supports customizing the key acquisition strategy.
6262
- Supports balance inquiry.
6363
- Supports personal account information inquiry.
64-
- Supports GPT3, GPT3.5, GPT4.0.
64+
- Supports GPT3, GPT3.5, GPT4.0, GPT3.5—0614, GPT4.0—0614...
6565
- Supports all OpenAI APIs.
6666

6767
# 📑 Update Log
68-
- [ ] 1.0.14 Upgrade to support the latest version 0614 model, support function-calling
68+
- [x] 1.0.14 Upgrade to support the latest version gpt-3.5—0614、gpt-4.0—0614 models, support function-calling full test e.g.:[OpenAiClientFunctionTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientFunctionTest.java)
6969
- [x] 1.0.13 Added support for custom handling of key exceptions (invalid, expired, blocked) with the implementation reference [DynamicKeyOpenAiAuthInterceptor](https://github.com/Grt1228/chatgpt-java/blob/main/src/main/java/com/unfbx/chatgpt/interceptor/DynamicKeyOpenAiAuthInterceptor.java). Also added support for alerting on key exceptions (DingTalk, Feishu, email, WeChat Enterprise, etc.), which requires custom development.
7070
- [x] 1.0.12 Optimized token calculation, modified delete model interface, and updated speech interface to support the latest official parameters.
7171
- [x] 1.0.11 Added new balance query interface with reference to [OpenAiClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientTest.java) and [OpenAiStreamClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiStreamClientTest.java). Fixed slow token calculation issue.
@@ -85,9 +85,9 @@ WebSocket Reference:[OpenAIWebSocketEventSourceListener](https://github.com/Gr
8585

8686
This project supports both **default output** and **streaming output**. For a complete SDK test case, see:
8787

88-
SDK Test Cases | Token Test Cases |
89-
---|---|
90-
[OpenAiClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientTest.java) and [OpenAiStreamClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiStreamClientTest.java) | Token calculation reference: [TikTokensTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/TikTokensTest.java)|
88+
SDK Test Cases | TikToken Test Cases | Full Function Call Test Cases
89+
---|---|---|
90+
[OpenAiClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientTest.java) and [OpenAiStreamClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiStreamClientTest.java) | Token calculation reference: [TikTokensTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/TikTokensTest.java) | [OpenAiClientFunctionTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientFunctionTest.java)
9191

9292
## Method 1
9393

@@ -96,7 +96,7 @@ SDK Test Cases | Token Test Cases |
9696
<dependency>
9797
<groupId>com.unfbx</groupId>
9898
<artifactId>chatgpt-java</artifactId>
99-
<version>1.0.13</version>
99+
<version>1.0.14</version>
100100
</dependency>
101101
```
102102
### 2. Streaming client usage example:

Tokens_README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
chatgpt-java 更新到1.0.10支持Tokens计算,增加[TikTokensUtil](https://github.com/Grt1228/chatgpt-java/blob/main/src/main/java/com/unfbx/chatgpt/utils/TikTokensUtil.java) 工具类.
33

44
## tokens计算说明
5-
openai 的tokens计算规则适合模型先关的,不同的模型计算方法是不一样的。大致的表格如下:
5+
openai 的tokens计算规则和模型相关的,不同的模型计算方法是不一样的。大致的表格如下:
66

77
## 关于流式返回
88
流式返回的数据,返回行数-2=返回tokens
@@ -28,7 +28,7 @@ openai 的tokens计算规则适合模型先关的,不同的模型计算方法
2828
## 使用示例
2929
完整使用示例请参考:[TikTokensTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/TikTokensTest.java)
3030
31-
结合chat模型使用示例:
31+
### 结合chat模型使用示例:
3232
完整示例参考:[OpenAiClientTest](https://github.com/Grt1228/chatgpt-java/blob/main/src/test/java/com/unfbx/chatgpt/OpenAiClientTest.java)
3333
```
3434
public void chatTokensTest() {
@@ -51,7 +51,7 @@ openai 的tokens计算规则适合模型先关的,不同的模型计算方法
5151
log.info("Open AI 官方计算的返回的tokens数{}", chatCompletionResponse.getUsage().getCompletionTokens());
5252
}
5353
```
54-
单独使用示例:
54+
### 单独使用示例:
5555
```java
5656
public class TikTokensTest {
5757
String text;

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.unfbx</groupId>
77
<artifactId>chatgpt-java</artifactId>
8-
<version>1.0.13</version>
8+
<version>1.0.14</version>
99
<name>chatgpt-java</name>
1010
<description>OpenAI Java SDK, OpenAI Api for Java. ChatGPT Java SDK .</description>
1111
<url>https://www.unfbx.com</url>
@@ -115,7 +115,7 @@
115115
<dependency>
116116
<groupId>com.knuddels</groupId>
117117
<artifactId>jtokkit</artifactId>
118-
<version>0.2.0</version>
118+
<version>0.5.0</version>
119119
</dependency>
120120
</dependencies>
121121

src/main/java/com/unfbx/chatgpt/OpenAiApi.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public interface OpenAiApi {
5555
/**
5656
* models 返回的数据id
5757
*
58-
* @param id
58+
* @param id 模型主键
5959
* @return Single Model
6060
*/
6161
@GET("v1/models/{id}")
@@ -314,7 +314,7 @@ Single<WhisperResponse> speechToTextTranslations(@Part MultipartBody.Part file,
314314
/**
315315
* 账户信息查询:里面包含总金额(美元)等信息
316316
*
317-
* @return
317+
* @return 账户信息
318318
*/
319319
@GET("v1/dashboard/billing/subscription")
320320
Single<Subscription> subscription();

src/main/java/com/unfbx/chatgpt/OpenAiClient.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public class OpenAiClient {
102102
/**
103103
* 构造器
104104
*
105-
* @return
105+
* @return OpenAiClient.Builder
106106
*/
107107
public static OpenAiClient.Builder builder() {
108108
return new OpenAiClient.Builder();
@@ -189,8 +189,8 @@ public List<Model> models() {
189189
/**
190190
* openAi模型详细信息
191191
*
192-
* @param id
193-
* @return Model
192+
* @param id 模型主键
193+
* @return Model 模型类
194194
*/
195195
public Model model(String id) {
196196
if (Objects.isNull(id) || "".equals(id)) {
@@ -240,7 +240,7 @@ public EditResponse edit(Edit edit) {
240240
/**
241241
* 根据描述生成图片
242242
*
243-
* @param prompt
243+
* @param prompt 描述信息
244244
* @return ImageResponse
245245
*/
246246
public ImageResponse genImages(String prompt) {
@@ -407,7 +407,7 @@ private void checkImageSize(java.io.File image) {
407407
/**
408408
* 向量计算:单文本
409409
*
410-
* @param input
410+
* @param input 单文本
411411
* @return EmbeddingResponse
412412
*/
413413
public EmbeddingResponse embeddings(String input) {
@@ -480,7 +480,7 @@ public UploadFileResponse uploadFile(String purpose, java.io.File file) {
480480
/**
481481
* 上传文件
482482
*
483-
* @param file
483+
* @param file 文件
484484
* @return UploadFileResponse
485485
*/
486486
public UploadFileResponse uploadFile(java.io.File file) {
@@ -538,7 +538,7 @@ public ModerationResponse moderations(List<String> input) {
538538
/**
539539
* 文本审核
540540
*
541-
* @param moderation
541+
* @param moderation 审核参数
542542
* @return ModerationResponse
543543
*/
544544
public ModerationResponse moderations(Moderation moderation) {
@@ -592,7 +592,7 @@ public FineTuneResponse retrieveFineTune(String fineTuneId) {
592592
/**
593593
* 取消微调作业
594594
*
595-
* @param fineTuneId
595+
* @param fineTuneId 主键
596596
* @return FineTuneResponse
597597
*/
598598
public FineTuneResponse cancelFineTune(String fineTuneId) {
@@ -615,7 +615,7 @@ public List<Event> fineTuneEvents(String fineTuneId) {
615615
* 删除微调作业模型
616616
* Delete a fine-tuned model. You must have the Owner role in your organization.
617617
*
618-
* @param model
618+
* @param model 模型名称
619619
* @return FineTuneDeleteResponse
620620
*/
621621
public FineTuneDeleteResponse deleteFineTuneModel(String model) {
@@ -771,7 +771,7 @@ private void checkSpeechFileSize(java.io.File file) {
771771
* ## 官方已经禁止使用此api
772772
* OpenAi账户余额查询
773773
*
774-
* @return
774+
* @return 余额
775775
* @see #subscription()
776776
* @see #billingUsage(LocalDate, LocalDate)
777777
*/

src/main/java/com/unfbx/chatgpt/OpenAiStreamClient.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public Subscription subscription() {
310310
*
311311
* @param starDate 开始时间
312312
* @param endDate 结束时间
313-
* @return
313+
* @return 消耗金额信息
314314
*/
315315
public BillingUsage billingUsage(@NotNull LocalDate starDate, @NotNull LocalDate endDate) {
316316
Single<BillingUsage> billingUsage = this.openAiApi.billingUsage(starDate, endDate);
@@ -320,7 +320,7 @@ public BillingUsage billingUsage(@NotNull LocalDate starDate, @NotNull LocalDate
320320
/**
321321
* 构造
322322
*
323-
* @return
323+
* @return Builder
324324
*/
325325
public static OpenAiStreamClient.Builder builder() {
326326
return new OpenAiStreamClient.Builder();
@@ -361,7 +361,7 @@ public Builder apiKey(@NotNull List<String> val) {
361361

362362
/**
363363
* @param val api请求地址,结尾处有斜杠
364-
* @return
364+
* @return Builder
365365
* @see com.unfbx.chatgpt.constant.OpenAIConst
366366
*/
367367
public Builder apiHost(String val) {

src/main/java/com/unfbx/chatgpt/entity/billing/BillingUsage.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.unfbx.chatgpt.entity.billing;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45
import lombok.Data;
56

@@ -13,6 +14,7 @@
1314
* @since 2023-04-08
1415
*/
1516
@Data
17+
@JsonIgnoreProperties(ignoreUnknown = true)
1618
public class BillingUsage {
1719

1820
@JsonProperty("object")

src/main/java/com/unfbx/chatgpt/entity/billing/CreditGrantsResponse.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.unfbx.chatgpt.entity.billing;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45
import lombok.Data;
56

@@ -13,6 +14,7 @@
1314
* @since 2023-03-18
1415
*/
1516
@Data
17+
@JsonIgnoreProperties(ignoreUnknown = true)
1618
public class CreditGrantsResponse implements Serializable {
1719
private String object;
1820
/**

src/main/java/com/unfbx/chatgpt/entity/billing/DailyCost.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.unfbx.chatgpt.entity.billing;
22

3+
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
34
import com.fasterxml.jackson.annotation.JsonProperty;
45
import lombok.Data;
56

@@ -12,6 +13,7 @@
1213
* @since 2023-04-08
1314
*/
1415
@Data
16+
@JsonIgnoreProperties(ignoreUnknown = true)
1517
public class DailyCost {
1618
/**
1719
* 时间戳

0 commit comments

Comments
 (0)