AiModel

Inheritance: java.lang.Object

public abstract class AiModel

Represents information about a Generative Language Model.

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");
 

Constructors

ConstructorDescription
AiModel()

Methods

MethodDescription
create(int modelType)
withApiKey(String apiKey)Sets a specified API key to the model.

AiModel()

public AiModel()

create(int modelType)

public static AiModel create(int modelType)

Parameters:

ParameterTypeDescription
modelTypeint

Returns: AiModel

withApiKey(String apiKey)

public AiModel withApiKey(String apiKey)

Sets a specified API key to the model.

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
apiKeyjava.lang.String

Returns: AiModel