Skip to content

Commit 95201d5

Browse files
committed
Autoport ApiExamples 25.01
1 parent 71f1e1d commit 95201d5

15 files changed

+438
-50
lines changed

Examples/ApiExamples/JavaPorting/ExAI.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@
1313
import com.aspose.words.Document;
1414
import com.aspose.ms.System.Environment;
1515
import com.aspose.words.IAiModelText;
16+
import com.aspose.words.OpenAiModel;
1617
import com.aspose.words.AiModel;
1718
import com.aspose.words.AiModelType;
1819
import com.aspose.words.SummarizeOptions;
1920
import com.aspose.words.SummaryLength;
2021
import com.aspose.words.Language;
22+
import com.aspose.words.CheckGrammarOptions;
2123

2224

2325
@Test
@@ -30,10 +32,13 @@ public void aiSummarize() throws Exception
3032
//GistId:366eb64fd56dec3c2eaa40410e594182
3133
//ExFor:GoogleAiModel
3234
//ExFor:OpenAiModel
35+
//ExFor:OpenAiModel.WithOrganization(String)
36+
//ExFor:OpenAiModel.WithProject(String)
3337
//ExFor:IAiModelText
3438
//ExFor:IAiModelText.Summarize(Document, SummarizeOptions)
3539
//ExFor:IAiModelText.Summarize(Document[], SummarizeOptions)
3640
//ExFor:SummarizeOptions
41+
//ExFor:SummarizeOptions.#ctor
3742
//ExFor:SummarizeOptions.SummaryLength
3843
//ExFor:SummaryLength
3944
//ExFor:AiModel
@@ -46,7 +51,7 @@ public void aiSummarize() throws Exception
4651

4752
String apiKey = System.getenv("API_KEY");
4853
// Use OpenAI or Google generative language models.
49-
IAiModelText model = (IAiModelText)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);
54+
IAiModelText model = ((OpenAiModel)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey)).withOrganization("Organization").withProject("Project");
5055

5156
Document oneDocumentSummary = model.summarize(firstDoc, new SummarizeOptions(); { oneDocumentSummary.setSummaryLength(SummaryLength.SHORT); });
5257
oneDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.One.docx");
@@ -62,6 +67,7 @@ public void aiTranslate() throws Exception
6267
//ExStart:AiTranslate
6368
//GistId:695136dbbe4f541a8a0a17b3d3468689
6469
//ExFor:IAiModelText.Translate(Document, AI.Language)
70+
//ExFor:AI.Language
6571
//ExSummary:Shows how to translate text using Google models.
6672
Document doc = new Document(getMyDir() + "Document.docx");
6773

@@ -73,5 +79,27 @@ public void aiTranslate() throws Exception
7379
translatedDoc.save(getArtifactsDir() + "AI.AiTranslate.docx");
7480
//ExEnd:AiTranslate
7581
}
82+
83+
@Test (enabled = false, description = "This test should be run manually to manage API requests amount")
84+
public void aiGrammar() throws Exception
85+
{
86+
//ExStart:AiGrammar
87+
//GistId:f86d49dc0e6781b93e576539a01e6ca2
88+
//ExFor:IAiModelText.CheckGrammar(Document, CheckGrammarOptions)
89+
//ExFor:CheckGrammarOptions
90+
//ExSummary:Shows how to check the grammar of a document.
91+
Document doc = new Document(getMyDir() + "Big document.docx");
92+
93+
String apiKey = System.getenv("API_KEY");
94+
// Use OpenAI generative language models.
95+
IAiModelText model = (IAiModelText)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);
96+
97+
CheckGrammarOptions grammarOptions = new CheckGrammarOptions();
98+
grammarOptions.setImproveStylistics(true);
99+
100+
Document proofedDoc = model.checkGrammar(doc, grammarOptions);
101+
proofedDoc.save("AI.AiGrammar.docx");
102+
//ExEnd:AiGrammar
103+
}
76104
}
77105

0 commit comments

Comments
 (0)