GoogleAiModel

GoogleAiModel class

Class representing Google AI Models (Gemini) integration within Aspose.Words.

public class GoogleAiModel : AiModel

Constructors

NameDescription
GoogleAiModel(string)Initializes a new instance of GoogleAiModel class.
GoogleAiModel(string, string)Initializes a new instance of GoogleAiModel class.

Properties

NameDescription
Timeout { get; set; }Gets or sets the number of milliseconds to wait before the request to AI model times out. The default value is 100,000 milliseconds (100 seconds).
override Url { get; set; }Gets or sets a URL of the model. The default value is “https://generativelanguage.googleapis.com/v1beta/models/".

Methods

NameDescription
virtual CheckGrammar(DocumentCheckGrammarOptions)Checks grammar of the provided document. This operation leverages the connected AI model for checking grammar of document.
override Summarize(DocumentSummarizeOptions)Summarizes specified Document object.
override Summarize(Document[], SummarizeOptions)Summarizes specified Document objects.
override Translate(DocumentLanguage)Translates a specified document.
WithApiKey(string)Sets a specified API key to the model.

Remarks

Please refer to https://ai.google.dev/gemini-api/docs/models for Gemini models details.

Examples

Shows how to use google AI model.

string apiKey = Environment.GetEnvironmentVariable("API_KEY");
GoogleAiModel model = new GoogleAiModel("gemini-flash-latest", apiKey);

Document doc = new Document(MyDir + "Big document.docx");
SummarizeOptions summarizeOptions = new SummarizeOptions() { SummaryLength = SummaryLength.VeryShort };
Document summary = model.Summarize(doc, summarizeOptions);

Shows how to summarize text using OpenAI and Google models.

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

string apiKey = Environment.GetEnvironmentVariable("API_KEY");
// Use OpenAI or Google generative language models.
AiModel model = ((OpenAiModel)AiModel.Create(AiModelType.Gpt4OMini).WithApiKey(apiKey)).WithOrganization("Organization").WithProject("Project");

SummarizeOptions options = new SummarizeOptions();

options.SummaryLength = SummaryLength.Short;
Document oneDocumentSummary = model.Summarize(firstDoc, options);
oneDocumentSummary.Save(ArtifactsDir + "AI.AiSummarize.One.docx");

options.SummaryLength = SummaryLength.Long;
Document multiDocumentSummary = model.Summarize(new Document[] { firstDoc, secondDoc }, options);
multiDocumentSummary.Save(ArtifactsDir + "AI.AiSummarize.Multi.docx");

See Also