public abstract class OpenAiModel extends AiModel implements IAiModelText
Examples:
Shows how to use self-hosted AI model based on OpenAiModel.
public void selfHostedModel() throws Exception
{
Document doc = new Document(getMyDir() + "Big document.docx");
String apiKey = System.getenv("API_KEY");
// Use OpenAI generative language models.
AiModel model = new CustomAiModel().withApiKey(apiKey);
Document translatedDoc = model.translate(doc, Language.RUSSIAN);
translatedDoc.save(getArtifactsDir() + "AI.SelfHostedModel.docx");
}
/// <summary>
/// Custom self-hosted AI model.
/// </summary>
static class CustomAiModel extends OpenAiModel
{
/// <summary>
/// Gets custom URL of the model.
/// </summary>
protected "; }
/// <summary>
/// Gets model name.
/// </summary>
protected String getName() { return "my-model-24b"; }
}
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 | Constructor and Description |
|---|---|
protected |
OpenAiModel()
Initializes a new instance of this class.
|
| Modifier and Type | Method and Description |
|---|---|
protected int |
getContextWindow() |
protected int |
getMaxOutputTokens() |
protected java.lang.String |
getUrl() |
Document |
summarize(Document sourceDocument) |
Document |
summarize(Document[] sourceDocuments) |
Document |
summarize(Document[] sourceDocuments,
SummarizeOptions options)
Generates summaries for an array of documents, with options to control the summary length and other settings.
|
Document |
summarize(Document sourceDocument,
SummarizeOptions options)
Generates a summary of the specified document, with options to adjust the length of the summary.
|
Document |
translate(Document sourceDocument,
int targetLanguage) |
OpenAiModel |
withOrganization(java.lang.String organizationId)
Sets a specified Organization to the model.
|
OpenAiModel |
withProject(java.lang.String projectId)
Sets a specified Project to the model.
|
checkGrammar, create, getName, withApiKeyclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcheckGrammarpublic Document summarize(Document sourceDocument) throws java.lang.Exception
java.lang.Exceptionpublic Document summarize(Document sourceDocument, SummarizeOptions options) throws java.lang.Exception
summarize in interface IAiModelTextsummarize in class AiModelsourceDocument - The document to be summarized.options - Optional settings to control the summary length and other parameters.java.lang.Exceptionpublic Document summarize(Document[] sourceDocuments) throws java.lang.Exception
java.lang.Exceptionpublic Document summarize(Document[] sourceDocuments, SummarizeOptions options) throws java.lang.Exception
summarize in interface IAiModelTextsummarize in class AiModelsourceDocuments - An array of documents to be summarized.options - Optional settings to control the summary length and other parametersjava.lang.Exceptionpublic Document translate(Document sourceDocument, int targetLanguage) throws java.lang.Exception
translate in interface IAiModelTexttranslate in class AiModeljava.lang.Exceptionpublic OpenAiModel withOrganization(java.lang.String organizationId)
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");
public OpenAiModel withProject(java.lang.String projectId)
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");
protected int getContextWindow()
protected int getMaxOutputTokens()