public abstract class GoogleAiModel extends AiModel implements IAiModelText
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");
| Constructor and Description |
|---|
GoogleAiModel() |
| Modifier and Type | Method and Description |
|---|---|
protected int |
getInputTokenLimit() |
protected int |
getOutputTokenLimit() |
protected java.lang.String |
getUrl() |
Document |
summarize(Document doc) |
Document |
summarize(Document[] docs) |
Document |
summarize(Document[] docs,
SummarizeOptions options)
Summarizes specified
Document objects. |
Document |
summarize(Document doc,
SummarizeOptions options)
Summarizes specified
Document object. |
Document |
translate(Document doc,
int language) |
checkGrammar, create, getName, withApiKeyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcheckGrammarpublic Document summarize(Document doc) throws java.lang.Exception
java.lang.Exceptionpublic Document summarize(Document doc, SummarizeOptions options) throws java.lang.Exception
Document object.summarize in interface IAiModelTextsummarize in class AiModeldoc - The document to be summarized.options - Optional settings to control the summary length and other parameters.java.lang.Exceptionpublic Document summarize(Document[] docs) throws java.lang.Exception
java.lang.Exceptionpublic Document summarize(Document[] docs, SummarizeOptions options) throws java.lang.Exception
Document objects.summarize in interface IAiModelTextsummarize in class AiModeldocs - An array of documents to be summarized.options - Optional settings to control the summary length and other parametersjava.lang.Exceptionpublic Document translate(Document doc, int language) throws java.lang.Exception
translate in interface IAiModelTexttranslate in class AiModeljava.lang.Exceptionprotected int getInputTokenLimit()
protected int getOutputTokenLimit()