Verified Owner
Top Constructors Methods
org.jabref.logic.ai.chatting.util

public final Class ChatHistoryUtils

extends Object
Class Inheritance
Imports
java.time.Instant, java.util.List, .Objects, .Optional, org.jabref.model.ai.chatting.ChatMessage

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static void
delete(List<ChatMessage> chatHistory, String id)

Removes the message with the specified ID from history.

public static Optional<ChatMessage>

Returns:

the last user messag, or empty if no user message is found
getLastUserMessage
(List<ChatMessage>
the chat history to search
chatHistory
)

Finds the last user message in the chat history by iterating backwards.

public static Optional<String>

Returns:

the content to regenerate or empty if the message was not found
regenerate
(List<ChatMessage> chatHistory, String id)

Rewinds history to the point before the specified message and returns the user content to be re-sent.

public static void
updateSystemMessage(List<ChatMessage>
the chat history to update
chatHistory
,
String
the new system message content
newSystemMessage
)

Updates the system message in the chat history.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

ChatHistoryUtilsback to summary
private ChatHistoryUtils()

Method Detail

deleteback to summary
public static void delete(List<ChatMessage> chatHistory, String id)

Removes the message with the specified ID from history. Leaves a "hole" in context, but this is intended.

getLastUserMessageback to summary
public static Optional<ChatMessage> getLastUserMessage(List<ChatMessage> chatHistory)

Finds the last user message in the chat history by iterating backwards.

Parameters
chatHistory:List<ChatMessage>

the chat history to search

Returns:Optional<ChatMessage>

the last user messag, or empty if no user message is found

regenerateback to summary
public static Optional<String> regenerate(List<ChatMessage> chatHistory, String id)

Rewinds history to the point before the specified message and returns the user content to be re-sent.

Modifies the chat history in-place.

Returns:Optional<String>

the content to regenerate or empty if the message was not found

updateSystemMessageback to summary
public static void updateSystemMessage(List<ChatMessage> chatHistory, String newSystemMessage)

Updates the system message in the chat history. If a system message already exists, it is replaced. Otherwise, a new system message is added at the beginning.

Parameters
chatHistory:List<ChatMessage>

the chat history to update

newSystemMessage:String

the new system message content