Class RestAPI

java.lang.Object
mindsdb.connectors.RestAPI

public final class RestAPI extends Object
RestAPI class for handling REST API requests.
  • Constructor Details

    • RestAPI

      public RestAPI(String url, String login, String password, String apiKey, boolean isManaged, Map<String,String> headers)
      Constructor for RestAPI
      Parameters:
      url - URL to MindsDB server
      login - User login, for cloud version it contains email
      password - User password to login (for cloud version)
      apiKey - API key to authenticate (for cloud version)
      isManaged - Whether or not the URL points to a managed instance
      headers - Additional headers to send with the connection, optional
  • Method Details

    • getUrl

      public String getUrl()
      Get the URL of the MindsDB server
      Returns:
      URL of the MindsDB server
    • login

      public void login()
      Login to the MindsDB server
    • sqlQuery

      public tech.tablesaw.api.Table sqlQuery(String sql, String database)
      Execute a SQL query to the MindsDB server
      Parameters:
      sql - SQL query to execute
      database - Database to execute the query on
      Returns:
      Tablesaw Table containing the result of the query
    • sqlQuery

      public tech.tablesaw.api.Table sqlQuery(String sql)
      Execute a SQL query to the MindsDB server
      Parameters:
      sql - SQL query to execute
      Returns:
      Tablesaw Table containing the result of the query in form of table
    • closeSession

      public void closeSession()
      Close the session
    • createAgent

      public com.google.gson.JsonObject createAgent(String project, String name, String model, String provider, List<String> skills, Map<String,Object> params)
      Create a new agent
      Parameters:
      project - Name of the project
      name - Name of the Agent
      model - Name of the model
      provider - Name of the provider
      skills - List of skills
      params - Additional parameters
      Returns:
      JsonObject containing the agent details
      Throws:
      kong.unirest.core.UnirestException - when the request fails when the request fails
    • updateAgent

      public com.google.gson.JsonObject updateAgent(String project, String name, String updatedName, String updatedModel, List<String> skillsToAdd, List<String> skillsToRemove, com.google.gson.JsonObject updatedParams)
      Update an agent
      Parameters:
      project - Project name
      name - Agent name
      updatedName - Updated agent name
      updatedModel - Updated model name
      skillsToAdd - List of skills to add
      skillsToRemove - List of skills to remove
      updatedParams - Updated parameters
      Returns:
      JsonObject containing the updated agent details
    • status

      public com.google.gson.JsonObject status() throws kong.unirest.core.UnirestException
      Upload a custom handler to MindsDB
      Returns:
      JsonObject containing the response
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • agents

      public com.google.gson.JsonArray agents(String project) throws kong.unirest.core.UnirestException
      Get the status of the MindsDB server
      Parameters:
      project - Name of the project
      Returns:
      JsonObject containing the status of the project
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • agent

      public com.google.gson.JsonObject agent(String project, String name) throws kong.unirest.core.UnirestException
      Get the status of the MindsDB server
      Parameters:
      project - Name of the project
      name - Name of the agent
      Returns:
      JsonObject containing the status of the agent
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • agentCompletion

      public com.google.gson.JsonObject agentCompletion(String project, String name, List<com.google.gson.JsonObject> messages) throws kong.unirest.core.UnirestException
      Get the status of the MindsDB server
      Parameters:
      project - Name of the project
      name - Name of the agent
      messages - List of messages
      Returns:
      JsonObject containing the completion of the agent
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • deleteAgent

      public void deleteAgent(String project, String name) throws kong.unirest.core.UnirestException
      Delete an agent
      Parameters:
      project - Name of the project
      name - Name of the agent
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • skills

      public com.google.gson.JsonArray skills(String project) throws kong.unirest.core.UnirestException
      Get skills of a project
      Parameters:
      project - Name of the project
      Returns:
      JsonArray containing the skills of the project
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • skill

      public com.google.gson.JsonObject skill(String project, String name) throws kong.unirest.core.UnirestException
      Get a skill of a project
      Parameters:
      project - Name of the project
      name - Name of the skill
      Returns:
      JsonObject containing the skill details
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • createSkill

      public void createSkill(String project, String name, String type, com.google.gson.JsonObject params) throws kong.unirest.core.UnirestException
      Create a skill
      Parameters:
      project - Name of the project
      name - Name of the skill
      type - Type of the skill
      params - Parameters of the skill
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • updateSkill

      public void updateSkill(String project, String name, String updatedName, String updatedType, com.google.gson.JsonObject updatedParams) throws kong.unirest.core.UnirestException
      Update a skill
      Parameters:
      project - Name of the project
      name - Name of the skill
      updatedName - Updated name of the skill
      updatedType - Updated type of the skill
      updatedParams - Updated parameters of the skill
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • deleteSkill

      public void deleteSkill(String project, String name) throws kong.unirest.core.UnirestException
      Delete a skill
      Parameters:
      project - Name of the project
      name - Name of the skill
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • insertFilesIntoKnowledgeBase

      public void insertFilesIntoKnowledgeBase(String project, String knowledgeBaseName, List<String> fileNames) throws kong.unirest.core.UnirestException
      Insert files into a knowledge base
      Parameters:
      project - Name of the project
      knowledgeBaseName - Name of the knowledge base
      fileNames - List of file names
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • insertWebpagesIntoKnowledgeBase

      public void insertWebpagesIntoKnowledgeBase(String project, String knowledgeBaseName, List<String> urls, int crawlDepth, List<String> filters) throws kong.unirest.core.UnirestException
      Insert webpages into a knowledge base
      Parameters:
      project - Name of the project
      knowledgeBaseName - Name of the knowledge base
      urls - List of URLs
      crawlDepth - Crawl depth
      filters - List of filters
      Throws:
      kong.unirest.core.UnirestException - when the request fails
    • objectsTree

      public tech.tablesaw.api.Table objectsTree(String item)
      Insert data into a knowledge base
      Parameters:
      item - Name of the item
      Returns:
      Tablesaw Table containing the data
    • objectsTree

      public tech.tablesaw.api.Table objectsTree()
      Insert data into a knowledge base
      Returns:
      Tablesaw Table containing the data
    • modelPredict

      public tech.tablesaw.api.Table modelPredict(String project, String model, tech.tablesaw.api.Table data, Map<String,String> params, Integer version)
      Make a batch prediction using a MindsDB model
      Parameters:
      project - Name of the project
      model - Name of the model
      data - Tablesaw table containing the data
      params - Additional params for model
      version - Version of model to use
      Returns:
      Tablesaw table object containing prediction
    • modelPredict

      public tech.tablesaw.api.Table modelPredict(String project, String model, Map<String,String> data, Map<String,String> params, Integer version)
      Make a single prediction using a MindsDB model
      Parameters:
      project - Name of field to predict
      model - Name of the model
      data - Data provided to model
      params - Additional parameters
      version - Version of the model
      Returns:
      Tablesaw Table containing the prediction
    • readFileAsBytes

      public static byte[] readFileAsBytes(String filePath)
      Read the content of a file as bytes
      Parameters:
      filePath - Path to the file
      Returns:
      Byte array of the file
    • readDataFrameAsCSV

      public static byte[] readDataFrameAsCSV(tech.tablesaw.api.Table dataframe)
      Read the content of dataframe as csv in bytes
      Parameters:
      dataframe - DataFrame to read
      Returns:
      DataFrame as csv in bytes
    • readFileAsWebpage

      public static String readFileAsWebpage(String url)
      Read the content of a file as a webpage
      Parameters:
      url - URL of the webpage
      Returns:
      Content of the webpage
    • uploadData

      public void uploadData(String fileName, byte[] data)
      Upload a file to the MindsDB server
      Parameters:
      fileName - Name of the file
      data - Byte array of the file
    • uploadFile

      public void uploadFile(String name, String data)
      Upload a file to the MindsDB server
      Parameters:
      name - Name of the file
      data - Data of the file
    • uploadFile

      public void uploadFile(String name, tech.tablesaw.api.Table data)
      Upload a file to the MindsDB server
      Parameters:
      name - Name of the file
      data - Tablesaw Table containing the data
    • getFileMetadata

      public com.google.gson.JsonObject getFileMetadata(String name) throws kong.unirest.core.UnirestException
      Upload a file to the MindsDB server
      Parameters:
      name - Name of the file
      Returns:
      Tablesaw Table containing the data
      Throws:
      kong.unirest.core.UnirestException - when the request fails