Skip to content

Commit 90fddb3

Browse files
author
guorutao
committed
Merge branch 'develop' into 1.0.15
# Conflicts: # src/main/java/com/unfbx/chatgpt/entity/chat/Functions.java
2 parents cbac3eb + eed52c9 commit 90fddb3

29 files changed

+56
-88
lines changed

pom.xml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@
5959
<artifactId>slf4j-api</artifactId>
6060
<version>${slf4j.version}</version>
6161
</dependency>
62-
<dependency>
63-
<groupId>org.slf4j</groupId>
64-
<artifactId>slf4j-simple</artifactId>
65-
<version>${slf4j.version}</version>
66-
</dependency>
6762
<dependency>
6863
<groupId>com.fasterxml.jackson.core</groupId>
6964
<artifactId>jackson-databind</artifactId>
@@ -106,6 +101,12 @@
106101
<version>4.13.2</version>
107102
<scope>test</scope>
108103
</dependency>
104+
<dependency>
105+
<groupId>org.slf4j</groupId>
106+
<artifactId>slf4j-simple</artifactId>
107+
<version>${slf4j.version}</version>
108+
<scope>test</scope>
109+
</dependency>
109110
<dependency>
110111
<groupId>org.jetbrains</groupId>
111112
<artifactId>annotations</artifactId>

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,12 @@ private OkHttpClient okHttpClient() {
166166
}
167167
this.authInterceptor.setApiKey(this.apiKey);
168168
this.authInterceptor.setKeyStrategy(this.keyStrategy);
169-
OkHttpClient okHttpClient = new OkHttpClient
169+
return new OkHttpClient
170170
.Builder()
171171
.addInterceptor(this.authInterceptor)
172172
.connectTimeout(30, TimeUnit.SECONDS)
173173
.writeTimeout(30, TimeUnit.SECONDS)
174174
.readTimeout(30, TimeUnit.SECONDS).build();
175-
return okHttpClient;
176175
}
177176

178177
/**
@@ -182,8 +181,7 @@ private OkHttpClient okHttpClient() {
182181
*/
183182
public List<Model> models() {
184183
Single<ModelResponse> models = this.openAiApi.models();
185-
List<Model> modelList = models.blockingGet().getData();
186-
return modelList;
184+
return models.blockingGet().getData();
187185
}
188186

189187
/**
@@ -727,7 +725,7 @@ public WhisperResponse speechToTextTranslations(java.io.File file, Translations
727725
RequestBody fileBody = RequestBody.create(MediaType.parse("multipart/form-data"), file);
728726
MultipartBody.Part multipartBody = MultipartBody.Part.createFormData("file", file.getName(), fileBody);
729727
//自定义参数
730-
Map<String, RequestBody> requestBodyMap = new HashMap<>();
728+
Map<String, RequestBody> requestBodyMap = new HashMap<>(5,1L);
731729

732730
if (StrUtil.isNotBlank(translations.getModel())) {
733731
requestBodyMap.put(Translations.Fields.model, RequestBody.create(MediaType.parse("multipart/form-data"), translations.getModel()));
@@ -738,9 +736,7 @@ public WhisperResponse speechToTextTranslations(java.io.File file, Translations
738736
if (StrUtil.isNotBlank(translations.getResponseFormat())) {
739737
requestBodyMap.put(Translations.Fields.responseFormat, RequestBody.create(MediaType.parse("multipart/form-data"), translations.getResponseFormat()));
740738
}
741-
if (Objects.nonNull(translations.getTemperature())) {
742-
requestBodyMap.put(Translations.Fields.temperature, RequestBody.create(MediaType.parse("multipart/form-data"), String.valueOf(translations.getTemperature())));
743-
}
739+
requestBodyMap.put(Translations.Fields.temperature, RequestBody.create(MediaType.parse("multipart/form-data"), String.valueOf(translations.getTemperature())));
744740
Single<WhisperResponse> whisperResponse = this.openAiApi.speechToTextTranslations(multipartBody, requestBodyMap);
745741
return whisperResponse.blockingGet();
746742
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,13 @@ private OkHttpClient okHttpClient() {
142142
}
143143
this.authInterceptor.setApiKey(this.apiKey);
144144
this.authInterceptor.setKeyStrategy(this.keyStrategy);
145-
OkHttpClient okHttpClient = new OkHttpClient
145+
return new OkHttpClient
146146
.Builder()
147147
.addInterceptor(this.authInterceptor)
148148
.connectTimeout(10, TimeUnit.SECONDS)
149149
.writeTimeout(50, TimeUnit.SECONDS)
150150
.readTimeout(50, TimeUnit.SECONDS)
151151
.build();
152-
return okHttpClient;
153152
}
154153

155154
/**
@@ -279,9 +278,8 @@ public CreditGrantsResponse creditGrants() {
279278
log.error(openAiResponse.getError().getMessage());
280279
throw new BaseException(openAiResponse.getError().getMessage());
281280
}
282-
String errorMsg = bodyStr;
283-
log.error("询余额请求异常:{}", errorMsg);
284-
OpenAiResponse openAiResponse = JSONUtil.toBean(errorMsg, OpenAiResponse.class);
281+
log.error("询余额请求异常:{}", bodyStr);
282+
OpenAiResponse openAiResponse = JSONUtil.toBean(bodyStr, OpenAiResponse.class);
285283
if (Objects.nonNull(openAiResponse.getError())) {
286284
log.error(openAiResponse.getError().getMessage());
287285
throw new BaseException(openAiResponse.getError().getMessage());
@@ -290,8 +288,7 @@ public CreditGrantsResponse creditGrants() {
290288
}
291289
ObjectMapper mapper = new ObjectMapper();
292290
// 读取Json 返回值
293-
CreditGrantsResponse completionResponse = mapper.readValue(bodyStr, CreditGrantsResponse.class);
294-
return completionResponse;
291+
return mapper.readValue(bodyStr, CreditGrantsResponse.class);
295292
}
296293

297294
/**

src/main/java/com/unfbx/chatgpt/config/ChatGPTUrl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ public enum ChatGPTUrl {
1616
COMPLETIONS("https://api.openai.com/v1/completions"),
1717
;
1818

19-
private String url;
19+
private final String url;
2020

2121
}

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

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

3-
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
43
import com.fasterxml.jackson.annotation.JsonProperty;
54
import lombok.Data;
65

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ public enum Model {
175175
*/
176176
GPT_4_32K_0613("gpt-4-32k-0613"),
177177
;
178-
private String name;
178+
private final String name;
179179
}
180180

181181
}
182-
183-

src/main/java/com/unfbx/chatgpt/entity/chat/FunctionCall.java

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

3-
import cn.hutool.json.JSONUtil;
43
import lombok.AllArgsConstructor;
54
import lombok.Builder;
65
import lombok.Data;
@@ -9,7 +8,7 @@
98
/**
109
* 描述:函数调用返回值
1110
*
12-
* @author https://www.unfbx.com
11+
* @author <a href="https://www.unfbx.com">unfbx</a>
1312
* @since 2023-06-14
1413
*/
1514
@Data

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public enum Role {
7272
ASSISTANT("assistant"),
7373
FUNCTION("function"),
7474
;
75-
private String name;
75+
private final String name;
7676
}
7777

7878
public static final class Builder {

src/main/java/com/unfbx/chatgpt/entity/completions/Completion.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import cn.hutool.core.util.StrUtil;
44
import com.fasterxml.jackson.annotation.JsonInclude;
55
import com.fasterxml.jackson.annotation.JsonProperty;
6-
import com.unfbx.chatgpt.exception.BaseException;
7-
import com.unfbx.chatgpt.exception.CommonError;
86
import com.unfbx.chatgpt.utils.TikTokensUtil;
97
import lombok.*;
108
import lombok.extern.slf4j.Slf4j;
@@ -121,8 +119,6 @@ public enum Model {
121119
DAVINCI_002("text-davinci-002"),
122120
DAVINCI("davinci"),
123121
;
124-
private String name;
122+
private final String name;
125123
}
126124
}
127-
128-

src/main/java/com/unfbx/chatgpt/entity/edits/Edit.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,6 @@ public void setTemperature(double temperature) {
6666
this.temperature = 2;
6767
return;
6868
}
69-
if (temperature < 0) {
70-
log.error("temperature参数异常,temperature属于[0,2]");
71-
this.temperature = 0;
72-
return;
73-
}
7469
this.temperature = temperature;
7570
}
7671

@@ -96,9 +91,6 @@ public enum Model {
9691
TEXT_DAVINCI_EDIT_001("text-davinci-edit-001"),
9792
CODE_DAVINCI_EDIT_001("code-davinci-edit-001"),
9893
;
99-
private String name;
94+
private final String name;
10095
}
10196
}
102-
103-
104-

0 commit comments

Comments
 (0)