OpenAiModel class

OpenAiModel class

An abstract class representing the integration with OpenAI’s large language models within the Aspose.Words.

Inheritance: OpenAiModelAiModel

Interfaces: IAiModelText

Methods

NameDescription
create(model_type)Creates a new instance of AiModel class.
(Inherited from AiModel)
summarize(doc, 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.
(Inherited from IAiModelText)
summarize(docs, 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.
(Inherited from IAiModelText)
with_api_key(api_key)Sets a specified API key to the model.
(Inherited from AiModel)
with_organization(organization_id)Sets a specified Organization to the model.
with_project(project_id)Sets a specified Project to the model.

Examples

Shows how to summarize text using OpenAI and Google models.

first_doc = aw.Document(MyDir + "Big document.docx")
second_doc = aw.Document(MyDir + "Document.docx")
api_key = os.getenv("API_KEY")
# Use OpenAI or Google generative language models.
model = aw.ai.AiModel.create(aw.ai.AiModelType.GPT_4O_MINI).with_api_key(api_key).as_open_ai_model()
options = aw.ai.SummarizeOptions()
options.summary_length = aw.ai.SummaryLength.SHORT
one_document_summary = model.summarize(first_doc, options)
oneDocumentSummary.save(ArtifactsDir + "AI.AiSummarize.One.docx")
options.summary_length = aw.ai.SummaryLength.LONG
multi_document_summary = model.summarize([first_doc, second_doc], options)
multiDocumentSummary.save(ArtifactsDir + "AI.AiSummarize.Multi.docx")

See Also