AiModel

AiModel class

An abstract class representing the integration with various AI models within the Aspose.Words.

public abstract class AiModel

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).
abstract Url { get; set; }Gets or sets a URL of the model. The default value is specific for the model.

Methods

NameDescription
static Create(AiModelType)Creates a new instance of AiModel class.
virtual CheckGrammar(DocumentCheckGrammarOptions)Checks grammar of the provided document. This operation leverages the connected AI model for checking grammar of document.
abstract Summarize(DocumentSummarizeOptions)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.
abstract Summarize(Document[], SummarizeOptions)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.
abstract Translate(DocumentLanguage)Translates the provided document into the specified target language. This operation leverages the connected AI model for content translating.
WithApiKey(string)Sets a specified API key to the model.

Examples

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