in server/src/main/java/com/epam/aidial/core/server/service/ApplicationService.java [425:492]
private void prepareApplication(ResourceDescriptor resource, Application application) {
verifyApplication(resource);
if (application.getApplicationTypeSchemaId() != null) {
if (application.getEndpoint() != null || application.getFunction() != null) {
throw new IllegalArgumentException("Endpoint must not be set for custom application");
}
} else if (application.getEndpoint() == null && application.getFunction() == null) {
throw new IllegalArgumentException("Application endpoint or function must be provided");
}
application.setName(resource.getUrl());
application.setUserRoles(null);
application.setForwardAuthToken(false);
if (application.getReference() == null) {
application.setReference(ApplicationUtil.generateReference());
}
Application.Function function = application.getFunction();
if (function != null) {
if (application.getFeatures() == null) {
application.setFeatures(new Features());
}
application.setEndpoint(null);
application.getFeatures().setRateEndpoint(null);
application.getFeatures().setTokenizeEndpoint(null);
application.getFeatures().setTruncatePromptEndpoint(null);
application.getFeatures().setConfigurationEndpoint(null);
function.setAuthorBucket(resource.getBucketName());
function.setError(null);
if (function.getRuntime() == null) {
throw new IllegalArgumentException("Application function runtime must be provided");
}
if (function.getEnv() == null) {
function.setEnv(Map.of());
}
if (function.getMapping() == null) {
throw new IllegalArgumentException("Application function mapping must be provided");
}
verifyMapping(function.getMapping().getChatCompletion(), true, "Application chat_completion mapping is missing/invalid");
verifyMapping(function.getMapping().getRate(), false, "Application rate mapping is invalid");
verifyMapping(function.getMapping().getTokenize(), false, "Application tokenize mapping is invalid");
verifyMapping(function.getMapping().getTruncatePrompt(), false, "Application truncate_prompt mapping is invalid");
verifyMapping(function.getMapping().getConfiguration(), false, "Application configuration mapping is invalid");
if (function.getSourceFolder() == null) {
throw new IllegalArgumentException("Application function source folder must be provided");
}
try {
ResourceDescriptor folder = ResourceDescriptorFactory.fromAnyUrl(function.getSourceFolder(), encryptionService);
if (!folder.isFolder() || folder.getType() != ResourceTypes.FILE || !folder.getBucketName().equals(resource.getBucketName())) {
throw new IllegalArgumentException();
}
function.setSourceFolder(folder.getUrl());
} catch (Throwable e) {
throw new IllegalArgumentException("Application function sources must be a valid file folder: " + function.getSourceFolder());
}
}
}