-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f67c3b
commit f0d6c64
Showing
16 changed files
with
5,888 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
dotCMS/src/main/java/com/dotcms/ai/api/AsyncEmbeddingsCallStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.dotcms.ai.api; | ||
|
||
import com.dotcms.ai.rest.forms.EmbeddingsForm; | ||
import com.dotcms.ai.util.OpenAIThreadPool; | ||
import com.dotmarketing.portlets.contentlet.model.Contentlet; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* The AsyncEmbeddingsCallStrategy class is responsible for embedding contentlets in an asynchronous manner. | ||
* | ||
* @author vico | ||
*/ | ||
public class AsyncEmbeddingsCallStrategy implements EmbeddingsCallStrategy { | ||
|
||
@Override | ||
public void bulkEmbed(final List<String> inodes, final EmbeddingsForm embeddingsForm) { | ||
OpenAIThreadPool.submit(new BulkEmbeddingsRunner(inodes, embeddingsForm)); | ||
} | ||
|
||
@Override | ||
public void embed(final EmbeddingsAPIImpl embeddingsAPI, | ||
final Contentlet contentlet, | ||
final String content, | ||
final String indexName) { | ||
OpenAIThreadPool.submit(new EmbeddingsRunner(embeddingsAPI, contentlet, content, indexName)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
dotCMS/src/main/java/com/dotcms/ai/api/EmbeddingsCallStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.dotcms.ai.api; | ||
|
||
import com.dotcms.ai.rest.forms.EmbeddingsForm; | ||
import com.dotmarketing.portlets.contentlet.model.Contentlet; | ||
import com.dotmarketing.util.ConfigUtils; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* The EmbeddingsCallStrategy interface defines the contract for embedding strategies. | ||
* Implementations of this interface will provide different ways to handle the embedding of contentlets. | ||
* | ||
* The embed method takes a list of inodes and an EmbeddingsForm object, and performs the embedding operation. | ||
* The specifics of how the embedding is done depends on the implementation. | ||
* | ||
* @author Your Name | ||
*/ | ||
public interface EmbeddingsCallStrategy { | ||
|
||
/** | ||
* Embeds contentlets based on the provided inodes and form data. | ||
* | ||
* @param inodes the list of inodes representing the contentlets to be embedded | ||
* @param embeddingsForm the form data containing the details for the embedding operation | ||
*/ | ||
void bulkEmbed(List<String> inodes, EmbeddingsForm embeddingsForm); | ||
|
||
/** | ||
* Embeds the content of a contentlet. | ||
* | ||
* @param embeddingsAPI the EmbeddingsAPIImpl instance to use | ||
* @param contentlet the contentlet to embed | ||
* @param content the content to embed | ||
* @param indexName the index name to use | ||
*/ | ||
void embed(EmbeddingsAPIImpl embeddingsAPI, Contentlet contentlet, String content, String indexName); | ||
|
||
/** | ||
* Resolves the appropriate embedding strategy based on the current environment. | ||
* | ||
* @return the EmbeddingsCallStrategy implementation to use | ||
*/ | ||
static EmbeddingsCallStrategy resolveStrategy() { | ||
return ConfigUtils.isDevMode() ? new SyncEmbeddingsCallStrategy() : new AsyncEmbeddingsCallStrategy(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
dotCMS/src/main/java/com/dotcms/ai/api/SyncEmbeddingsCallStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.dotcms.ai.api; | ||
|
||
import com.dotcms.ai.rest.forms.EmbeddingsForm; | ||
import com.dotmarketing.portlets.contentlet.model.Contentlet; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* The SyncEmbeddingsCallStrategy class is responsible for embedding contentlets in a synchronous manner. | ||
* | ||
* @author vico | ||
*/ | ||
public class SyncEmbeddingsCallStrategy implements EmbeddingsCallStrategy { | ||
|
||
@Override | ||
public void bulkEmbed(final List<String> inodes, final EmbeddingsForm embeddingsForm) { | ||
new BulkEmbeddingsRunner(inodes, embeddingsForm).run(); | ||
} | ||
|
||
@Override | ||
public void embed(final EmbeddingsAPIImpl embeddingsAPI, | ||
final Contentlet contentlet, | ||
final String content, | ||
final String indexName) { | ||
new EmbeddingsRunner(embeddingsAPI, contentlet, content, indexName).run(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.