0.0.12 • Published 2 years ago

@instill-ai/typescript-sdk v0.0.12

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

Overview

Typescript SDK for Instill AI products

Unix Build Status NPM License NPM Version NPM Downloads

!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

Setup

Requirements

  • Node 16+
  • npm 7+ | pnpm 6+ | yarn 1+

installation

npm i @instill-ai/typescript-sdk
yarn add @instill-ai/typescript-sdk
pnpm add @instill-ai/typescript-sdk

Usage:

// node.js
const InstillClient = require("@instill-ai/typescript-sdk").default;

// next.js
import InstillClient from "@instill-ai/typescript-sdk";

config

baseUrl: string
appVersion: string
apiToken: string

Example app templetes

local

import { useEffect, useState } from "react";
import InstillClient, {
  Nullable,
  User,
} from "@instill-ai/typescript-sdk";

export default function TypescriptSdkDemo() {
  const [user, setUser] = useState<User[]>([]);

  const client = new InstillClient(
    "http://localhost:8080",
    "v1alpha",
    "<your_api_token>" // get console API token from `http://localhost:3000/settings`
  );

  useEffect(() => {
    client.Auth.getUserQuery()
      .then((data: any) => {
        console.log("data", data);
        setUser(data);
      })
      .catch((error: any) => {
        console.log("error", error);
      });
  }, []);

  return (
    <>
      <h1>User Data</h1>
      <pre style={{ backgroundColor: "white" }}>
        {JSON.stringify(user, null, 4)}
      </pre>
    </>
  );
}

With Token

import { useEffect, useState } from "react";
import InstillClient, {
  Nullable,
  Pipeline,
  User,
} from "@instill-ai/typescript-sdk";

export default function TypescriptSdkDemo() {
  const [pipelines, setPipelines] = useState<Pipeline[]>([]);
  const [user, setUser] = useState<User[]>([]);

  const client = new InstillClient(
    "https://api.instill.tech",
    "v1alpha",
    "<your_api_token>" // console API token
  );

  useEffect(() => {
    client.Auth.getUserQuery()
      .then((data: any) => {
        console.log("data", data);
        setUser(data);
      })
      .catch((error: any) => {
        console.log("error", error);
      });

    client.Pipeline.listPipelinesQuery({
      pageSize: null,
      nextPageToken: null,
    })
      .then((data: any) => {
        console.log("data", data);
        setPipelines(data);
      })
      .catch((error: any) => {
        console.log("error", error);
      });
  }, []);

  return (
    <>
      <h1>User Data</h1>
      <pre style={{ backgroundColor: "white" }}>
        {JSON.stringify(user, null, 4)}
      </pre>

      <h1>Pipelines List</h1>
      <pre style={{ backgroundColor: "white" }}>
        {JSON.stringify(pipelines, null, 4)}
      </pre>
    </>
  );
}

Next APP

Node APP

API Reference

Pipelines

create Pipeline

userName : check your userName: https://console.instill.tech/settings

client.PipelineClient.createUserPipelineMutation("<userName>",
  {
    "id": "overseas-blue-lobster",
    "recipe": {
      "version": "v1alpha",
      "components": [
        {
          "id": "start",
          "resource_name": "",
          "configuration": {
            "metadata": {
              "text": {
                "instillFormat": "string",
                "type": "string",
                "title": "text"
              }
            }
          },
          "definition_name": "operator-definitions/op-start"
        },
        {
          "id": "end",
          "resource_name": "",
          "configuration": {
            "metadata": {
              "output": {
                "title": "output"
              }
            },
            "input": {
              "output": "{ai_1.output.texts}"
            }
          },
          "definition_name": "operator-definitions/op-end"
        },
        {
          "id": "ai_1",
          "resource_name": "users/namananand-instill-ai/connector-resources/ai2",
          "configuration": {
            "task": "TASK_TEXT_GENERATION",
            "input": {
              "prompt": "{start.text}",
              "model": "gpt-3.5-turbo"
            }
          },
          "definition_name": "connector-definitions/ai-openai"
        }
      ]
    }
  }
).then((response) => {
  console.log(response.data)
})
.catch(error => {
  console.log(error)
})
functionparams
listPipelinesQuerypageSize, nextPageToken
listUserPipelinesQuerypageSize, nextPageToken, userName
getUserPipelineQuerypipelineName
ListUserPipelineReleasesQueryuserName, pipelineName, pageSize, nextPageToken
getUserPipelineReleaseQuerypipelineReleaseName
watchUserPipelineReleaseQuerypipelineReleaseName
createUserPipelineMutationuserName, payload
updateUserPipelineMutationpayload
deleteUserPipelineMutationpipelineName
renameUserPipelineMutationpayload
createUserPipelineReleaseMutationpipelineName, payload
updateUserPipelineReleaseMutationpipelineReleaseName, payload
deleteUserPipelineReleaseMutationpipelineReleaseName
triggerUserPipelineActionpipelineName, payload, returnTraces
triggerAsyncUserPipelineActionpipelineName, payload, returnTraces
setDefaultUserPipelineReleaseMutationpipelineReleaseName
restoreUserPipelineReleaseMutationpipelineReleaseName
triggerUserPipelineReleaseActionpipelineReleaseName, payload, returnTraces
triggerAsyncUserPipelineReleaseActionpipelineReleaseName, payload, returnTraces

Connector

Create new connector

userName : check your userName: https://console.instill.tech/settings

query.ConnectorClient.createUserConnectorResourceMutation("<userName>",
  {
    "id": "open-ai-model-1",
    "connector_definition_name": "connector-definitions/ai-openai",
    "configuration": {
      "organization": "my-org",
      "api_key": "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"
    }
  }
).then((response) => {
  console.log(response.data)
})
.catch(error => {
  console.log(error)
})
functionparams
listConnectorResourcesQueryuserName, pageSize, nextPageToken, filter
listUserConnectorResourcesQuerypageSize, nextPageToken, filter
listConnectorDefinitionsQueryconnectorDefinitionName
getConnectorDefinitionQueryconnectorDefinitionName
getUserConnectorResourceQueryconnectorDefinitionName
watchUserConnectorResourceconnectorResourceName
createUserConnectorResourceMutationuserName, payload
deleteUserConnectorResourceMutationpayload
updateUserConnectorResourceMutationpayload
renameUserConnectorResourcepayload
testUserConnectorResourceConnectionActionconnectorDefinitionName
connectUserConnectorResourceActionconnectorDefinitionName
disconnectUserConnectorResourceActionconnectorDefinitionName

Metric

functionparams
listPipelineTriggerRecordsQuerypageSize, nextPageToken, filter
listTriggeredPipelineQuerypageSize, nextPageToken, filter
listTriggeredPipelineChartQuerypageSize, nextPageToken, filter

Model

functionparams
getModelDefinitionQuerymodelDefinitionName
listModelDefinitionsQuerypageSize, nextPageToken
getUserModelQuerymodelName
listModelsQuerypageSize, nextPageToken
listUserModelsQueryuserName, pageSize, nextPageToken
getUserModelReadmeQuerymodelName
watchUserModelmodelName
createUserModelMutationuserName, payload
updateModelMutationpayload
deleteUserModelMutationmodelName
deployUserModelActionmodelName
undeployUserModeleActionmodelName

Operation

functionparams
getOperationQueryoperationName
checkUntilOperationIsDoenoperationName

Mgmt

create API token

client.AuthClient.createApiTokenMutation({
  "id": "aa",
  "ttl": -1
}).then((response) => {
  console.log(response.data)
})
.catch(error => {
  console.log(error)
})
functionparams
getUserQuery
checkUserIdExistid
getApiTokenQuerytokenName
listApiTokensQuerypageSize, nextPageToken
updateUserMutationpayload
createApiTokenMutationpayload
deleteApiTokenMutationtokenName

Contribution Guidelines:

Please refer to the Contributing Guidelines for more details.

Release Notes:

Release

Genrate proto-ts

  • run ./generate_proto.sh
  • it will genrate protobuf into dist/protogen-ts

Support:

Contact details for help and support resources. This list isn't exhaustive but covers major aspects usually included in most SDK design documents.

0.0.12

2 years ago

0.0.11

2 years ago

0.0.11-rc.0

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.8-rc.13

2 years ago

0.0.8-rc.12

2 years ago

0.0.8-rc.11

2 years ago

0.0.8-rc.10

2 years ago

0.0.8-rc.9

2 years ago

0.0.8-rc.8

2 years ago

0.0.8-rc.7

2 years ago

0.0.8-rc.6

2 years ago

0.0.8-rc.5

2 years ago

0.0.8-rc.4

2 years ago

0.0.8-rc.3

2 years ago

0.0.8-rc.2

2 years ago

0.0.8-rc.1

2 years ago

0.0.8-rc.0

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.3-rc.0

2 years ago

0.0.2

2 years ago

0.0.2-rc.0

2 years ago

0.0.1

2 years ago

1.0.2

2 years ago