Package com.storedobject.ai
Interface Chat
public interface Chat
The Chat interface represents a basic contract for interaction between the user
and an AI system through text-based communication. It provides a method to ask
a question or send a message to the system, receiving a response asynchronously.
- Author:
- Syam
-
Method Summary
Modifier and TypeMethodDescriptionvoidabort()Aborts the current chat session, interrupting any ongoing interactions with the AI system.Sends a message to the chat system and receives a response asynchronously.voidclose()Closes the chat interface, releasing any associated resources or connections.intReturns the number of tokens in the input message that was last sent to the chat system.intReturns the number of tokens in the output message that was last received from the chat system.default intReturns the total number of tokens used by the chat system in the current conversation.intReturns the total number of tokens used by the chat system in the current conversation.intReturns the total number of tokens used by the chat system in the current conversation.default intReturns the total number of tokens used by the chat system in the current conversation.booleanisClosed()Checks whether the chat instance has been closed.booleanCheck if logging is enabled.voidsetChatClosedListener(Runnable listener) Sets a listener to be invoked when the chat is closed.voidsetLogging(boolean logging) Enable/Disable logging.
-
Method Details
-
ask
-
abort
void abort()Aborts the current chat session, interrupting any ongoing interactions with the AI system. This method should be called when the user wants to stop the current conversation prematurely. -
close
void close()Closes the chat interface, releasing any associated resources or connections. This method should be called when the chat instance is no longer needed to ensure proper cleanup. -
isClosed
boolean isClosed()Checks whether the chat instance has been closed.- Returns:
trueif the chat instance is closed, otherwisefalse.
-
setChatClosedListener
Sets a listener to be invoked when the chat is closed. The listener is aRunnablethat will execute when the chat instance is closed by calling theclosemethod.- Parameters:
listener- theRunnableto be executed when the chat is closed.
-
getInputTokenCount
int getInputTokenCount()Returns the number of tokens in the input message that was last sent to the chat system. This can be useful for monitoring the token usage in the chat session.- Returns:
- the number of tokens in the last input message.
-
getOutputTokenCount
int getOutputTokenCount()Returns the number of tokens in the output message that was last received from the chat system. This can be useful for monitoring the token usage in the chat session.- Returns:
- the number of tokens in the last output message.
-
getTotalInputTokenCount
int getTotalInputTokenCount()Returns the total number of tokens used by the chat system in the current conversation.- Returns:
- the total number of tokens used in the current conversation.
-
getTotalOutputTokenCount
int getTotalOutputTokenCount()Returns the total number of tokens used by the chat system in the current conversation.- Returns:
- the total number of tokens used in the current conversation.
-
getTokensUsed
default int getTokensUsed()Returns the total number of tokens used by the chat system in the current conversation.- Returns:
- the total number of tokens used in the current conversation.
-
getTotalTokensUsed
default int getTotalTokensUsed()Returns the total number of tokens used by the chat system in the current conversation.- Returns:
- the total number of tokens used in the current conversation.
-
setLogging
void setLogging(boolean logging) Enable/Disable logging.- Parameters:
logging- true to enable logging, false to disable logging.
-
isLogging
boolean isLogging()Check if logging is enabled.- Returns:
- true if logging is enabled, false otherwise.
-