Skip to content

Commit

Permalink
#29284: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralfaro-dotcms committed Jul 31, 2024
1 parent da61861 commit c3c6717
Show file tree
Hide file tree
Showing 38 changed files with 259 additions and 39 deletions.
13 changes: 13 additions & 0 deletions dotCMS/src/main/java/com/dotcms/ai/api/AIClientAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.dotcms.ai.api;

import com.dotcms.ai.model.request.AIRequest;

import java.io.OutputStream;

public interface AIClientAPI {

void sendRequest(final AIRequest request, final OutputStream output);

void sendRequest(final AIRequest request);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.dotcms.ai.app;
package com.dotcms.ai.api;

import com.dotcms.ai.app.AIModelType;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.model.AIModel;
import com.dotcms.ai.model.OpenAIModel;
import com.dotcms.ai.model.OpenAIModels;
import com.dotcms.http.CircuitBreakerUrl;
Expand Down
21 changes: 21 additions & 0 deletions dotCMS/src/main/java/com/dotcms/ai/api/AIServices.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.dotcms.ai.api;

import com.dotcms.ai.model.AIProvider;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

public class AIServices {

private final ConcurrentMap<AIProvider, List<AIClientAPI>> clients = new ConcurrentHashMap();

public List<AIProvider> getProviders() {
return List.of();
}

public List<AIClientAPI> getClients(final List<AIProvider> providers) {
return List.of();
}

}
2 changes: 1 addition & 1 deletion dotCMS/src/main/java/com/dotcms/ai/api/CompletionsAPI.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dotcms.ai.api;

import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.rest.forms.CompletionsForm;
import com.dotmarketing.util.json.JSONObject;
import io.vavr.Lazy;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.dotcms.ai.api;

import com.dotcms.ai.AiKeys;
import com.dotcms.ai.app.AIModel;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.model.AIModel;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.db.EmbeddingsDTO;
Expand Down
4 changes: 2 additions & 2 deletions dotCMS/src/main/java/com/dotcms/ai/api/EmbeddingsAPIImpl.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dotcms.ai.api;

import com.dotcms.ai.AiKeys;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.db.EmbeddingsDTO;
Expand Down Expand Up @@ -54,7 +54,7 @@
import java.util.Optional;
import java.util.stream.Collectors;

import static com.dotcms.ai.app.AppConfig.debugLogger;
import static com.dotcms.ai.config.AppConfig.debugLogger;
import static com.liferay.util.StringPool.BLANK;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;
import java.util.Locale;

import static com.dotcms.ai.app.AppConfig.debugLogger;
import static com.dotcms.ai.config.AppConfig.debugLogger;
import static com.liferay.util.StringPool.SPACE;

/**
Expand Down
1 change: 1 addition & 0 deletions dotCMS/src/main/java/com/dotcms/ai/app/ConfigService.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotcms.ai.app;

import com.dotcms.ai.config.AppConfig;
import com.dotcms.api.web.HttpServletRequestThreadLocal;
import com.dotcms.security.apps.AppSecrets;
import com.dotmarketing.beans.Host;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package com.dotcms.ai.app;

package com.dotcms.ai.config;

import com.dotcms.ai.api.AIModels;
import com.dotcms.ai.app.AIModelType;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.model.AIModel;
import com.dotcms.ai.util.AIAppUtil;
import com.dotcms.security.apps.Secret;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.util.Config;
Expand Down
39 changes: 39 additions & 0 deletions dotCMS/src/main/java/com/dotcms/ai/config/ProviderConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dotcms.ai.config;

import com.dotcms.ai.model.AIProvider;

import java.util.Objects;

public class ProviderConfig {

private final AIProvider provider;

public ProviderConfig(final AIProvider provider) {
this.provider = provider;
}

public AIProvider getProvider() {
return provider;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ProviderConfig that = (ProviderConfig) o;
return provider == that.provider;
}

@Override
public int hashCode() {
return Objects.hashCode(provider);
}

@Override
public String toString() {
return "ProviderConfig{" +
"provider=" + provider +
'}';
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dotcms.ai.listener;

import com.dotcms.ai.app.AIModels;
import com.dotcms.ai.api.AIModels;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.security.apps.AppSecretSavedEvent;
import com.dotcms.system.event.local.model.EventSubscriber;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dotcms.ai.listener;

import com.dotcms.ai.api.EmbeddingsAPI;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.db.EmbeddingsDTO;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dotcms.ai.app;
package com.dotcms.ai.model;

import com.dotcms.ai.app.AIModelType;
import com.dotcms.util.DotPreconditions;
import com.dotmarketing.util.Logger;

Expand Down
27 changes: 27 additions & 0 deletions dotCMS/src/main/java/com/dotcms/ai/model/AIProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.dotcms.ai.model;

import com.dotmarketing.util.Config;

public enum AIProvider {

OPEN_AI("OpenAI"),
AMAZON_BEDROCK("Bedrock"),
GOOGLE_GEMINI("Gemini"),;

private final String provider;
private final boolean enabled;

AIProvider(final String provider) {
this.provider = provider;
enabled = Config.getBooleanProperty("AI_PROVIDER_" + provider.toUpperCase() + "_ENABLED", false);
}

public String getProvider() {
return provider;
}

public boolean isEnabled() {
return enabled;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.dotcms.ai.model.request;

import com.dotcms.ai.config.AppConfig;
import com.dotmarketing.util.json.JSONObject;

public class AIJSONObjectRequest extends AIRequest<JSONObject> {

public AIJSONObjectRequest(final String url,
final String method,
final AppConfig appConfig,
final JSONObject payload) {
super(url, method, appConfig, payload);
}

}
87 changes: 87 additions & 0 deletions dotCMS/src/main/java/com/dotcms/ai/model/request/AIRequest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.dotcms.ai.model.request;

import com.dotcms.ai.config.AppConfig;

import java.io.Serializable;

public class AIRequest<T extends Serializable> {

private final String url;
private final String method;
private final AppConfig appConfig;
private final T payload;

AIRequest(final String url,
final String method,
final AppConfig appConfig,
final T payload) {
this.url = url;
this.method = method;
this.appConfig = appConfig;
this.payload = payload;
}

public String getUrl() {
return url;
}

public String getMethod() {
return method;
}

public AppConfig getAppConfig() {
return appConfig;
}

public T getPayload() {
return payload;
}

@Override
public String toString() {
return "AIRequest{" +
"url='" + url + '\'' +
", method='" + method + '\'' +
", appConfig=" + appConfig +
", payload=" + payload +
'}';
}

static <T extends Serializable> Builder<T> builder() {
return new Builder<>();
}

private static class Builder<T extends Serializable> {

private String url;
private String method;
private AppConfig appConfig;
private T payload;

public Builder url(final String url) {
this.url = url;
return this;
}

public Builder method(final String method) {
this.method = method;
return this;
}

public Builder appConfig(final AppConfig appConfig) {
this.appConfig = appConfig;
return this;
}

public Builder payload(final T payload) {
this.payload = payload;
return this;
}

public AIRequest build() {
return new AIRequest(url, method, appConfig, payload);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import com.dotcms.ai.AiKeys;
import com.dotcms.ai.api.CompletionsAPI;
import com.dotcms.ai.app.AIModels;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.api.AIModels;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.rest.forms.CompletionsForm;
Expand Down
2 changes: 1 addition & 1 deletion dotCMS/src/main/java/com/dotcms/ai/rest/ImageResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.dotcms.ai.AiKeys;
import com.dotcms.ai.Marshaller;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.model.AIImageRequestDTO;
import com.dotcms.ai.service.OpenAIImageService;
Expand Down
2 changes: 1 addition & 1 deletion dotCMS/src/main/java/com/dotcms/ai/rest/TextResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.dotcms.ai.AiKeys;
import com.dotcms.ai.api.CompletionsAPI;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.ConfigService;
import com.dotcms.ai.rest.forms.CompletionsForm;
import com.dotcms.rest.WebResource;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.dotcms.ai.rest.forms;

import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.app.ConfigService;
import com.dotmarketing.business.APILocator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.dotcms.ai.rest.forms;

import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.ConfigService;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.util.UtilMethods;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dotcms.ai.service;

import com.dotcms.ai.AiKeys;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.util.OpenAIRequest;
import com.dotmarketing.util.UtilMethods;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.dotcms.ai.service;

import com.dotcms.ai.AiKeys;
import com.dotcms.ai.app.AppConfig;
import com.dotcms.ai.config.AppConfig;
import com.dotcms.ai.model.AIImageRequestDTO;
import com.dotcms.ai.util.OpenAIRequest;
import com.dotcms.ai.util.OpenAiRequestUtil;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.dotcms.ai.app;
package com.dotcms.ai.util;

import com.dotcms.ai.app.AIModelType;
import com.dotcms.ai.app.AppKeys;
import com.dotcms.ai.model.AIModel;
import com.dotcms.security.apps.AppsUtil;
import com.dotcms.security.apps.Secret;
import com.dotmarketing.util.UtilMethods;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static com.dotcms.ai.app.AppConfig.debugLogger;
import static com.dotcms.ai.config.AppConfig.debugLogger;
import static com.liferay.util.StringPool.BLANK;
import static com.liferay.util.StringPool.SPACE;

Expand Down
Loading

0 comments on commit c3c6717

Please sign in to comment.