Skip to content

Commit

Permalink
added timeout configuratio. issue #2395
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Sep 15, 2024
1 parent 4d9b33d commit 2448fc6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion j-lawyer-fax/src/com/jdimension/jlawyer/ai/AssistantAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ You should also get your employer (if you work as a programmer) or school,
import java.util.List;
import javax.ws.rs.core.Response;
import org.apache.log4j.Logger;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.JerseyClient;
import org.glassfish.jersey.client.JerseyClientBuilder;
import org.glassfish.jersey.client.JerseyWebTarget;
Expand All @@ -694,14 +695,18 @@ public class AssistantAPI {
private String baseUri = null;
private String user = null;
private String password = null;
private int connectTimeout=5;
private int readTimeout=60;

public AssistantAPI(String baseUri, String user, String password) {
public AssistantAPI(String baseUri, String user, String password, int connectTimeout, int readTimeout) {
this.baseUri = baseUri;
if (!this.baseUri.endsWith("/")) {
this.baseUri = this.baseUri + "/";
}
this.user = user;
this.password = password;
this.connectTimeout=connectTimeout;
this.readTimeout=readTimeout;
}

private String getAuthString() {
Expand Down Expand Up @@ -738,6 +743,8 @@ public AiRequestStatus submitRequest(String requestType, String modelType, Strin
String authStringEnc = this.getAuthString();

JerseyClient restClient = (JerseyClient) JerseyClientBuilder.createClient();
restClient.property(ClientProperties.CONNECT_TIMEOUT, this.connectTimeout*1000);
restClient.property(ClientProperties.READ_TIMEOUT, this.readTimeout*1000);
JerseyWebTarget webTarget = restClient.target(baseUri + "j-lawyer-ai/request-submit");

StringBuilder jsonQuery = new StringBuilder();
Expand Down Expand Up @@ -901,6 +908,8 @@ public AiRequestStatus submitRequest(String requestType, String modelType, Strin

public List<AiCapability> getCapabilities() throws AssistantException {
JerseyClient restClient = (JerseyClient) JerseyClientBuilder.createClient();
restClient.property(ClientProperties.CONNECT_TIMEOUT, this.connectTimeout*1000);
restClient.property(ClientProperties.READ_TIMEOUT, this.readTimeout*1000);
JerseyWebTarget webTarget = restClient.target(baseUri + "j-lawyer-ai/capabilities");
List<AiCapability> allCapabilities = new ArrayList<>();
try {
Expand Down Expand Up @@ -1002,6 +1011,8 @@ public List<AiCapability> getCapabilities() throws AssistantException {

public AiResponse getRequestStatus(String requestId) throws AssistantException {
JerseyClient restClient = (JerseyClient) JerseyClientBuilder.createClient();
restClient.property(ClientProperties.CONNECT_TIMEOUT, this.connectTimeout*1000);
restClient.property(ClientProperties.READ_TIMEOUT, this.readTimeout*1000);
JerseyWebTarget webTarget = restClient.target(baseUri + "j-lawyer-ai/request-status/" + requestId);

AiResponse resp = new AiResponse();
Expand Down

0 comments on commit 2448fc6

Please sign in to comment.