This project demonstrates how to interact with the Casibase API using Java. It provides examples of sending messages and handling streaming responses from the AI model.
- Send messages to Casibase AI
- Handle streaming responses
- Process AI responses in real-time
Sends a message to the Casibase API.
addMessage("hi"); // Sends "hi" to the AI
Retrieves the name of the last message in the chat history.
String lastMessageName = getLastMessageName();
Gets the AI's response for a specific message. Handles streaming response with real-time output.
getMessageAnswer(lastMessageName); // Prints AI response in real-time
try {
// Send message
addMessage("hi");
String lastMessageName = getLastMessageName();
// Get AI response
if (lastMessageName != null) {
getMessageAnswer(lastMessageName);
}
} catch (IOException e) {
e.printStackTrace();
}
The API uses Server-Sent Events (SSE) for streaming responses. The response is processed in real-time, and the output is printed as it arrives. The stream automatically terminates when receiving a "data: end" message.