Class Conversation
java.lang.Object
org.openhab.core.voice.text.conversation.Conversation
The
Conversation class contains a list of messages in between the user and a LanguageInterpreter.- Author:
- Miguel Álvarez Díez - Initial contribution
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConversation(String id) Conversation(String id, Instant created, Instant lastUpdated, List<Conversation.Message> messages) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(ConversationListener listener) Adds aConversationListener.intaddMessage(ConversationRole role, String content) Adds a new message to the end of the conversation.intaddMessage(ConversationRole role, String content, @Nullable Integer prevMessageID) Adds a new message to the end of the conversation.getId()@Nullable Conversation.MessageGet the last message (if any).Get a copy of the list of messages.voidremoveListener(ConversationListener listener) Removes aConversationListener.voidRemove all messages from the conversation.booleanremoveSinceMessage(int id) Removes a specific messages and all subsequent messages from the conversation.voidsetMaxMessages(int maxMessages) Set the maximum number of messages to keep in history.
-
Field Details
-
DEFAULT_MAX_MESSAGES
public static final int DEFAULT_MAX_MESSAGES- See Also:
-
-
Constructor Details
-
Conversation
-
Conversation
public Conversation(String id, Instant created, Instant lastUpdated, List<Conversation.Message> messages)
-
-
Method Details
-
addListener
Adds aConversationListener.- Parameters:
listener- the listener
-
removeListener
Removes aConversationListener.- Parameters:
listener- the listener
-
setMaxMessages
public void setMaxMessages(int maxMessages) Set the maximum number of messages to keep in history. At least 5 messages must be kept in the history.- Parameters:
maxMessages- the maximum number of messages
-
getId
-
getCreated
-
getLastUpdated
-
getMessages
Get a copy of the list of messages.- Returns:
- list of messages
-
getLastMessage
Get the last message (if any).- Returns:
- the last message or null
-
addMessage
Adds a new message to the end of the conversation.- Parameters:
role- the role that authored this messagecontent- the content of the message- Returns:
- the UID of the newly added message
- Throws:
ConversationException- seeaddMessage(ConversationRole, String, Integer)
-
addMessage
public int addMessage(ConversationRole role, String content, @Nullable Integer prevMessageID) throws ConversationException Adds a new message to the end of the conversation.The following conditions are enforced:
- If
prevMessageUIDis provided: The last message has the expected UID, so the conversation hasn't changed unexpectedly. - A tool return message must come after a tool call message.
- The first message is expected to be a user message.
- Parameters:
role- the role that authored this messagecontent- the content of the messageprevMessageID- the ID of the (assumed) previous message- Returns:
- the UID of the newly added message
- Throws:
ConversationException- when any of the above conditions is violated
- If
-
removeSinceMessage
public boolean removeSinceMessage(int id) Removes a specific messages and all subsequent messages from the conversation.- Parameters:
id- the ID of the message and its successors to remove- Returns:
- whether an actual removal happened
-
removeMessages
public void removeMessages()Remove all messages from the conversation.
-