Categorygithub.com/modzy/sdk-go
modulepackage
0.0.7
Repository: https://github.com/modzy/sdk-go.git
Documentation: pkg.go.dev

# README

Modzy Golang SDK

Modzy Logo

Modzy's Golang SDK queries models, submits inference jobs, and returns results directly to your editor.

GitHub contributors GitHub last commit GitHub Release Date Go Report Card

The job lifecycle | API Keys | Samples | Documentation

Installation

Add the dependency

go get -u github.com/modzy/sdk-go

Get your API key

API keys are security credentials required to perform API requests to Modzy. Our API keys are composed of an ID that is split by a dot into two parts: a public and private part.

The public part is the API keys' visible part only used to identify the key and by itself, it’s unable to perform API requests.

The private part is the public part's complement and it’s required to perform API requests. Since it’s not stored on Modzy’s servers, it cannot be recovered. Make sure to save it securely. If lost, you can replace the API key.

Find your API key in your user profile. To get your full API key click on "Get key":

get key

Initialize

Once you have a model and version identified, get authenticated with your API key.

client := modzy.NewClient("http://url.to.modzy/api").WithAPIKey("API Key")

Basic usage

Browse models

Modzy’s Marketplace includes pre-trained and re-trainable AI models from industry-leading machine learning companies, accelerating the process from data to value.

The Model service drives the Marketplace and can be integrated with other applications, scripts, and systems. It provides routes to list, search, and filter model and model-version details.

List models:

out, err := client.Models().ListModels(ctx, input)
if err != nil {
	return err
}
for _, modelSummary := range out.Models {
	fmt.Println("Model: ", modelSummary)
}

Tags help categorize and filter models. They make model browsing easier.

List tags:

out, err := client.Models().GetTags(ctx)
if err != nil {
    return err
}
for _, tag := range out.Tags {
    fmt.Println("Tag: ", tag)
}

List models by tag:

out, err := client.Models().GetTagModels(ctx)
if err != nil {
    return err
}
for _, model := range out.Models {
    fmt.Println("Model: ", model)
}

Get a model's details

Models accept specific input file MIME types. Some models may require multiple input file types to run data accordingly. In this sample, we use a model that requires text/plain.

Models require inputs to have a specific input name declared in the job request. This name can be found in the model’s details. In this sample, we use a model that requires input.txt.

Additionally, users can set their own input names. When multiple input items are processed in a job, these names are helpful to identify and get each input’s results. In this sample, we use a model that requires input-1 and input-2.

Get a model's details:

out, err := client.Models().GetModelDetails(ctx, &modzy.GetModelDetailsInput{ModelID: "ed542963de"})
if err != nil {
    return err
}
fmt.Println("Model: ", out.Details)

Model specific sample requests are available in the version details and in the Model Details page.

Get version details:

out, err := client.Models().GetModelVersionDetails(ctx, &modzy.GetModelVersionDetailsInput{ModelID: "ed542963de", Version: "0.0.27"})
if err != nil {
    return err
}
// then you'll get all the details about the specific model version
fmt.Printf("ModelVersion Details %s\n", out.Details)
// Probably the more interesting are the ones related with the inputs and outputs of the model
fmt.Println("  inputs:")
for _, input := range out.Details.Inputs {
    fmt.Printf(
        "    key %s, type %s, description: %s\n", input.Name, input.AcceptedMediaTypes, input.Description
    )
}
fmt.Println("  outputs:")
for _, output := range out.Details.Outputs {
    fmt.Printf(
        "    key %s, type %s, description: %s\n", output.Name, output.MediaType, output.Description
    )
}

Submit a job and get results

A job is the process that sends data to a model, sets the model to run the data, and returns results.

Modzy supports several input types such as text, embedded for Base64 strings, aws-s3 and aws-s3-folder for inputs hosted in buckets, and jdbc for inputs stored in databases. In this sample, we use text.

Here are samples to submit jobs with embedded, aws-s3, aws-s3-folder, and jdbc input types.

Submit a job with the model, version, and input items:

submitResponse, err := client.Jobs().SubmitJobText(ctx, &modzy.SubmitJobTextInput{
    ModelIdentifier:"ed542963de",
    ModelVersion:"0.0.27",
    Inputs:map[string]string{
        "my-input": {
            "input.txt": "Modzy is great!"
        }
    }
})

Hold until the inference is complete and results become available:

jobDetails, err := submitResponse.WaitForCompletion(ctx, 20*time.Second)

Get the results:

Results are available per input item and can be identified with the name provided for each input item upon job request. You can also add an input name to the route and limit the results to any given input item.

Jobs requested for multiple input items may have partial results available prior to job completion.

results, err := jobDetails.GetResults(ctx)

Fetch errors

Errors may arise for different reasons. Fetch errors to know what is their cause and how to fix them.

ErrorDescription
ModzyHTTPErrorWrapper for different errors, check code, message, url attributes.

Submitting jobs:

submitResponse, err := client.Jobs().SubmitJobText(ctx, &modzy.SubmitJobTextInput{
	ModelIdentifier="ed542963de", 
	ModelVersion="0.0.27", 
	Inputs=map[string]string{
		"my-input": {
			"input.txt": "Modzy is great!"
		}
    }
})
if err != nil {
    log.Fatalf("The job submission fails with code %s and message %s", err.Status, err.Message)
    return
}

Features

Modzy supports batch processing, explainability, and model drift detection.

APIs

Here is a list of Modzy APIs. To see all the APIs, check our Documentation.

FeatureCodeApi route
List modelsclient.Models().ListModels()api/models
Get model detailsclient.Models().GetModelDetails()api/models/:model-id
List models by nameclient.Models().GetModelDetailsByName()api/models
List models by tagsclient.Models().GetTagsModels()api/models/tags/:tag-id
Get related modelsclient.Models().GetRelatedModels()api/models/:model-id/related-models
Get a model's versionsclient.Models().ListModelVersions()api/models/:model-id/versions
Get version detailsclient.Models().GetModelVersionsDetails()api/models/:model-id/versions/:version-id
List tagsclient.Models().ListTags()api/models/tags
Submit a Job (Text)client.Jobs().SubmitJobText()api/jobs
Submit a Job (Embedded)client.Jobs().SubmitJobEmbedded()api/jobs
Submit a Job (AWS S3)client.Jobs().SubmitJobS3()api/jobs
Submit a Job (JDBC)client.Jobs().SubmitJobJDBC()api/jobs
Cancel a joblient.Jobs().CancelJob()api/jobs/:job-id
Hold until inference is completeclient.Jobs().WaitForJobCompletion()api/jobs/:job-id
Get job detailsclient.Jobs().GetJobDetails()api/jobs/:job-id
Get resultsclient.Jobs().getJobResults()api/results/:job-id
List the job historyclient.Jobs().GetJobsHistory()api/jobs/history

Samples

Check out our samples for details on specific use cases.

To run samples:

Set the base url and api key in each sample file:

// TODO: set the base url of modzy api and you api key
client := modzy.NewClient("http://url.to.modzy/api").WithAPIKey("API Key")

Or follow the instructions here to learn more.

And then, you can:

$ go run samples/models/main.go

Contributing

We are happy to receive contributions from all of our users. Check out our contributing file to learn more.

Code of conduct

Contributor Covenant

# Packages

Package model contains types as defined by the http api.
No description provided by the author

# Functions

No description provided by the author
No description provided by the author
NewClient will create a standard client for the given baseURL.
No description provided by the author
NewPaging creates a PagingInput which allows you to set the paging, sorting and filtering information for a List request.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithHTTPClient allows providing a custom underlying http client.
WithHTTPDebugging will trigger logrus debug messages to be emitted with the raw request and response information.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
JobStatus constants for known statuses.
JobStatus constants for known statuses.
JobStatus constants for known statuses.
JobStatus constants for known statuses.
JobStatus constants for known statuses.
JobStatus constants for known statuses.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
I see "prefix" in the docs -- what does that mean?.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
PrometheusMetricTypeCPUAvailable - The cluster’s total number of available CPU cores.
PrometheusMetricTypeCPUCurrentUsage - cpu-requested / cpu-available.
PrometheusMetricTypeCPUOverallUsage - cpu-used / cpu-available.
PrometheusMetricTypeCPURequest - The number of cores requested by a container.
PrometheusMetricTypeCPUUsed - The total amount of “system” time + the total amount of “user” time.
PrometheusMetricTypeMemoryAvailable - A node’s total allocatable memory bytes.
PrometheusMetricTypeMemoryOverallUsage - memory-used / memory-available.
PrometheusMetricTypeMemoryRequested - The number of memory bytes requested by a container.
PrometheusMetricTypeMemoryUsed - The current memory usage in bytes, it includes all memory regardless of when it was accessed.
No description provided by the author
No description provided by the author

# Variables

AppFs is exposed for possible mocking.
Known errors.
Known errors.
Known errors.
Known errors.
Known errors.
Known errors.
Known errors.

# Structs

AccountingClientFake is meant to help in mocking the AccountingClient interface easily for unit testing.
No description provided by the author
No description provided by the author
No description provided by the author
ClientFake is meant to help in mocking the Client interface easily for unit testing.
DashboardClientFake is meant to help in mocking the DashboardClient interface easily for unit testing.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetAlertDetailsInput -.
GetAlertDetailsOutput -.
GetAlertsInput -.
GetAlertsOutput -.
GetDataProcessedInput - The default and minimum accepted time between BtartDate and EndDate is 7 days.
No description provided by the author
GetEntitlementsOutput -.
GetJobDetailsInput -.
GetJobDetailsOutput -.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetModelVersionDetailsInput -.
GetModelVersionDetailsOutput -.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GetPredictionsMadeInput - The default and minimum accepted time between BtartDate and EndDate is 7 days.
No description provided by the author
GetProcessingModelsOutput -.
No description provided by the author
No description provided by the author
GetPrometheusMetricInput - The default and minimum accepted time between startDate and endDate is 7 days.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
JobsClientFake is meant to help in mocking the JobsClient interface easily for unit testing.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
ModelsClientFake is meant to help in mocking the ModelsClient interface easily for unit testing.
ModzyHTTPError contains additional error information as returned by the http API.
PagingInput -.
No description provided by the author
ResourcesClientFake is meant to help in mocking the ResourcesClient interface easily for unit testing.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author
JobActions are a collection shortcut methods when dealing with a single job.
No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
FileInputEncodable is a data input that can be provided when using Jobs().SubmitJobFile(...).
No description provided by the author
No description provided by the author
ListAccountingUsersFilterField are known field names that can be used when filtering the jobs history.
ListJobsHistoryFilterField are known field names that can be used when filtering the jobs history.
ListJobsHistorySortField are known field names that can be used when sorting the jobs history.
ListModelsFilterField are known field names that can be used when filtering the models list.
ListModelVersionsFilterField are known field names that can be used when filtering the model versions list.
ListProjectsFilterField are known field names that can be used when filtering the jobs history.
No description provided by the author
S3Inputable is a data input that can be provided when using Jobs().SubmitJobS3(...).
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
URIEncodable is a data input that can be provided when using Jobs().SubmitJobEmbedded(...).
No description provided by the author