public class SummaryLength
extends java.lang.Object
Examples:
Shows how to summarize text using OpenAI and Google models.
Document firstDoc = new Document(getMyDir() + "Big document.docx");
Document secondDoc = new Document(getMyDir() + "Document.docx");
String apiKey = System.getenv("API_KEY");
// Use OpenAI or Google generative language models.
AiModel model = ((OpenAiModel)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey)).withOrganization("Organization").withProject("Project");
SummarizeOptions options = new SummarizeOptions();
options.setSummaryLength(SummaryLength.SHORT);
Document oneDocumentSummary = model.summarize(firstDoc, options);
oneDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.One.docx");
options.setSummaryLength(SummaryLength.LONG);
Document multiDocumentSummary = model.summarize(new Document[] { firstDoc, secondDoc }, options);
multiDocumentSummary.save(getArtifactsDir() + "AI.AiSummarize.Multi.docx");
| Modifier and Type | Field and Description |
|---|---|
static int |
length |
static int |
LONG
Try to generate 7-10 sentences.
|
static int |
MEDIUM
Try to generate 5-6 sentences.
|
static int |
SHORT
Try to generate 3-4 sentences.
|
static int |
VERY_LONG
Try to generate 11-20 sentences.
|
static int |
VERY_SHORT
Try to generate 1-2 sentences.
|
| Modifier and Type | Method and Description |
|---|---|
static int |
fromName(java.lang.String summaryLengthName) |
static java.lang.String |
getName(int summaryLength) |
static int[] |
getValues() |
static java.lang.String |
toString(int summaryLength) |
public static int VERY_SHORT
public static int SHORT
public static int MEDIUM
public static int LONG
public static int VERY_LONG
public static int length