Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.dotcms.ai.exception.DotAIModelNotFoundException;
import com.dotcms.ai.rest.forms.CompletionsForm;
import com.dotcms.ai.util.EncodingUtil;
import com.dotcms.analytics.Util;
import com.dotcms.api.web.HttpServletRequestThreadLocal;
import com.dotcms.mock.request.FakeHttpRequest;
import com.dotcms.mock.response.BaseResponse;
Expand Down
1 change: 1 addition & 0 deletions dotCMS/src/main/java/com/dotcms/ai/app/AppKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

public enum AppKeys {

ADVANCE_PROVIDER_SETTINGS_KEY("advanceProviderSettings", null),
API_KEY("apiKey", null),
API_URL("apiUrl", "https://api.openai.com/v1/chat/completions"),
API_IMAGE_URL("apiImageUrl", "https://api.openai.com/v1/images/generations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
import com.dotcms.ai.exception.DotAIClientConnectException;
import com.dotcms.ai.exception.DotAIModelNotFoundException;
import com.dotcms.ai.exception.DotAIModelNotOperationalException;
import com.dotcms.business.SystemTableUpdatedKeyEvent;
import com.dotcms.http.CircuitBreakerUrl;
import com.dotcms.rest.exception.GenericHttpStatusCodeException;
import com.dotcms.system.event.local.model.EventSubscriber;
import com.dotmarketing.util.Config;
import com.dotmarketing.util.Logger;
import com.dotmarketing.util.json.JSONObject;
Expand All @@ -29,8 +27,6 @@
import java.io.OutputStream;
import java.io.Serializable;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

/**
* Implementation of the {@link AIClient} interface for interacting with the OpenAI service.
Expand Down
40 changes: 40 additions & 0 deletions dotCMS/src/main/java/com/dotcms/ai/config/AiModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.dotcms.ai.config;

import java.util.Map;

/**
* Model encapsulates a default configuration for known models, however the Models still able to be created dynamically
* @author jsanca
*/
public enum AiModel {

OPEN_AI_GPT_4O_MINI(AiVendor.OPEN_AI, "gpt-4o-mini", "https://api.openai.com/v1"),
OPEN_AI_TEXT_EMBEDDING_3_SMALL(AiVendor.OPEN_AI, "text-embedding-3-small", "https://api.openai.com/v1"),
ANTHROPIC_CLAUDE_3_7(AiVendor.ANTHROPIC, "claude-3-7-sonnet-20250219", "https://api.openai.com/v1");

private final AiVendor vendor;
private final String model;
private final String apiUrl;

AiModel(final AiVendor vendor, final String model, final String apiUrl) {
this.vendor = vendor;
this.model = model;
this.apiUrl = apiUrl;
}

public AiVendor getVendor() { return vendor; }
public String getModel() { return model; }
public String getApiUrl() { return apiUrl; }
public String getProviderName() {
return vendor.getVendorName() + "/" + model;
}

public AiModelConfig toConfig(final String apiKey) {

return new AiModelConfig(this.model,
Map.of(AiModelConfig.API_KEY, apiKey,
AiModelConfig.VENDOR, vendor.getVendorName(),
AiModelConfig.MODEL, model,
AiModelConfig.API_URL, apiUrl));
}
}
47 changes: 47 additions & 0 deletions dotCMS/src/main/java/com/dotcms/ai/config/AiModelConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.dotcms.ai.config;

import java.util.Map;

/**
* Encapsulates the Configuration for a model
* @author jsanca
*/
public class AiModelConfig {

public static final String API_KEY = "key";
public static final String VENDOR = "vendor";
public static final String MODEL = "model";
public static final String API_URL = "apiUrl";

private final String name;
private final Map<String, String> config;

public AiModelConfig(final String name, final Map<String, String> config) {
this.name = name;
this.config = config;
}

public String getName() {
return name;
}

public String get(final String key) {
return config.get(key);
}

public String getOrDefault(final String key, final String defaultValue) {
return config.getOrDefault(key, defaultValue);
}

public Map<String, String> asMap() {
return Map.copyOf(config);
}

@Override
public String toString() {
return "AiModelConfig{" +
"name='" + name + '\'' +
", config=" + config +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.dotcms.ai.config;

import java.util.List;

/**
* Model Config Catalog
* Returns the ModelConfig for Chat and Embeddings based on vendor and model
* @author jsanca
*/
public interface AiModelConfigCatalog {

/**
* Gets the default chat config based on the vendor
* @param vendor
* @return
*/
AiModelConfig getChatConfig(AiVendor vendor);

/**
* Get the default chat config based on the vendor
* @param vendor
* @return
*/
AiModelConfig getChatConfig(String vendor);

/**
* Gets the chat config model for vendor and modelKey
* @param vendor
* @param modelKey
* @return
*/
AiModelConfig getChatConfig(String vendor, String modelKey);

/**
* Get the default embeddings model for this vendor
* @param vendor
* @return
*/
AiModelConfig getEmbeddingsConfig(String vendor);

/**
* Gets an embedding model config based on vendor and model key
* @param vendor
* @param modelKey
* @return
*/
AiModelConfig getEmbeddingsConfig(String vendor, String modelKey);

/**
* Return a model config based on a path such as
* "openai.chat.gpt-4o-mini" / "openai.embeddings.text-embedding-3-small"
* @param path
* @return
*/
AiModelConfig getByPath(String path);

/**
* Return all the chat models
* @param vendorName
* @return
*/
List<String> getChatModelNames(String vendorName);

/**
* Return all the vendors name
* @return
*/
List<String> getVendorNames();
}
Loading