Skip to content

Commit

Permalink
add a constructor function
Browse files Browse the repository at this point in the history
  • Loading branch information
lhpqaq committed Aug 28, 2024
1 parent e8bfd1e commit b4da0dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,11 @@ public class PlatformAuthorizedDTO {
private String baseUrl;
private String model;
private Map<String, String> credentials;

public PlatformAuthorizedDTO(String name, Map<String, String> credentialSet, String apiUrl, String model) {
this.platformName = name;
this.credentials = credentialSet;
this.baseUrl = apiUrl;
this.model = model;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private Boolean testAuthorization(PlatformAuthorizedDTO platformAuthorizedDTO) {
return false;
}
try {
aiAssistant.ask("Answer one word.");
aiAssistant.ask("1+1=");
} catch (Exception e) {
throw new ApiException(ApiExceptionEnum.CREDIT_INCORRECT, e.getMessage());
}
Expand Down Expand Up @@ -167,12 +167,12 @@ public PlatformAuthorizedVO addAuthorizedPlatform(PlatformDTO platformDTO) {
}
credentialSet.put(key, credentialGet.get(key));
}

PlatformAuthorizedDTO platformAuthorizedDTO = new PlatformAuthorizedDTO();
platformAuthorizedDTO.setPlatformName(platformPO.getName());
platformAuthorizedDTO.setCredentials(credentialSet);
platformAuthorizedDTO.setBaseUrl(platformPO.getApiUrl());
platformAuthorizedDTO.setModel(platformPO.getSupportModels().split(",")[0]);
List<String> models = List.of(platformPO.getSupportModels().split(","));
if (models.isEmpty()) {
throw new ApiException(ApiExceptionEnum.MODEL_NOT_SUPPORTED);
}
PlatformAuthorizedDTO platformAuthorizedDTO =
new PlatformAuthorizedDTO(platformPO.getName(), credentialSet, platformPO.getApiUrl(), models.get(0));

if (!testAuthorization(platformAuthorizedDTO)) {
throw new ApiException(ApiExceptionEnum.PLATFORM_NOT_FOUND);
Expand Down Expand Up @@ -301,11 +301,11 @@ public SseEmitter talk(Long platformId, Long threadId, String message) {
.findById(platformAuthorizedPO.getPlatformPO().getId())
.orElseThrow(() -> new ApiException(ApiExceptionEnum.PLATFORM_NOT_FOUND));

PlatformAuthorizedDTO platformAuthorizedDTO = new PlatformAuthorizedDTO();
platformAuthorizedDTO.setPlatformName(platformPO.getName());
platformAuthorizedDTO.setCredentials(platformAuthorizedPO.getCredentials());
platformAuthorizedDTO.setBaseUrl(platformPO.getApiUrl());
platformAuthorizedDTO.setModel(chatThreadPO.getModel());
PlatformAuthorizedDTO platformAuthorizedDTO = new PlatformAuthorizedDTO(
platformPO.getName(),
platformAuthorizedPO.getCredentials(),
platformPO.getApiUrl(),
chatThreadPO.getModel());
AIAssistant aiAssistant = buildAIAssistant(platformAuthorizedDTO, chatThreadPO.getId());
if (aiAssistant == null) {
throw new ApiException(ApiExceptionEnum.CREDIT_INCORRECT);
Expand Down

0 comments on commit b4da0dd

Please sign in to comment.