AiModel class
AiModel class
An abstract class representing the integration with various AI models within the Aspose.Words.
Methods
Name | Description |
---|---|
asAnthropicAiModel() | Cast AiModel to AnthropicAiModel. |
asGoogleAiModel() | Cast AiModel to GoogleAiModel. |
asOpenAiModel() | Cast AiModel to OpenAiModel. |
checkGrammar(sourceDocument, options) | Checks grammar of the provided document. This operation leverages the connected AI model for checking grammar of document. |
create(modelType) | Creates a new instance of AiModel class. |
createClaude35Haiku() | |
createClaude35Sonnet() | |
createClaude3Haiku() | |
createClaude3Opus() | |
createClaude3Sonnet() | |
createGemini15Flash() | |
createGemini15Flash8B() | |
createGemini15Pro() | |
createGpt35Turbo() | |
createGpt4O() | |
createGpt4OMini() | |
createGpt4Turbo() | |
setApiKey(apiKey) | Sets a specified API key to the model. |
summarize(sourceDocument, 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. |
summarize(sourceDocuments, 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. |
translate(sourceDocument, targetLanguage) | Translates the provided document into the specified target language. This operation leverages the connected AI model for content translating. |
Examples
Shows how to summarize text using OpenAI and Google models.
let firstDoc = new aw.Document(base.myDir + "Big document.docx");
let secondDoc = new aw.Document(base.myDir + "Document.docx");
const apiKey = process.env.API_KEY;
if (!apiKey) {
console.warn("API_KEY environment variable is not set.");
return;
}
// Use OpenAI or Google generative language models.
let model = aw.AI.AiModel.createGpt4OMini();
model.setApiKey(apiKey);
model.setOrganization("Organization");
model.setProject("Project");
let options = new aw.AI.SummarizeOptions();
options.summaryLength = aw.AI.SummaryLength.Short;
let oneDocumentSummary = model.summarize(firstDoc, options);
oneDocumentSummary.save(base.artifactsDir + "AI.AiSummarize.one.docx");
options.summaryLength = aw.AI.SummaryLength.Long;
let multiDocumentSummary = model.summarize([firstDoc, secondDoc], options);
multiDocumentSummary.save(base.artifactsDir + "AI.AiSummarize.multi.docx");
See Also
- module Aspose.Words.AI