SAM - Simple Action Model with Java

vishalmysore - Mar 27 - - Dev Community

As the initial excitement surrounding the novelty of generating images, videos, and conversation with artificial intelligence gradually fades, individuals begin to seek more tangible and practical applications. Enter "SAM" – Open source "Simple Action Model" designed to take actions , not just chat. Leveraging AI and Java integration, SAM can serve as an intuitive platform capable of executing various tasks seamlessly in response to simple English conversations.

SAM is a reference application built on open source Tools4AI project.

By using Tools4AI, Sam's versatility can extend across multiple domains, and can offer a wide array of functionalities to enhance convenience and efficiency in everyday life. Here's a glimpse into what Sam can accomplish:

Home Automation:
Sam can seamlessly integrates with smart home ecosystem by leveraging open source Home Assistant API (https://developers.home-assistant.io/docs/api/rest/,) allowing you to effortlessly control various devices. Whether you want to adjust the thermostat to create the perfect ambiance, lock or unlock doors for added security, or even dim the lights to set the mood, Sam responds promptly to your commands, making home management a breeze. The HTTP actions built into Sam can call any actions which are exposed as API via Home Assistant.
prompt = "Sam, how many devices do you see?"
Will trigger this action automatically


@Predict
public class HAAction implements AIAction {

public List<State> getDevices() {
        List<State> theDeviceStates = null;
        State[] theHassStates;
        String theUrl = null;
        String theData;
        headers = getAuthHeader();
        if (hassAddress.getSecure() != null && hassAddress.getSecure())
            theUrl = "https";
        else
            theUrl = "http";
        theUrl = theUrl + "://" + hassAddress.getIp() + ":" + hassAddress.getPort() + "/api/states";
        theData = anHttpHandler.doHttpRequest(theUrl, HttpGet.METHOD_NAME, "application/json", null, headers);
        if (theData != null) {
            log.debug("GET Hass States - data: " + theData);
            theHassStates = new Gson().fromJson(theData, State[].class);
            if (theHassStates == null) {
                log.warn("Cannot get an devices for HomeAssistant " + hassAddress.getName()
                        + " as response is not parsable.");
            } else {
                theDeviceStates = new ArrayList<State>(Arrays.asList(theHassStates));
            }
        } else
            log.warn("Cannot get an devices for HomeAssistant " + hassAddress.getName() + " http call failed.");
        return theDeviceStates;
    }


Enter fullscreen mode Exit fullscreen mode

Travel Assistance:
Say goodbye to the hassle of planning and booking travel arrangements manually. With Sam at your service, you can simply instruct it to book flight tickets to your desired destination, ensuring a smooth and hassle-free travel experience. Additionally, Sam can assist in reserving accommodations, scheduling transportation, and providing real-time updates on travel itineraries, simplifying the entire process from start to finish.
prompt = "Sam , whats the status of flight AIR-785"
will automatically call one of these rest API's

Image description

prompt = "Sam what is my booking details"
can trigger one of these rest apis

Image description

Dining and Entertainment:
Sam simplifies the process of dining out and enjoying entertainment experiences. Need a table at your favorite restaurant? Just ask Sam, and it will make the reservation for you, considering your preferences and dietary restrictions. Planning a movie night? Sam can secure tickets for the latest blockbuster, ensuring you never miss out on the entertainment you love.
prompt = "I am in mood to eat some spicy food today"
will automatically trigger this HTTP GET Request

# Get /v1/restaurant/{Indian}

{
  "restaurant": {
    "name": "My Spicy Restaurant",
    "cuisines": "Indian",
    "phone": "011 01 009910091",
    "email": "my@spicyfoodemail.com",
    "opening_times_attributes": [{ "day_of_week": "monday", "opening_time": "12:00", "closing_time": "23:00" }],
    "location": "Bangalore"
  }
}
Enter fullscreen mode Exit fullscreen mode

Personal Assistance:
From managing appointments and reminders to organizing tasks and events, Sam acts as your reliable personal assistant. Whether you need to set reminders for important deadlines, organize your schedule for the week, or even draft emails and messages, Sam is there to streamline your day-to-day activities, allowing you to focus on what matters most.
Sam boasts integrations with various technologies such as HTTP, databases (DB), Java, Websockets, and more. Unlike being tethered to a single AI platform, Sam offers interoperability with any AI platform (OpenAI, Gemini , LocalAI). This flexibility ensures that Sam can seamlessly adapt to your needs, leveraging the optimal AI tools available for enhanced performance and versatility
In essence, Sam represents the next frontier in AI-driven action models, offering a practical and intuitive solution to meet the evolving needs of users. With its ability to understand natural language commands and execute tasks seamlessly across various domains, Sam redefines the way we interact with technology, ushering in a new era of efficiency, convenience, and empowerment.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . .