Aspose::Words::AI::OpenAiModel class
Contents
[
Hide
]OpenAiModel class
Class representing OpenAi models integration within Aspose.Words.
class OpenAiModel : public AiModel
Methods
| Method | Description |
|---|---|
| OpenAiModel(const System::String &) | Initializes a new instance of OpenAiModel class. |
| OpenAiModel(const System::String &, const System::String &) | Initializes a new instance of OpenAiModel class. |
| Summarize(System::ArrayPtr<System::SharedPtr<Aspose::Words::Document>>, System::SharedPtr<Aspose::Words::AI::SummarizeOptions>) override | 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. |
| Summarize(System::SharedPtr<Aspose::Words::Document>, System::SharedPtr<Aspose::Words::AI::SummarizeOptions>) override | 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. |
| Translate(System::SharedPtr<Aspose::Words::Document>, Aspose::Words::AI::Language) override | Translates the provided document into the specified target language. This operation leverages the connected AI model for content translating. |
| WithOrganization(const System::String &) | Sets a specified Organization to the model. |
| WithProject(const System::String &) | Sets a specified Project to the model. |
| get_Url() override | Gets or sets a URL of the model. The default value is “https://api.openai.com/". |
| set_Url(System::String) override | Sets a URL of the model. The default value is “https://api.openai.com/". |
| virtual CheckGrammar(System::SharedPtr<Aspose::Words::Document>, System::SharedPtr<Aspose::Words::AI::CheckGrammarOptions>) | Checks grammar of the provided document. This operation leverages the connected AI model for checking grammar of document. |
| static Create(Aspose::Words::AI::AiModelType) | Creates a new instance of AiModel class. |
| virtual Summarize(System::ArrayPtr<System::SharedPtr<Aspose::Words::Document>>, System::SharedPtr<Aspose::Words::AI::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. |
| virtual Summarize(System::SharedPtr<Aspose::Words::Document>, System::SharedPtr<Aspose::Words::AI::SummarizeOptions>) | 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. |
| virtual Translate(System::SharedPtr<Aspose::Words::Document>, Aspose::Words::AI::Language) | Translates the provided document into the specified target language. This operation leverages the connected AI model for content translating. |
| WithApiKey(const System::String &) | Sets a specified API key to the model. |
| get_Timeout() const | 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). |
| virtual get_Url() | Gets or sets a URL of the model. The default value is specific for the model. |
| set_Timeout(int32_t) | Sets the number of milliseconds to wait before the request to AI model times out. The default value is 100,000 milliseconds (100 seconds). |
| virtual set_Url(System::String) | Sets a URL of the model. The default value is specific for the model. |
Remarks
Please refer to https://platform.openai.com/docs/models for OpenAi models details.
Examples
Shows how to summarize text using OpenAI and Google models.
auto firstDoc = System::MakeObject<Aspose::Words::Document>(System::String(get_MyDir() + u"Big document.docx"));
auto secondDoc = System::MakeObject<Aspose::Words::Document>(System::String(get_MyDir() + u"Document.docx"));
System::String apiKey = System::Environment::GetEnvironmentVariable(u"API_KEY");
// Use OpenAI or Google generative language models.
System::SharedPtr<Aspose::Words::AI::AiModel> model = (System::ExplicitCast<Aspose::Words::AI::OpenAiModel>(AiModel::Create(AiModelType::Gpt4OMini)->WithApiKey(apiKey)))->WithOrganization(u"Organization")->WithProject(u"Project");
auto options = System::MakeObject<Aspose::Words::AI::SummarizeOptions>();
options->set_SummaryLength(SummaryLength::Short);
System::SharedPtr<Aspose::Words::Document> oneDocumentSummary = model->Summarize(firstDoc, options);
oneDocumentSummary->Save(get_ArtifactsDir() + u"AI.AiSummarize.One.docx");
options->set_SummaryLength(SummaryLength::Long);
System::SharedPtr<Aspose::Words::Document> multiDocumentSummary = model->Summarize(System::MakeArray<System::SharedPtr<Aspose::Words::Document>>({firstDoc, secondDoc}), options);
multiDocumentSummary->Save(get_ArtifactsDir() + u"AI.AiSummarize.Multi.docx");
See Also
- Class AiModel
- Namespace Aspose::Words::AI
- Library Aspose.Words for C++