R/openapi/model_api.R

#' Jaqpot API
#'
#' A modern RESTful API for model management and prediction services, built using Spring Boot and Kotlin. Supports seamless integration with machine learning workflows.
#'
#' The version of the OpenAPI document: 1.0.0
#' Contact: upci.ntua@gmail.com
#' Generated by: https://openapi-generator.tech
#'
#' @docType class
#' @title Model operations
#' @description ModelApi
#' @format An \code{R6Class} generator object
#' @field api_client Handles the client-server communication.
#'
#' @examples
#' \dontrun{
#' ####################  CreateModel  ####################
#'
#' library(openapi)
#' var_model <- Model$new("name_example", ModelType$new(), "jaqpotpyVersion_example", c(Library$new("name_example", "version_example", 123, "createdAt_example", "updatedAt_example")), c(Feature$new("key_example", "name_example", FeatureType$new(), 123, "units_example", "range_example", "description_example", "DEPENDENT", "visible_example", c(FeaturePossibleValue$new("key_example", "value_example")), "createdAt_example", "updatedAt_example")), c(Feature$new("key_example", "name_example", FeatureType$new(), 123, "units_example", "range_example", "description_example", "DEPENDENT", "visible_example", c(FeaturePossibleValue$new("key_example", "value_example")), "createdAt_example", "updatedAt_example")), ModelVisibility$new(), ModelTask$new(), "rawModel_example", 123, "description_example", c(Doa$new(DoaMethod$new(), c(key = TODO), 123, "createdAt_example", "updatedAt_example")), c(Organization$new("name_example", OrganizationVisibility$new(), "contactEmail_example", 123, User$new("id_example", "username_example", "firstName_example", "lastName_example", "email_example", "emailVerified_example"), "description_example", c(OrganizationUser$new("userId_example", OrganizationUserAssociationType$new(), 123, "username_example", "email_example")), "contactPhone_example", "website_example", "address_example", "canEdit_example", "isMember_example", "created_at_example", "updated_at_example")), c(key = TODO), c(Transformer$new("name_example", c(key = TODO), 123)), c(Transformer$new("name_example", c(key = TODO), 123)), "rawPreprocessor_example", User$new("id_example", "username_example", "firstName_example", "lastName_example", "email_example", "emailVerified_example"), "canEdit_example", "isAdmin_example", c("selectedFeatures_example"), "tags_example", "legacyPredictionService_example", Model_scores$new(c(Scores$new(RegressionScores$new("yName_example", 123, 123, 123, 123), BinaryClassificationScores$new("yName_example", c("labels_example"), 123, 123, 123, c(123), c(123), c(123), c(123), 123, c(c(123))), MulticlassClassificationScores$new("yName_example", c("labels_example"), 123, 123, 123, c(123), c(123), c(123), c(123), 123, c(c(123))))), c(Scores$new(RegressionScores$new("yName_example", 123, 123, 123, 123), BinaryClassificationScores$new("yName_example", c("labels_example"), 123, 123, 123, c(123), c(123), c(123), c(123), 123, c(c(123))), MulticlassClassificationScores$new("yName_example", c("labels_example"), 123, 123, 123, c(123), c(123), c(123), c(123), 123, c(c(123))))), c(Scores$new(RegressionScores$new("yName_example", 123, 123, 123, 123), BinaryClassificationScores$new("yName_example", c("labels_example"), 123, 123, 123, c(123), c(123), c(123), c(123), 123, c(c(123))), MulticlassClassificationScores$new("yName_example", c("labels_example"), 123, 123, 123, c(123), c(123), c(123), c(123), 123, c(c(123)))))), RPbpkConfig$new("odeSolver_example"), "createdAt_example", "updatedAt_example") # Model |
#'
#' #Create a new model
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' api_instance$CreateModel(var_model)
#'
#'
#' ####################  DeleteModelById  ####################
#'
#' library(openapi)
#' var_id <- 0 # integer | The ID of the model to delete
#'
#' #Delete a Model
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' api_instance$DeleteModelById(var_id)
#'
#'
#' ####################  GetLegacyModelById  ####################
#'
#' library(openapi)
#' var_id <- "id_example" # character | The ID of the model to retrieve
#'
#' #Get a legacy model
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$GetLegacyModelById(var_iddata_file = "result.txt")
#' result <- api_instance$GetLegacyModelById(var_id)
#' dput(result)
#'
#'
#' ####################  GetModelById  ####################
#'
#' library(openapi)
#' var_id <- 0 # integer | The ID of the model to retrieve
#'
#' #Get a Model
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$GetModelById(var_iddata_file = "result.txt")
#' result <- api_instance$GetModelById(var_id)
#' dput(result)
#'
#'
#' ####################  GetModels  ####################
#'
#' library(openapi)
#' var_page <- 0 # integer |  (Optional)
#' var_size <- 10 # integer |  (Optional)
#' var_sort <- c("inner_example") # array[character] |  (Optional)
#'
#' #Get paginated models
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$GetModels(page = var_page, size = var_size, sort = var_sortdata_file = "result.txt")
#' result <- api_instance$GetModels(page = var_page, size = var_size, sort = var_sort)
#' dput(result)
#'
#'
#' ####################  GetSharedModels  ####################
#'
#' library(openapi)
#' var_page <- 0 # integer |  (Optional)
#' var_size <- 10 # integer |  (Optional)
#' var_sort <- c("inner_example") # array[character] |  (Optional)
#' var_organization_id <- 56 # integer |  (Optional)
#'
#' #Get paginated shared models
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$GetSharedModels(page = var_page, size = var_size, sort = var_sort, organization_id = var_organization_iddata_file = "result.txt")
#' result <- api_instance$GetSharedModels(page = var_page, size = var_size, sort = var_sort, organization_id = var_organization_id)
#' dput(result)
#'
#'
#' ####################  PartiallyUpdateModel  ####################
#'
#' library(openapi)
#' var_id <- 56 # integer |
#' var_partially_update_model_request <- partiallyUpdateModel_request$new("name_example", ModelVisibility$new(), ModelTask$new(), "description_example", "tags_example", c(123)) # PartiallyUpdateModelRequest |
#'
#' #Partially update specific fields of a model
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$PartiallyUpdateModel(var_id, var_partially_update_model_requestdata_file = "result.txt")
#' result <- api_instance$PartiallyUpdateModel(var_id, var_partially_update_model_request)
#' dput(result)
#'
#'
#' ####################  PredictWithModel  ####################
#'
#' library(openapi)
#' var_model_id <- 0 # integer | The ID of the model to use for prediction
#' var_dataset <- Dataset$new(DatasetType$new(), "ARRAY", c(TODO), 123, c(TODO), "CREATED", "failureReason_example", "userId_example", 123, "modelName_example", "executedAt_example", "executionFinishedAt_example", "createdAt_example", "updatedAt_example") # Dataset |
#'
#' #Predict with Model
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' api_instance$PredictWithModel(var_model_id, var_dataset)
#'
#'
#' ####################  PredictWithModelCSV  ####################
#'
#' library(openapi)
#' var_model_id <- 0 # integer | The ID of the model to use for prediction
#' var_dataset_csv <- DatasetCSV$new(DatasetType$new(), "inputFile_example", 123, c(TODO), "CREATED", "failureReason_example", 123, "modelName_example", "executedAt_example", "executionFinishedAt_example", "createdAt_example", "updatedAt_example") # DatasetCSV |
#'
#' #Predict using CSV with Model
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' api_instance$PredictWithModelCSV(var_model_id, var_dataset_csv)
#'
#'
#' ####################  SearchModels  ####################
#'
#' library(openapi)
#' var_query <- "query_example" # character |
#' var_page <- 0 # integer |  (Optional)
#' var_size <- 10 # integer |  (Optional)
#'
#' #Search for models
#' api_instance <- ModelApi$new()
#'
#' # Configure HTTP bearer authorization: bearerAuth
#' api_instance$api_client$bearer_token <- Sys.getenv("BEARER_TOKEN")
#'
#' # to save the result into a file, simply add the optional `data_file` parameter, e.g.
#' # result <- api_instance$SearchModels(var_query, page = var_page, size = var_sizedata_file = "result.txt")
#' result <- api_instance$SearchModels(var_query, page = var_page, size = var_size)
#' dput(result)
#'
#'
#' }
#' @importFrom R6 R6Class
#' @importFrom base64enc base64encode
#' @keywords internal
ModelApi <- R6::R6Class(
  "ModelApi",
  public = list(
    api_client = NULL,

    #' @description
    #' Initialize a new ModelApi.
    #'
    #' @param api_client An instance of API client.
    initialize = function(api_client) {
      if (!missing(api_client)) {
        self$api_client <- api_client
      } else {
        self$api_client <- ApiClient$new()
      }
    },

    #' @description
    #' Create a new model
    #'
    #' @param model
    #' @param ... Other optional arguments
    #'
    #' @return void
    CreateModel = function(model, ...) {
      local_var_response <- self$CreateModelWithHttpInfo(model, ...)

      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        return(local_var_response)
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        return(local_var_response)
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        return(local_var_response)
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        return(local_var_response)
      }
    },

    #' @description
    #' Create a new model
    #'
    #' @param model
    #' @param ... Other optional arguments
    #'
    #' @return API response (void) with additional information such as HTTP status code, headers
    CreateModelWithHttpInfo = function(model, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

      if (missing(`model`)) {
        stop("Missing required parameter `model`.")
      }


      if (!is.null(`model`)) {
        local_var_body <- jsonlite::toJSON(`model`$toJSON(), auto_unbox = TRUE, digits = NA)
      } else {
        body <- NULL
      }

      local_var_url_path <- "/v1/models"
      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list()

      # The Content-Type representation header
      local_var_content_types <- list("application/json")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "POST",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)
      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        api_url <-local_var_resp$headers$Location
        model_id <- sub(".*/models/([0-9]+).*", "\\1", api_url)
        dashboard_url <- paste0("https://app.jaqpot.org/dashboard/models/", model_id, "/")
        
        print(paste0("Model has been deployed on the Jaqpot platform. Visit model at: ", dashboard_url))
        #local_var_resp$content <- NULL
        return(local_var_resp)
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
        print(paste0("Error, status code ", local_var_resp$status_code))
        return(local_var_resp)
        } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
        print(paste0("API client error, status code ", local_var_resp$status_code))
        return(local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
          print(paste0("API server error, status code ", local_var_resp$status_code))
        }
        return(local_var_resp)
      }
    },

    #' @description
    #' Delete a Model
    #'
    #' @param id The ID of the model to delete
    #' @param ... Other optional arguments
    #'
    #' @return void
    DeleteModelById = function(id, ...) {
      local_var_response <- self$DeleteModelByIdWithHttpInfo(id, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Delete a Model
    #'
    #' @param id The ID of the model to delete
    #' @param ... Other optional arguments
    #'
    #' @return API response (void) with additional information such as HTTP status code, headers
    DeleteModelByIdWithHttpInfo = function(id, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

      if (missing(`id`)) {
        stop("Missing required parameter `id`.")
      }


      local_var_url_path <- "/v1/models/{id}"
      if (!missing(`id`)) {
        local_var_url_path <- gsub("\\{id\\}", URLencode(as.character(`id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list()

      # The Content-Type representation header
      local_var_content_types <- list()

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "DELETE",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        local_var_resp$content <- NULL
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    },

    #' @description
    #' Get a legacy model
    #'
    #' @param id The ID of the model to retrieve
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return Model
    GetLegacyModelById = function(id, data_file = NULL, ...) {
      local_var_response <- self$GetLegacyModelByIdWithHttpInfo(id, data_file = data_file, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Get a legacy model
    #'
    #' @param id The ID of the model to retrieve
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return API response (Model) with additional information such as HTTP status code, headers
    GetLegacyModelByIdWithHttpInfo = function(id, data_file = NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

      if (missing(`id`)) {
        stop("Missing required parameter `id`.")
      }


      local_var_url_path <- "/v1/models/legacy/{id}"
      if (!missing(`id`)) {
        local_var_url_path <- gsub("\\{id\\}", URLencode(as.character(`id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list()

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Model", loadNamespace("openapi")),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    },

    #' @description
    #' Get a Model
    #'
    #' @param id The ID of the model to retrieve
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return Model
    GetModelById = function(id, data_file = NULL, ...) {
      local_var_response <- self$GetModelByIdWithHttpInfo(id, data_file = data_file, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Get a Model
    #'
    #' @param id The ID of the model to retrieve
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return API response (Model) with additional information such as HTTP status code, headers
    GetModelByIdWithHttpInfo = function(id, data_file = NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

      if (missing(`id`)) {
        stop("Missing required parameter `id`.")
      }


      local_var_url_path <- "/v1/models/{id}"
      if (!missing(`id`)) {
        local_var_url_path <- gsub("\\{id\\}", URLencode(as.character(`id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list()

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Model", loadNamespace("openapi")),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    },

    #' @description
    #' Get paginated models
    #'
    #' @param page (optional) No description (default value: 0)
    #' @param size (optional) No description (default value: 10)
    #' @param sort (optional) No description
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return GetModels200Response
    GetModels = function(page = 0, size = 10, sort = NULL, data_file = NULL, ...) {
      local_var_response <- self$GetModelsWithHttpInfo(page, size, sort, data_file = data_file, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Get paginated models
    #'
    #' @param page (optional) No description (default value: 0)
    #' @param size (optional) No description (default value: 10)
    #' @param sort (optional) No description
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return API response (GetModels200Response) with additional information such as HTTP status code, headers
    GetModelsWithHttpInfo = function(page = 0, size = 10, sort = NULL, data_file = NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE




      query_params[["page"]] <- `page`

      query_params[["size"]] <- `size`

      # explore
      for (query_item in `sort`) {
        query_params[["sort"]] <- c(query_params[["sort"]], list(`sort` = query_item))
      }

      local_var_url_path <- "/v1/user/models"
      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list()

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "GetModels200Response", loadNamespace("openapi")),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    },

    #' @description
    #' Get paginated shared models
    #'
    #' @param page (optional) No description (default value: 0)
    #' @param size (optional) No description (default value: 10)
    #' @param sort (optional) No description
    #' @param organization_id (optional) No description
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return GetModels200Response
    GetSharedModels = function(page = 0, size = 10, sort = NULL, organization_id = NULL, data_file = NULL, ...) {
      local_var_response <- self$GetSharedModelsWithHttpInfo(page, size, sort, organization_id, data_file = data_file, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Get paginated shared models
    #'
    #' @param page (optional) No description (default value: 0)
    #' @param size (optional) No description (default value: 10)
    #' @param sort (optional) No description
    #' @param organization_id (optional) No description
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return API response (GetModels200Response) with additional information such as HTTP status code, headers
    GetSharedModelsWithHttpInfo = function(page = 0, size = 10, sort = NULL, organization_id = NULL, data_file = NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE





      query_params[["page"]] <- `page`

      query_params[["size"]] <- `size`

      # explore
      for (query_item in `sort`) {
        query_params[["sort"]] <- c(query_params[["sort"]], list(`sort` = query_item))
      }

      query_params[["organizationId"]] <- `organization_id`

      local_var_url_path <- "/v1/user/shared-models"
      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list()

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "GetModels200Response", loadNamespace("openapi")),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    },

    #' @description
    #' Partially update specific fields of a model
    #'
    #' @param id
    #' @param partially_update_model_request
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return Model
    PartiallyUpdateModel = function(id, partially_update_model_request, data_file = NULL, ...) {
      local_var_response <- self$PartiallyUpdateModelWithHttpInfo(id, partially_update_model_request, data_file = data_file, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Partially update specific fields of a model
    #'
    #' @param id
    #' @param partially_update_model_request
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return API response (Model) with additional information such as HTTP status code, headers
    PartiallyUpdateModelWithHttpInfo = function(id, partially_update_model_request, data_file = NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

      if (missing(`id`)) {
        stop("Missing required parameter `id`.")
      }

      if (missing(`partially_update_model_request`)) {
        stop("Missing required parameter `partially_update_model_request`.")
      }



      if (!is.null(`partially_update_model_request`)) {
        local_var_body <- `partially_update_model_request`$toJSONString()
      } else {
        body <- NULL
      }

      local_var_url_path <- "/v1/models/{id}/partial"
      if (!missing(`id`)) {
        local_var_url_path <- gsub("\\{id\\}", URLencode(as.character(`id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list("application/json")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "PATCH",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "Model", loadNamespace("openapi")),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    },

    #' @description
    #' Predict with Model
    #'
    #' @param model_id The ID of the model to use for prediction
    #' @param dataset
    #' @param ... Other optional arguments
    #'
    #' @return void
    PredictWithModel = function(model_id, dataset, ...) {
      local_var_response <- self$PredictWithModelWithHttpInfo(model_id, dataset, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        return(local_var_response)
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        return(local_var_response)
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        return(local_var_response)
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        return(local_var_response)
      }
    },

    #' @description
    #' Predict with Model
    #'
    #' @param model_id The ID of the model to use for prediction
    #' @param dataset
    #' @param ... Other optional arguments
    #'
    #' @return API response (void) with additional information such as HTTP status code, headers
    PredictWithModelWithHttpInfo = function(model_id, dataset, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE
  
      if (missing(`model_id`)) {
        stop("Missing required parameter `model_id`.")
      }

      if (missing(`dataset`)) {
        stop("Missing required parameter `dataset`.")
      }



      if (!is.null(`dataset`)) {
        json_data <- `dataset`$toJSON()
        json_data$type <- gsub('"', '', json_data$type)
        local_var_body <- jsonlite::toJSON(json_data, auto_unbox = TRUE, digits = NA)
      } else {
        body <- NULL
      }
      
      local_var_url_path <- "/v1/models/{modelId}/predict"
      if (!missing(`model_id`)) {
        local_var_url_path <- gsub("\\{modelId\\}", URLencode(as.character(`model_id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list()

      # The Content-Type representation header
      local_var_content_types <- list("application/json")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "POST",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)
      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        return(local_var_resp)
        
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
        print(paste0("Error, status code ", local_var_resp$status_code))
        return(local_var_resp)
        
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
        print(paste0("API client error, status code ", local_var_resp$status_code))
        return(local_var_resp)
        
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        
        print(paste0("API server error, status code ", local_var_resp$status_code))
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        return(local_var_resp)
      }
    },

    #' @description
    #' Predict using CSV with Model
    #'
    #' @param model_id The ID of the model to use for prediction
    #' @param dataset_csv
    #' @param ... Other optional arguments
    #'
    #' @return void
    PredictWithModelCSV = function(model_id, dataset_csv, ...) {
      local_var_response <- self$PredictWithModelCSVWithHttpInfo(model_id, dataset_csv, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Predict using CSV with Model
    #'
    #' @param model_id The ID of the model to use for prediction
    #' @param dataset_csv
    #' @param ... Other optional arguments
    #'
    #' @return API response (void) with additional information such as HTTP status code, headers
    PredictWithModelCSVWithHttpInfo = function(model_id, dataset_csv, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

      if (missing(`model_id`)) {
        stop("Missing required parameter `model_id`.")
      }

      if (missing(`dataset_csv`)) {
        stop("Missing required parameter `dataset_csv`.")
      }



      if (!is.null(`dataset_csv`)) {
        local_var_body <- `dataset_csv`$toJSONString()
      } else {
        body <- NULL
      }

      local_var_url_path <- "/v1/models/{modelId}/predict/csv"
      if (!missing(`model_id`)) {
        local_var_url_path <- gsub("\\{modelId\\}", URLencode(as.character(`model_id`), reserved = TRUE), local_var_url_path)
      }

      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list()

      # The Content-Type representation header
      local_var_content_types <- list("application/json")

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "POST",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        local_var_resp$content <- NULL
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    },

    #' @description
    #' Search for models
    #'
    #' @param query
    #' @param page (optional) No description (default value: 0)
    #' @param size (optional) No description (default value: 10)
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return GetModels200Response
    SearchModels = function(query, page = 0, size = 10, data_file = NULL, ...) {
      local_var_response <- self$SearchModelsWithHttpInfo(query, page, size, data_file = data_file, ...)
      if (local_var_response$status_code >= 200 && local_var_response$status_code <= 299) {
        local_var_response$content
      } else if (local_var_response$status_code >= 300 && local_var_response$status_code <= 399) {
        local_var_response
      } else if (local_var_response$status_code >= 400 && local_var_response$status_code <= 499) {
        local_var_response
      } else if (local_var_response$status_code >= 500 && local_var_response$status_code <= 599) {
        local_var_response
      }
    },

    #' @description
    #' Search for models
    #'
    #' @param query
    #' @param page (optional) No description (default value: 0)
    #' @param size (optional) No description (default value: 10)
    #' @param data_file (optional) name of the data file to save the result
    #' @param ... Other optional arguments
    #'
    #' @return API response (GetModels200Response) with additional information such as HTTP status code, headers
    SearchModelsWithHttpInfo = function(query, page = 0, size = 10, data_file = NULL, ...) {
      args <- list(...)
      query_params <- list()
      header_params <- c()
      form_params <- list()
      file_params <- list()
      local_var_body <- NULL
      oauth_scopes <- NULL
      is_oauth <- FALSE

      if (missing(`query`)) {
        stop("Missing required parameter `query`.")
      }




      query_params[["query"]] <- `query`

      query_params[["page"]] <- `page`

      query_params[["size"]] <- `size`

      local_var_url_path <- "/v1/models/search"
      # Bearer token
      if (!is.null(self$api_client$bearer_token)) {
        header_params["Authorization"] <- paste("Bearer", self$api_client$bearer_token, sep = " ")
      }

      # The Accept request HTTP header
      local_var_accepts <- list("application/json")

      # The Content-Type representation header
      local_var_content_types <- list()

      local_var_resp <- self$api_client$CallApi(url = paste0(self$api_client$base_path, local_var_url_path),
                                 method = "GET",
                                 query_params = query_params,
                                 header_params = header_params,
                                 form_params = form_params,
                                 file_params = file_params,
                                 accepts = local_var_accepts,
                                 content_types = local_var_content_types,
                                 body = local_var_body,
                                 is_oauth = is_oauth,
                                 oauth_scopes = oauth_scopes,
                                 ...)

      if (local_var_resp$status_code >= 200 && local_var_resp$status_code <= 299) {
        # save response in a file
        if (!is.null(data_file)) {
          write(local_var_resp$response, data_file)
        }

        deserialized_resp_obj <- tryCatch(
          self$api_client$deserialize(local_var_resp$response_as_text(), "GetModels200Response", loadNamespace("openapi")),
          error = function(e) {
            stop("Failed to deserialize response")
          }
        )
        local_var_resp$content <- deserialized_resp_obj
        local_var_resp
      } else if (local_var_resp$status_code >= 300 && local_var_resp$status_code <= 399) {
        ApiResponse$new(paste("Server returned ", local_var_resp$status_code, " response status code."), local_var_resp)
      } else if (local_var_resp$status_code >= 400 && local_var_resp$status_code <= 499) {
        ApiResponse$new("API client error", local_var_resp)
      } else if (local_var_resp$status_code >= 500 && local_var_resp$status_code <= 599) {
        if (is.null(local_var_resp$response) || local_var_resp$response == "") {
          local_var_resp$response <- "API server error"
        }
        local_var_resp
      }
    }
  )
)
KinkyDesign/jaqpotr documentation built on Nov. 27, 2024, 1:20 a.m.