Skip to content

Commit

Permalink
Refactor ShortestPathAiImpl initialization and update timeout settings.
Browse files Browse the repository at this point in the history
  • Loading branch information
backwind1233 committed Oct 22, 2024
1 parent bc6f4e7 commit 8410171
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@
<goal>deploy</goal>
</goals>
<configuration>
<libertyRuntimeVersion>23.0.0.3</libertyRuntimeVersion>
<libertyRuntimeVersion>23.0.0.9</libertyRuntimeVersion>
<outputDirectory>${project.build.directory}/wlp-package</outputDirectory>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private String getShortestPathWithTimeout(String originUnLocode, String destinat
);

try {
return future.completeOnTimeout("[]", 5, TimeUnit.SECONDS)
return future.completeOnTimeout("[]", 2, TimeUnit.MINUTES)
.get();
} catch (Exception e) {
e.printStackTrace();
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/org/eclipse/pathfinder/api/ShortestPathAiImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@

@ApplicationScoped
public class ShortestPathAiImpl implements ShortestPathAi {
private final ShortestPathAi shortestPathAi;
private static final AzureOpenAiChatModel MODEL;
private static final ShortestPathAi SHORTEST_PATH_AI;

public ShortestPathAiImpl() {
AzureOpenAiChatModel model = AzureOpenAiChatModel.builder()
static {
MODEL = AzureOpenAiChatModel.builder()
.apiKey(System.getenv("AZURE_OPENAI_KEY"))
.endpoint(System.getenv("AZURE_OPENAI_ENDPOINT"))
.deploymentName(System.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"))
.temperature(0.2)
.logRequestsAndResponses(true)
.build();

// Create AI service
this.shortestPathAi = AiServices.builder(ShortestPathAi.class)
.chatLanguageModel(model)
SHORTEST_PATH_AI = AiServices.builder(ShortestPathAi.class)
.chatLanguageModel(MODEL)
.build();
}

public ShortestPathAiImpl() {
// Empty constructor
}

@Override
public String chat(String location,String voyage, String carrier_movement, String from,String to) {
return shortestPathAi.chat(location, voyage, carrier_movement, from, to);
public String chat(String location, String voyage, String carrier_movement, String from, String to) {
return SHORTEST_PATH_AI.chat(location, voyage, carrier_movement, from, to);
}
}

0 comments on commit 8410171

Please sign in to comment.