Skip to content

Actions Using Tools4AI

vishalmysore edited this page Mar 19, 2024 · 1 revision

In the ever-evolving landscape of artificial intelligence (AI), the demand for scalable and efficient AI models is constantly increasing. With the advent of Tools4AI, a groundbreaking project designed to streamline AI development processes, building large action models has become more accessible than ever before. By leveraging the power of JavaMethodAction extension and the intuitive @Predict annotation, developers can effortlessly create sophisticated AI systems capable of handling diverse tasks with ease.

Tools4AI represents a paradigm shift in AI development, offering a comprehensive toolkit that simplifies the creation of complex AI models. At its core, Tools4AI provides a framework for defining and implementing JavaMethodAction extensions, allowing developers to encapsulate specific actions within their AI systems.

Extending JavaMethodAction One of the key features of Tools4AI is the JavaMethodAction interface, which serves as the foundation for building AI actions. By extending JavaMethodAction, developers can define custom actions tailored to their specific requirements. Let's consider an example:

import java.util.logging.Logger;
import kong.unirest.HttpResponse;
import kong.unirest.Unirest;
import com.tools4ai.*;

@Predict(actionName = "googleSearch", description = "Search the web for information")
public class SearchAction implements JavaMethodAction {

    private static final Logger log = Logger.getLogger(SearchAction.class.getName());

    public String googleSearch(String searchString, boolean isNews)  {
        log.info(searchString + " : " + isNews);
        HttpResponse<String> response = Unirest.post("https://google.serper.dev/search")
                .header("X-API-KEY", PredictionLoader.getInstance().getSerperKey())
                .header("Content-Type", "application/json")
                .body("{\"q\":\"" + searchString + "\"}")
                .asString();
        return response.getBody();
    }

    @Override
    public String getDescription() {
        return "Search the web for information";
    }

    @Override
    public String getActionName() {
        return "googleSearch";
    }
}

In this example, the SearchAction class extends JavaMethodAction and is annotated with @Predict, specifying the actionName and description. The googleSearch method encapsulates the functionality to perform a web search using a specified search string. This method will be invoked when a user prompt matches the defined actionName during runtime.

Semantic Matching and Action Invocation One of the most powerful features of Tools4AI is its ability to semantically match user prompts with predefined actions. For instance, consider the following user queries:

"I am looking for the best places to see in Toronto as of this week." "What are the best attractions in Niagara Falls?" Using advanced natural language processing (NLP) techniques, Tools4AI can analyze these queries and identify the relevant action to be executed. In this case, the SearchAction with the actionName "googleSearch" would be invoked to perform the web search based on the provided search criteria.

Conclusion With Tools4AI, the process of building large action models for AI systems has never been easier. By extending the JavaMethodAction interface and annotating custom actions with @Predict, developers can create highly functional AI components capable of handling a wide range of tasks. Furthermore, the seamless integration of semantic matching ensures that user queries are accurately interpreted, leading to more intuitive and responsive AI interactions. As AI continues to reshape various industries, Tools4AI stands at the forefront, empowering developers to unlock the full potential of artificial intelligence.

By embracing the simplicity and flexibility offered by Tools4AI, developers can accelerate the development cycle, enhance the capabilities of their AI systems, and deliver exceptional user experiences in a rapidly evolving digital landscape.

Options

Clone this wiki locally