Git Product home page Git Product logo

typescript-sdk's Introduction

Overview

Typescript SDK for Instill AI products

The code now lives in https://github.com/instill-ai/console/tree/main/packages/sdk

Important

This SDK tool is under heavy development!!
Currently there has yet to be a stable version release, please feel free to open any issue regarding this SDK in our community repo

Requirements

  • Node 18+

Installation

npm i instill-sdk
yarn add instill-sdk
pnpm add instill-sdk

Usage

Import

import { InstillAPIClient } from "instill-sdk";

const client = new InstillAPIClient({
  // Note: Model related endpoint is still in v1alpha version
  baseURL: "https://api.instill.tech/v1beta",
  apiKey: "<YOUR_API_KEY>"
})

Useful helper for you to reuse the client instance

import { InstillAPIClient } from "instill-sdk";

let instillAPIClient: InstillAPIClient | null = null;

export function getInstillAPIClient() {
  if (!instillAPIClient) {
    const baseURL = `${
      process.env.NEXT_SERVER_API_GATEWAY_URL ??
      env("NEXT_PUBLIC_API_GATEWAY_URL")
    }/${env("NEXT_PUBLIC_GENERAL_API_VERSION")}`;

    instillAPIClient = new InstillAPIClient({
      // Note: Model related endpoint is still in v1alpha version
      baseURL: "https://api.instill.tech/v1beta", 
      apiToken: "<YOUR_API_KEY>"
    });
  }

  return instillAPIClient;
}

Example: Get all accessible pipelines

export async function getAccessiblePipelines(){
  try {
    const pipelines = await client.vdp.pipeline.listAccessiblePipelines({

      // This means you don't want to get the paginated response, instead,
      // you will get all the pipelines in one go
      enablePagination: false,

      // This means you want to have the full pipeline data object
      view: "VIEW_FULL",
    });

    return Promise.resolve(pipelines)
  } catch(error){
    return Promise.reject(error)
  }
}

Example: Get all models under your namespace

Let's say your namespace is users/instill-ai

export async function getNamespaceModels(){
  try {
    const models = await client.model.listNamespaceModels({
      namespaceName: "users/instill-ai",
      enablePagination: false,
      view: "VIEW_FULL"
    });

    return Promise.resolve(models)
  } catch(error){
    return Promise.reject(error)
  }
}

typescript-sdk's People

Contributors

donch1989 avatar droplet-bot avatar eiffelfly avatar iamnamananand996 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.