13
13
import com .aspose .words .Document ;
14
14
import com .aspose .ms .System .Environment ;
15
15
import com .aspose .words .IAiModelText ;
16
+ import com .aspose .words .OpenAiModel ;
16
17
import com .aspose .words .AiModel ;
17
18
import com .aspose .words .AiModelType ;
18
19
import com .aspose .words .SummarizeOptions ;
19
20
import com .aspose .words .SummaryLength ;
20
21
import com .aspose .words .Language ;
22
+ import com .aspose .words .CheckGrammarOptions ;
21
23
22
24
23
25
@ Test
@@ -30,10 +32,13 @@ public void aiSummarize() throws Exception
30
32
//GistId:366eb64fd56dec3c2eaa40410e594182
31
33
//ExFor:GoogleAiModel
32
34
//ExFor:OpenAiModel
35
+ //ExFor:OpenAiModel.WithOrganization(String)
36
+ //ExFor:OpenAiModel.WithProject(String)
33
37
//ExFor:IAiModelText
34
38
//ExFor:IAiModelText.Summarize(Document, SummarizeOptions)
35
39
//ExFor:IAiModelText.Summarize(Document[], SummarizeOptions)
36
40
//ExFor:SummarizeOptions
41
+ //ExFor:SummarizeOptions.#ctor
37
42
//ExFor:SummarizeOptions.SummaryLength
38
43
//ExFor:SummaryLength
39
44
//ExFor:AiModel
@@ -46,7 +51,7 @@ public void aiSummarize() throws Exception
46
51
47
52
String apiKey = System .getenv ("API_KEY" );
48
53
// 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" );
50
55
51
56
Document oneDocumentSummary = model .summarize (firstDoc , new SummarizeOptions (); { oneDocumentSummary .setSummaryLength (SummaryLength .SHORT ); });
52
57
oneDocumentSummary .save (getArtifactsDir () + "AI.AiSummarize.One.docx" );
@@ -62,6 +67,7 @@ public void aiTranslate() throws Exception
62
67
//ExStart:AiTranslate
63
68
//GistId:695136dbbe4f541a8a0a17b3d3468689
64
69
//ExFor:IAiModelText.Translate(Document, AI.Language)
70
+ //ExFor:AI.Language
65
71
//ExSummary:Shows how to translate text using Google models.
66
72
Document doc = new Document (getMyDir () + "Document.docx" );
67
73
@@ -73,5 +79,27 @@ public void aiTranslate() throws Exception
73
79
translatedDoc .save (getArtifactsDir () + "AI.AiTranslate.docx" );
74
80
//ExEnd:AiTranslate
75
81
}
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
+ }
76
104
}
77
105
0 commit comments