Skip to content

Commit

Permalink
[ISSUE apache#4047] fix review question
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangShuJu committed Apr 16, 2024
1 parent 6ccc530 commit 010e2a9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ public class OpenaiConfig {

private String token;
private String model;
private long timeout;
private long timeout = 30;
private Double temperature;
private Integer maxTokens;
private Boolean logprob;
private Double topLogprobs;
private Map<String, Integer> logitBias;
private Double frequencyPenalty;
private Double presencePenalty;
private String user;
private String user = "eventMesh";
private List<String> stop;

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import org.apache.eventmesh.common.ThreadPoolFactory;
import org.apache.eventmesh.common.exception.EventMeshException;
import org.apache.eventmesh.common.utils.AssertUtils;
import org.apache.eventmesh.connector.chatgpt.source.config.ChatGPTSourceConfig;
import org.apache.eventmesh.connector.chatgpt.source.dto.ChatGPTRequestDTO;
import org.apache.eventmesh.connector.chatgpt.source.enums.ChatGPTRequestType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public class OpenaiManager {

private String chatCompletionRequestTemplateStr;

private static final int DEFAULT_TIMEOUT = 30;

public OpenaiManager(ChatGPTSourceConfig sourceConfig) {
initOpenAi(sourceConfig);
}
Expand All @@ -77,7 +79,11 @@ public ChatCompletionRequest newChatCompletionRequest(List<ChatMessage> chatMess

private void initOpenAi(ChatGPTSourceConfig sourceConfig) {
OpenaiConfig openaiConfig = sourceConfig.getOpenaiConfig();
AssertUtils.isTrue(openaiConfig.getTimeout() > 0, "openaiTimeout must be >= 0");
if (openaiConfig.getTimeout() <= 0) {
log.warn("openaiTimeout must be > 0, your config value is {}, openaiTimeout will be reset {}", openaiConfig.getTimeout(),
DEFAULT_TIMEOUT);
openaiConfig.setTimeout(DEFAULT_TIMEOUT);
}
boolean proxyEnable = sourceConfig.connectorConfig.isProxyEnable();
if (proxyEnable) {
OpenaiProxyConfig chatgptProxyConfig = sourceConfig.openaiProxyConfig;
Expand All @@ -86,7 +92,8 @@ private void initOpenAi(ChatGPTSourceConfig sourceConfig) {
}
ObjectMapper mapper = defaultObjectMapper();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(chatgptProxyConfig.getHost(), chatgptProxyConfig.getPort()));
OkHttpClient client = defaultClient(openaiConfig.getToken(), Duration.ofSeconds(openaiConfig.getTimeout())).newBuilder().proxy(proxy).build();
OkHttpClient client =
defaultClient(openaiConfig.getToken(), Duration.ofSeconds(openaiConfig.getTimeout())).newBuilder().proxy(proxy).build();
Retrofit retrofit = defaultRetrofit(client, mapper);
OpenAiApi api = retrofit.create(OpenAiApi.class);
this.openAiService = new OpenAiService(api);
Expand Down

0 comments on commit 010e2a9

Please sign in to comment.