IAiModelText

public interface IAiModelText

The common interface for AI models designed to generate a variety of text-based content.

Examples:

Shows how to summarize text using OpenAI and Google models.


 Document firstDoc = new Document(getMyDir() + "Big document.docx");
 Document secondDoc = new Document(getMyDir() + "Document.docx");

 String apiKey = System.getenv("API_KEY");
 // Use OpenAI or Google generative language models.
 IAiModelText model = (IAiModelText) AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);

 SummarizeOptions options = new SummarizeOptions();
 options.setSummaryLength(SummaryLength.SHORT);
 Document oneDocumentSummary = model.summarize(firstDoc, options);
 oneDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.One.docx");

 options = new SummarizeOptions();
 options.setSummaryLength(SummaryLength.LONG);
 Document multiDocumentSummary = model.summarize(new Document[] { firstDoc, secondDoc }, options);
 multiDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.Multi.docx");
 

Methods

MethodDescription
summarize(Document sourceDocument, SummarizeOptions options)Generates a summary of the specified document, with options to adjust the length of the summary.
summarize(Document[] sourceDocuments, SummarizeOptions options)Generates summaries for an array of documents, with options to control the summary length and other settings.
translate(Document sourceDocument, int targetLanguage)

summarize(Document sourceDocument, SummarizeOptions options)

public abstract Document summarize(Document sourceDocument, SummarizeOptions options)

Generates a summary of the specified document, with options to adjust the length of the summary. This operation leverages the connected AI model for content processing.

Examples:

Shows how to summarize text using OpenAI and Google models.


 Document firstDoc = new Document(getMyDir() + "Big document.docx");
 Document secondDoc = new Document(getMyDir() + "Document.docx");

 String apiKey = System.getenv("API_KEY");
 // Use OpenAI or Google generative language models.
 IAiModelText model = (IAiModelText) AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);

 SummarizeOptions options = new SummarizeOptions();
 options.setSummaryLength(SummaryLength.SHORT);
 Document oneDocumentSummary = model.summarize(firstDoc, options);
 oneDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.One.docx");

 options = new SummarizeOptions();
 options.setSummaryLength(SummaryLength.LONG);
 Document multiDocumentSummary = model.summarize(new Document[] { firstDoc, secondDoc }, options);
 multiDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.Multi.docx");
 

Parameters:

ParameterTypeDescription
sourceDocumentDocumentThe document to be summarized.
optionsSummarizeOptionsOptional settings to control the summary length and other parameters.

Returns: Document - A summarized version of the document’s content.

summarize(Document[] sourceDocuments, SummarizeOptions options)

public abstract Document summarize(Document[] sourceDocuments, SummarizeOptions options)

Generates summaries for an array of documents, with options to control the summary length and other settings. This method utilizes the connected AI model for processing each document in the array.

Examples:

Shows how to summarize text using OpenAI and Google models.


 Document firstDoc = new Document(getMyDir() + "Big document.docx");
 Document secondDoc = new Document(getMyDir() + "Document.docx");

 String apiKey = System.getenv("API_KEY");
 // Use OpenAI or Google generative language models.
 IAiModelText model = (IAiModelText) AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);

 SummarizeOptions options = new SummarizeOptions();
 options.setSummaryLength(SummaryLength.SHORT);
 Document oneDocumentSummary = model.summarize(firstDoc, options);
 oneDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.One.docx");

 options = new SummarizeOptions();
 options.setSummaryLength(SummaryLength.LONG);
 Document multiDocumentSummary = model.summarize(new Document[] { firstDoc, secondDoc }, options);
 multiDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.Multi.docx");
 

Parameters:

ParameterTypeDescription
sourceDocumentsDocument[]An array of documents to be summarized.
optionsSummarizeOptionsOptional settings to control the summary length and other parameters

Returns: Document - A summarized version of the document’s content.

translate(Document sourceDocument, int targetLanguage)

public abstract Document translate(Document sourceDocument, int targetLanguage)

Parameters:

ParameterTypeDescription
sourceDocumentDocument
targetLanguageint

Returns: Document