@instill-ai/typescript-sdk
v0.0.12
Published
Instill AI's Typescript SDK
Downloads
2
Readme
Overview
Typescript SDK for Instill AI products
[!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)
})
| function | params | | :------------------------------------ | :---------------------------------------------: | | listPipelinesQuery | pageSize, nextPageToken | | listUserPipelinesQuery | pageSize, nextPageToken, userName | | getUserPipelineQuery | pipelineName | | ListUserPipelineReleasesQuery | userName, pipelineName, pageSize, nextPageToken | | getUserPipelineReleaseQuery | pipelineReleaseName | | watchUserPipelineReleaseQuery | pipelineReleaseName | | createUserPipelineMutation | userName, payload | | updateUserPipelineMutation | payload | | deleteUserPipelineMutation | pipelineName | | renameUserPipelineMutation | payload | | createUserPipelineReleaseMutation | pipelineName, payload | | updateUserPipelineReleaseMutation | pipelineReleaseName, payload | | deleteUserPipelineReleaseMutation | pipelineReleaseName | | triggerUserPipelineAction | pipelineName, payload, returnTraces | | triggerAsyncUserPipelineAction | pipelineName, payload, returnTraces | | setDefaultUserPipelineReleaseMutation | pipelineReleaseName | | restoreUserPipelineReleaseMutation | pipelineReleaseName | | triggerUserPipelineReleaseAction | pipelineReleaseName, payload, returnTraces | | triggerAsyncUserPipelineReleaseAction | pipelineReleaseName, 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)
})
| function | params | | :---------------------------------------- | :---------------------------------------: | | listConnectorResourcesQuery | userName, pageSize, nextPageToken, filter | | listUserConnectorResourcesQuery | pageSize, nextPageToken, filter | | listConnectorDefinitionsQuery | connectorDefinitionName | | getConnectorDefinitionQuery | connectorDefinitionName | | getUserConnectorResourceQuery | connectorDefinitionName | | watchUserConnectorResource | connectorResourceName | | createUserConnectorResourceMutation | userName, payload | | deleteUserConnectorResourceMutation | payload | | updateUserConnectorResourceMutation | payload | | renameUserConnectorResource | payload | | testUserConnectorResourceConnectionAction | connectorDefinitionName | | connectUserConnectorResourceAction | connectorDefinitionName | | disconnectUserConnectorResourceAction | connectorDefinitionName |
Metric
| function | params | | :------------------------------ | :-----------------------------: | | listPipelineTriggerRecordsQuery | pageSize, nextPageToken, filter | | listTriggeredPipelineQuery | pageSize, nextPageToken, filter | | listTriggeredPipelineChartQuery | pageSize, nextPageToken, filter |
Model
| function | params | | :------------------------ | :-------------------------------: | | getModelDefinitionQuery | modelDefinitionName | | listModelDefinitionsQuery | pageSize, nextPageToken | | getUserModelQuery | modelName | | listModelsQuery | pageSize, nextPageToken | | listUserModelsQuery | userName, pageSize, nextPageToken | | getUserModelReadmeQuery | modelName | | watchUserModel | modelName | | createUserModelMutation | userName, payload | | updateModelMutation | payload | | deleteUserModelMutation | modelName | | deployUserModelAction | modelName | | undeployUserModeleAction | modelName |
Operation
| function | params | | :------------------------ | :-----------: | | getOperationQuery | operationName | | checkUntilOperationIsDoen | operationName |
Mgmt
create API token
client.AuthClient.createApiTokenMutation({
"id": "aa",
"ttl": -1
}).then((response) => {
console.log(response.data)
})
.catch(error => {
console.log(error)
})
| function | params | | :--------------------- | :---------------------: | | getUserQuery | | | checkUserIdExist | id | | getApiTokenQuery | tokenName | | listApiTokensQuery | pageSize, nextPageToken | | updateUserMutation | payload | | createApiTokenMutation | payload | | deleteApiTokenMutation | tokenName |
Contribution Guidelines:
Please refer to the Contributing Guidelines for more details.
Release Notes:
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.