Class ChatHistory
- java.lang.Object
-
- com.microsoft.semantickernel.services.chatcompletion.ChatHistory
-
- All Implemented Interfaces:
Iterable<ChatMessageContent<?>>
public class ChatHistory extends Object implements Iterable<ChatMessageContent<?>>
Provides a history of messages between the User, Assistant and System
-
-
Constructor Summary
Constructors Constructor Description ChatHistory()The default constructorChatHistory(String instructions)Constructor that adds the given system instructions to the chat history.ChatHistory(List<? extends ChatMessageContent> chatMessageContents)Constructor that adds the given chat message contents to the chat history.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAll(ChatHistory value)Add all messages from the given chat history to this chat historyvoidaddAll(List<ChatMessageContent<?>> messages)voidaddAssistantMessage(String content)Add an assistant message to the chat historyvoidaddMessage(AuthorRole authorRole, String content)Add a message to the chat historyvoidaddMessage(AuthorRole authorRole, String content, Charset encoding, FunctionResultMetadata metadata)Add a message to the chat historyvoidaddMessage(ChatMessageContent<?> content)Add a message to the chat historyvoidaddSystemMessage(String content)Add an system message to the chat historyvoidaddUserMessage(String content)Add a user message to the chat historyvoidforEach(Consumer<? super ChatMessageContent<?>> action)Perform the given action for each message in the chat historyOptional<ChatMessageContent<?>>getLastMessage()Get last messageList<ChatMessageContent<?>>getMessages()Get the chat historyIterator<ChatMessageContent<?>>iterator()Create anIteratorfrom the chat history.Spliterator<ChatMessageContent<?>>spliterator()Create aSpliteratorfrom the chat history
-
-
-
Constructor Detail
-
ChatHistory
public ChatHistory()
The default constructor
-
ChatHistory
public ChatHistory(@Nullable String instructions)
Constructor that adds the given system instructions to the chat history.- Parameters:
instructions- The instructions to add to the chat history
-
ChatHistory
public ChatHistory(List<? extends ChatMessageContent> chatMessageContents)
Constructor that adds the given chat message contents to the chat history.- Parameters:
chatMessageContents- The chat message contents to add to the chat history
-
-
Method Detail
-
getMessages
public List<ChatMessageContent<?>> getMessages()
Get the chat history- Returns:
- List of messages in the chat
-
getLastMessage
public Optional<ChatMessageContent<?>> getLastMessage()
Get last message- Returns:
- The most recent message in chat
-
addAll
public void addAll(ChatHistory value)
Add all messages from the given chat history to this chat history- Parameters:
value- The chat history to add to this chat history
-
iterator
public Iterator<ChatMessageContent<?>> iterator()
Create anIteratorfrom the chat history.- Specified by:
iteratorin interfaceIterable<ChatMessageContent<?>>
-
forEach
public void forEach(Consumer<? super ChatMessageContent<?>> action)
Perform the given action for each message in the chat history- Specified by:
forEachin interfaceIterable<ChatMessageContent<?>>- Parameters:
action- The action to perform for each message in the chat history
-
spliterator
public Spliterator<ChatMessageContent<?>> spliterator()
Create aSpliteratorfrom the chat history- Specified by:
spliteratorin interfaceIterable<ChatMessageContent<?>>
-
addMessage
public void addMessage(AuthorRole authorRole, String content, Charset encoding, FunctionResultMetadata metadata)
Add a message to the chat history- Parameters:
authorRole- The role of the author of the messagecontent- The content of the messageencoding- The encoding of the messagemetadata- The metadata of the message
-
addMessage
public void addMessage(AuthorRole authorRole, String content)
Add a message to the chat history- Parameters:
authorRole- The role of the author of the messagecontent- The content of the message
-
addMessage
public void addMessage(ChatMessageContent<?> content)
Add a message to the chat history- Parameters:
content- The content of the message
-
addUserMessage
public void addUserMessage(String content)
Add a user message to the chat history- Parameters:
content- The content of the user message
-
addAssistantMessage
public void addAssistantMessage(String content)
Add an assistant message to the chat history- Parameters:
content- The content of the assistant message
-
addSystemMessage
public void addSystemMessage(String content)
Add an system message to the chat history- Parameters:
content- The content of the system message
-
addAll
public void addAll(List<ChatMessageContent<?>> messages)
-
-