ChatHistory Class
- java.
lang. Object - com.
microsoft. semantickernel. services. chatcompletion. ChatHistory
- com.
Implements
public class ChatHistory
implements java.lang.Iterable<ChatMessageContent<?>>
Provides a history of messages between the User, Assistant and System
Constructor Summary
| Constructor | Description |
|---|---|
| ChatHistory() |
The default constructor |
| ChatHistory(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
| Modifier and Type | Method and Description |
|---|---|
| void |
addAll(ChatHistory value)
Add all messages from the given chat history to this chat history |
|
Chat |
addAll(List<ChatMessageContent<?>> messages)
Add all messages to the chat history |
|
Chat |
addAssistantMessage(String content)
Add an assistant message to the chat history |
|
Chat |
addMessage(AuthorRole authorRole, String content)
Add a message to the chat history |
|
Chat |
addMessage(AuthorRole authorRole, String content, Charset encoding, FunctionResultMetadata<?> metadata)
Add a message to the chat history |
|
Chat |
addMessage(ChatMessageContent<?> content)
Add a message to the chat history |
|
Chat |
addSystemMessage(String content)
Add an system message to the chat history |
|
Chat |
addUserMessage(String content)
Add a user message to the chat history |
| void |
forEach(Consumer<? super ChatMessageContent<?>> action)
Perform the given action for each message in the chat history |
|
java.util.Optional<Chat |
getLastMessage()
Get last message |
|
java.util.List<Chat |
getMessages()
Get the chat history |
|
java.util.Iterator<Chat |
iterator()
Create an |
|
java.util.Spliterator<Chat |
spliterator()
Create a |
Methods inherited from java.lang.Object
Constructor Details
ChatHistory
public ChatHistory()
The default constructor
ChatHistory
public ChatHistory(String instructions)
Constructor that adds the given system instructions to the chat history.
Parameters:
ChatHistory
public ChatHistory(List> chatMessageContents)
Constructor that adds the given chat message contents to the chat history.
Parameters:
Method Details
addAll
public void addAll(ChatHistory value)
Add all messages from the given chat history to this chat history
Parameters:
addAll
public ChatHistory addAll(List
Add all messages to the chat history
Parameters:
Returns:
this ChatHistoryaddAssistantMessage
public ChatHistory addAssistantMessage(String content)
Add an assistant message to the chat history
Parameters:
Returns:
this ChatHistoryaddMessage
public ChatHistory addMessage(AuthorRole authorRole, String content)
Add a message to the chat history
Parameters:
Returns:
this ChatHistoryaddMessage
public ChatHistory addMessage(AuthorRole authorRole, String content, Charset encoding, FunctionResultMetadata metadata)
Add a message to the chat history
Parameters:
Returns:
this ChatHistoryaddMessage
public ChatHistory addMessage(ChatMessageContent content)
Add a message to the chat history
Parameters:
Returns:
this ChatHistoryaddSystemMessage
public ChatHistory addSystemMessage(String content)
Add an system message to the chat history
Parameters:
Returns:
this ChatHistoryaddUserMessage
public ChatHistory addUserMessage(String content)
Add a user message to the chat history
Parameters:
Returns:
this ChatHistoryforEach
public void forEach(Consumer> action)
Perform the given action for each message in the chat history
Parameters:
getLastMessage
public Optional
Get last message
Returns:
getMessages
public List
Get the chat history
Returns:
iterator
public Iterator
Create an Iterator from the chat history.
Returns:
Iterator from the chat history.spliterator
public Spliterator
Create a Spliterator from the chat history
Returns:
Spliterator from the chat history