From 010e2a98e39f97471b8d4036022618a3f0a4aca0 Mon Sep 17 00:00:00 2001 From: JiangShuJu Date: Tue, 16 Apr 2024 22:27:27 +0800 Subject: [PATCH] [ISSUE #4047] fix review question --- .../connector/chatgpt/source/config/OpenaiConfig.java | 4 ++-- .../source/connector/ChatGPTSourceConnector.java | 1 - .../chatgpt/source/managers/OpenaiManager.java | 11 +++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/config/OpenaiConfig.java b/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/config/OpenaiConfig.java index 1954c74ddd..58ac1cea39 100644 --- a/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/config/OpenaiConfig.java +++ b/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/config/OpenaiConfig.java @@ -28,7 +28,7 @@ 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; @@ -36,7 +36,7 @@ public class OpenaiConfig { private Map logitBias; private Double frequencyPenalty; private Double presencePenalty; - private String user; + private String user = "eventMesh"; private List stop; } diff --git a/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/connector/ChatGPTSourceConnector.java b/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/connector/ChatGPTSourceConnector.java index b2427f0205..3d1465a85f 100644 --- a/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/connector/ChatGPTSourceConnector.java +++ b/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/connector/ChatGPTSourceConnector.java @@ -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; diff --git a/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/managers/OpenaiManager.java b/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/managers/OpenaiManager.java index 246e0b890b..570fb39728 100644 --- a/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/managers/OpenaiManager.java +++ b/eventmesh-connectors/eventmesh-connector-chatgpt/src/main/java/org/apache/eventmesh/connector/chatgpt/source/managers/OpenaiManager.java @@ -54,6 +54,8 @@ public class OpenaiManager { private String chatCompletionRequestTemplateStr; + private static final int DEFAULT_TIMEOUT = 30; + public OpenaiManager(ChatGPTSourceConfig sourceConfig) { initOpenAi(sourceConfig); } @@ -77,7 +79,11 @@ public ChatCompletionRequest newChatCompletionRequest(List 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; @@ -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);