Package io.keikai.doc.ai.api.editor
Class AIEditor
java.lang.Object
io.keikai.doc.api.editor.Editor
io.keikai.doc.ai.api.editor.AIEditor
public class AIEditor
extends io.keikai.doc.api.editor.Editor
An AI editor that can chat with a language model to generate responses.
- Author:
- jumperchen
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidAccepts the AI chat, if any.voidaddPromptTemplate(String key, AIPromptTemplate template) Adds a prompt template.voidReloads the chat with the default prompt template to continue writing.voidDiscards the AI chat, if any.static AIEditorgetInstance(io.keikai.doc.api.DocumentModel model, dev.langchain4j.model.chat.StreamingChatLanguageModel chatModel) Returns an AI editor for the specified document model.getPromptTemplate(String key) Returns the prompt template for the specified key.protected voidInitializes the prompt templates.voidreloadChat(Function<AIPromptTemplate, AIPromptTemplate> promptTemplateFunction, Consumer<String> responseConsumer) Reloads the chat with the specified prompt template.Removes the prompt template for the specified key.Methods inherited from class io.keikai.doc.api.editor.Editor
clearRevisionHistory, execute, getComponents, getComponentsByAttr, getCurrentRevisionIndex, getDirectComponents, getDirectParagraphs, getDirectTables, getInReadLock, getInstance, getLists, getModel, getParagraphs, getParagraphsByAttr, getRevisionHistory, getSections, getSelection, getTables, getTablesByAttr, loadJSON, loadJSON, loadJSON, loadJSON, loadRevision, redo, removeSelection, runInWriteLock, runInWriteLock, toJSON, undo
-
Method Details
-
initPromptTemplate
protected void initPromptTemplate()Initializes the prompt templates. -
addPromptTemplate
Adds a prompt template.- Parameters:
key-Enum.name()template- the prompt template
-
getPromptTemplate
Returns the prompt template for the specified key.- Parameters:
key-Enum.name()
-
removePromptTemplate
Removes the prompt template for the specified key.- Parameters:
key-Enum.name()
-
getInstance
public static AIEditor getInstance(io.keikai.doc.api.DocumentModel model, dev.langchain4j.model.chat.StreamingChatLanguageModel chatModel) Returns an AI editor for the specified document model.- Parameters:
model- the document model to edit or querychatModel- the chat model to use- Returns:
- an editor for the specified document model
-
acceptChat
public void acceptChat()Accepts the AI chat, if any. -
discardChat
public void discardChat()Discards the AI chat, if any. -
reloadChat
public void reloadChat(Function<AIPromptTemplate, AIPromptTemplate> promptTemplateFunction, Consumer<String> responseConsumer) Reloads the chat with the specified prompt template.To modify the prompt template, use the promptTemplateFunction function to modify the prompt template.
For example,
reloadChat(template -> { template.setUserMessage(template.getUserMessage().replace("{prompt}", "Continue writing AFTER <Block> ONLY ONE SENTENCE. DONT REPEAT THE TEXT.")); return template; }, response -> { execute(Commands.text(response)); });- Parameters:
promptTemplateFunction- a function to modify the prompt templateresponseConsumer- a consumer to consume the response
-
continueWrite
public void continueWrite()Reloads the chat with the default prompt template to continue writing.- See Also:
-