Skip to content

Commit

Permalink
[ISSUE apache#4047] default timeout value is zero , not timeout .
Browse files Browse the repository at this point in the history
  • Loading branch information
JiangShuJu committed Apr 19, 2024
1 parent c849912 commit 0bffda8
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ChatGPTSourceConnectorConfig {

private int port = 3756;

private int idleTimeout = 30;
private int idleTimeout = 0;

private boolean proxyEnable = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class OpenaiConfig {

private String token;
private String model = "gpt-3.5-turbo";
private long timeout = 30;
private long timeout = 0;
private Double temperature;
private Integer maxTokens;
private Boolean logprob;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public class ChatGPTSourceConnector implements Source {
private String parsePromptTemplateStr;
private ChatHandler chatHandler;
private ParseHandler parseHandler;
private static final int DEFAULT_TIMEOUT = 30;
private static final int DEFAULT_TIMEOUT = 0;

private static final String APPLICATION_JSON = "application/json";
private static final String TEXT_PLAIN = "text/plain";


@Override
Expand Down Expand Up @@ -139,8 +142,8 @@ private void doInit() {
handleError(e, ctx);
}
});
if (sourceConfig.connectorConfig.getIdleTimeout() <= 0) {
log.warn("idleTimeout must be > 0, your config value is {}, idleTimeout will be reset {}", sourceConfig.connectorConfig.getIdleTimeout(),
if (sourceConfig.connectorConfig.getIdleTimeout() < 0) {
log.warn("idleTimeout must be >= 0, your config value is {}, idleTimeout will be reset {}", sourceConfig.connectorConfig.getIdleTimeout(),
DEFAULT_TIMEOUT);
sourceConfig.connectorConfig.setIdleTimeout(DEFAULT_TIMEOUT);
}
Expand All @@ -150,8 +153,8 @@ private void doInit() {


private void validateRequestDTO(ChatGPTRequestDTO bodyObject) {
if (bodyObject.getSubject() == null || bodyObject.getDataContentType() == null || bodyObject.getText() == null) {
throw new IllegalArgumentException("Attributes 'subject', 'datacontenttype', and 'text' cannot be null");
if (bodyObject.getSubject() == null || bodyObject.getText() == null) {
throw new IllegalArgumentException("Attributes 'subject', and 'text' cannot be null");
}
}

Expand All @@ -177,12 +180,21 @@ private void handleRequest(ChatGPTRequestDTO bodyObject, RoutingContext ctx) {
private CloudEvent invokeHandler(ChatGPTRequestType chatgptRequestType, ChatGPTRequestDTO bodyObject) {
switch (chatgptRequestType) {
case CHAT:
if (StringUtils.isBlank(bodyObject.getDataContentType())) {
bodyObject.setDataContentType(TEXT_PLAIN);
}
return chatHandler.invoke(bodyObject);
case PARSE:
if (StringUtils.isBlank(parsePromptTemplateStr)) {
throw new IllegalStateException(
"the request type of PARSE must be configured with the correct parsePromptFileName in source-config.yml");
}
if (StringUtils.isBlank(bodyObject.getFields())) {
throw new IllegalStateException("Attributes 'fields' cannot be null in PARSE");
}
if (StringUtils.isBlank(bodyObject.getDataContentType())) {
bodyObject.setDataContentType(APPLICATION_JSON);
}
return parseHandler.invoke(bodyObject);
default:
throw new IllegalStateException("the request type is illegal");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ChatGPTRequestDTO {
private String subject = "chatGPT";

@JsonProperty("datacontenttype")
private String dataContentType = "application/json";
private String dataContentType;

private String type = "cloudevents";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class OpenaiManager {

private String chatCompletionRequestTemplateStr;

private static final int DEFAULT_TIMEOUT = 30;
private static final int DEFAULT_TIMEOUT = 0;

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

private void initOpenAi(ChatGPTSourceConfig sourceConfig) {
OpenaiConfig openaiConfig = sourceConfig.getOpenaiConfig();
if (openaiConfig.getTimeout() <= 0) {
log.warn("openaiTimeout must be > 0, your config value is {}, openaiTimeout will be reset {}", openaiConfig.getTimeout(),
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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ connectorConfig:
connectorName: chatgptSource
path: /chatgpt
port: 3756
idleTimeout: 30
idleTimeout: 0
proxyEnable: false
parsePromptFileName: prompt

# https://platform.openai.com/docs/api-reference/chat/create
openaiConfig:
token:
model: gpt-3.5-turbo
timeout: 30
timeout: 0
temperature: 1
maxTokens:
frequencyPenalty: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ connectorConfig:
connectorName: chatgptSource
path: /chatgpt
port: 3756
idleTimeout: 999
idleTimeout: 0
proxyEnable: true
parsePromptFileName: prompt

# https://platform.openai.com/docs/api-reference/chat/create
openaiConfig:
token:
model: gpt-3.5-turbo
timeout: 60
timeout: 0
temperature: 1
maxTokens:
frequencyPenalty: 0
Expand Down

0 comments on commit 0bffda8

Please sign in to comment.