Skip to content

casibase/casibase-java-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Casibase Java Example

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.

Main Features

  • Send messages to Casibase AI
  • Handle streaming responses
  • Process AI responses in real-time

API Functions

addMessage(String text)

Sends a message to the Casibase API.

addMessage("hi"); // Sends "hi" to the AI

getLastMessageName()

Retrieves the name of the last message in the chat history.

String lastMessageName = getLastMessageName();

getMessageAnswer(String messageName)

Gets the AI's response for a specific message. Handles streaming response with real-time output.

getMessageAnswer(lastMessageName); // Prints AI response in real-time

Usage Example

try {
    // Send message
    addMessage("hi");
    String lastMessageName = getLastMessageName();

    // Get AI response
    if (lastMessageName != null) {
        getMessageAnswer(lastMessageName);
    }
} catch (IOException e) {
    e.printStackTrace();
}

Response Handling

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.

Releases

No releases published

Packages

No packages published

Languages