Getting Started
The SDK packages are maintained on Maven Central: https://search.maven.org/artifact/ai.waii/waii-java-sdk
You can add the dependency to your project's pom.xml
file.
<dependency>
<groupId>ai.waii</groupId>
<artifactId>waii-java-sdk</artifactId>
<version>1.9.0</version>
</dependency>
You will also need an API key to use the API. (You can get your API key by reaching out to us here: https://www.waii.ai)
That wraps up the pre-requisites. To get started with the WAII API, you first need to initialize the system.
// Import the WAII module
import ai.waii.Waii;
// Initialize WAII with the URL and API key
Waii waii = new Waii("https://sql.waii.ai/api/", "your_api_key");
If it's the first time you're using the system, you have to add a database connection. This can be done ahead of time / outside the SDK (using the UI for instance).
import ai.waii.clients.database.DBConnection;
import ai.waii.clients.database.ModifyDBConnectionRequest;
import ai.waii.clients.database.ModifyDBConnectionResponse;
DBConnection newConnection = new DBConnection(
null, // will be generated by the system
"snowflake", // database you're using
"your account",
"your username",
"your password",
"your database name",
"your warehouse name",
"desired user role",
null, // database path, only used by some DBMS
null, // host, only used by some DBMS
null, // port, only used by some DBMS
null, // optional parameters, only used by some DBMS
true, // sample column values, recommended for better fidelity
null // DBContentFilters, if you want to set include / exclude lists
);
ModifyDBConnectionRequest request = new ModifyDBConnectionRequest();
request.setUpdated(new DBConnection[]{newConnection});
ModifyDBConnectionResponse result = waii.getDatabase().modifyConnections(request);
If you already have database connections configured, you can activate them by key. Like so:
waii.getDatabase().activateConnection("<connection key>");
It can take a little time depending on the number of tables in the system.
And now you are ready to generate queries:
import ai.waii.clients.query.GeneratedQuery;
import ai.waii.clients.query.QueryGenerationRequest;
QueryGenerationRequest queryRequest
= new QueryGenerationRequest()
.setAsk("show me the revenue month over month for the last three years by store location");
GeneratedQuery queryResult = waii.getQuery().generate(queryRequest);