GoogleAiModel

Inheritance: java.lang.Object, com.aspose.words.AiModel

All Implemented Interfaces: com.aspose.words.IAiModelText

public abstract class GoogleAiModel extends AiModel implements IAiModelText

An abstract class representing the integration with Google\u2019s AI models within the Aspose.Words.

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.
 AiModel model = ((OpenAiModel)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey)).withOrganization("Organization").withProject("Project");

 SummarizeOptions options = new SummarizeOptions();

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

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

Constructors

ConstructorDescription
GoogleAiModel()

Methods

MethodDescription
checkGrammar(Document sourceDocument, CheckGrammarOptions options)Checks grammar of the provided document.
create(int modelType)
summarize(Document doc)
summarize(Document doc, SummarizeOptions options)Summarizes specified Document object.
summarize(Document[] docs)
summarize(Document[] docs, SummarizeOptions options)Summarizes specified Document objects.
translate(Document doc, int language)
withApiKey(String apiKey)Sets a specified API key to the model.

GoogleAiModel()

public GoogleAiModel()

checkGrammar(Document sourceDocument, CheckGrammarOptions options)

public Document checkGrammar(Document sourceDocument, CheckGrammarOptions options)

Checks grammar of the provided document. This operation leverages the connected AI model for checking grammar of document.

Examples:

Shows how to check the grammar of a document.


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

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

 CheckGrammarOptions grammarOptions = new CheckGrammarOptions();
 grammarOptions.setImproveStylistics(true);

 Document proofedDoc = model.checkGrammar(doc, grammarOptions);
 proofedDoc.save(getArtifactsDir() + "AI.AiGrammar.docx");
 

Parameters:

ParameterTypeDescription
sourceDocumentDocumentThe document being checked for grammar.
optionsCheckGrammarOptionsOptional settings to control how grammar will be checked.

Returns: Document - A new Document with checked grammar.

create(int modelType)

public static AiModel create(int modelType)

Parameters:

ParameterTypeDescription
modelTypeint

Returns: AiModel

summarize(Document doc)

public Document summarize(Document doc)

Parameters:

ParameterTypeDescription
docDocument

Returns: Document

summarize(Document doc, SummarizeOptions options)

public Document summarize(Document doc, SummarizeOptions options)

Summarizes specified Document object.

Parameters:

ParameterTypeDescription
docDocument
optionsSummarizeOptions

Returns: Document

summarize(Document[] docs)

public Document summarize(Document[] docs)

Parameters:

ParameterTypeDescription
docsDocument[]

Returns: Document

summarize(Document[] docs, SummarizeOptions options)

public Document summarize(Document[] docs, SummarizeOptions options)

Summarizes specified Document objects.

Parameters:

ParameterTypeDescription
docsDocument[]
optionsSummarizeOptions

Returns: Document

translate(Document doc, int language)

public Document translate(Document doc, int language)

Parameters:

ParameterTypeDescription
docDocument
languageint

Returns: Document

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.
 AiModel model = ((OpenAiModel)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey)).withOrganization("Organization").withProject("Project");

 SummarizeOptions options = new SummarizeOptions();

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

 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