Skip to content

Commit

Permalink
chore: namananand/ins 1901 example documentation for sdk (#3)
Browse files Browse the repository at this point in the history
Because

- example documentation for sdk

This commit

- example documentation for sdk
  • Loading branch information
iamnamananand996 authored Sep 22, 2023
1 parent 38e0a39 commit b7e6255
Show file tree
Hide file tree
Showing 13 changed files with 3,927 additions and 67 deletions.
34 changes: 26 additions & 8 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
# Contributing Guidelines

Hello! Thanks for your interest in contributing to the codebase.
We appreciate your contribution to this amazing project! Any form of engagement is welcome, including but not limiting to

## How to contribute
- feature request
- documentation wording
- bug report
- roadmap suggestion
- ...and so on!

TBD
Please refer to the [community contributing section](https://github.com/instill-ai/community#contributing) for more details.

## Development and codebase contribution

## Submitting a pull request
Before delving into the details to come up with your first PR, please familiarise yourself with the project structure of [Instill Core](https://github.com/instill-ai/community#instill-core).

To make an efficient review process, we very much appreciate if the PR commits
### Sending PRs

- follow the [conventional commits guidelines](https://www.conventionalcommits.org/),
- follow the [7 rules of commit messages](https://chris.beams.io/posts/git-commit/), and
- are rearranged to squash trivial commits together (use [git rebase](http://gitready.com/advanced/2009/03/20/reorder-commits-with-rebase.html)).
Please take these general guidelines into consideration when you are sending a PR:

1. **Fork the Repository:** Begin by forking the repository to your GitHub account.
2. **Create a New Branch:** Create a new branch to house your work. Use a clear and descriptive name, like `<your-github-username>/<what-your-pr-about>`.
3. **Make and Commit Changes:** Implement your changes and commit them. We encourage you to follow these best practices for commits to ensure an efficient review process:
- Adhere to the [conventional commits guidelines](https://www.conventionalcommits.org/) for meaningful commit messages.
- Follow the [7 rules of commit messages](https://chris.beams.io/posts/git-commit/) for well-structured and informative commits.
- Rearrange commits to squash trivial changes together, if possible. Utilize [git rebase](http://gitready.com/advanced/2009/03/20/reorder-commits-with-rebase.html) for this purpose.
4. **Push to Your Branch:** Push your branch to your GitHub repository: `git push origin feat/<your-feature-name>`.
5. **Open a Pull Request:** Initiate a pull request to our repository. Our team will review your changes and collaborate with you on any necessary refinements.

When you are ready to send a PR, we recommend you to first open a `draft` one. This will trigger a bunch of `integration-test` [workflows](https://github.com/instill-ai/model/tree/main/.github/workflows) running a thorough test suite on multiple platforms. After the tests are done and passed, you can now mark the PR `open` to notify the codebase owners to review. We appreciate your endeavour to pass the integration test for your PR to make sure the sanity with respect to the entire scope of **Instill Core**.

## Last words

Your contributions make a difference. Let's build something amazing together!
130 changes: 117 additions & 13 deletions ReadMe.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,134 @@
### installation

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

## Usage Examples:

Gives real-life examples showing how to utilise the SDK.
```
// node.js
const instillAI = require("@instill-ai/typescript-sdk");
## Error Handling:
// next.js
import { Pipeline, listPipelinesQuery } from "@instill-ai/typescript-sdk";
Explains common errors and ways to resolve them.
```

## Integration Guide:

Guidance on how to incorporate the SDK into other applications.
## API Reference

## Guidelines:
### Pipelines

Recommendations for best practices while using the SDK.
| function | params | response |
| :------------------- | :---------------------------------------: | ----------------------: |
| listPipelinesQuery | pageSize, nextPageToken, accessToken | |
| listUserPipelinesQuery | pageSize, nextPageToken, accessToken, userName | |
| getUserPipelineQuery | pipelineName, accessToken | |
| ListUserPipelineReleasesQuery | userName, pipelineName, pageSize, nextPageToken, accessToken | |
| getUserPipelineReleaseQuery | pipelineReleaseName, accessToken | |
| watchUserPipelineReleaseQuery | pipelineReleaseName, accessToken | |
| createUserPipelineMutation | userName, payload, accessToken | |
| updateUserPipelineMutation | payload, accessToken | |
| deleteUserPipelineMutation | pipelineName, accessToken | |
| renameUserPipelineMutation | payload, accessToken | |
| createUserPipelineReleaseMutation | pipelineName, payload, accessToken | |
| updateUserPipelineReleaseMutation | pipelineReleaseName, payload, accessToken | |
| deleteUserPipelineReleaseMutation | pipelineReleaseName, accessToken | |
| triggerUserPipelineAction | pipelineName, payload, accessToken, returnTraces | |
| triggerAsyncUserPipelineAction | pipelineName, payload, accessToken, returnTraces | |
| setDefaultUserPipelineReleaseMutation | pipelineReleaseName, accessToken | |
| restoreUserPipelineReleaseMutation | pipelineReleaseName, accessToken | |
| triggerUserPipelineReleaseAction | pipelineReleaseName, payload, accessToken, returnTraces | |
| triggerAsyncUserPipelineReleaseAction | pipelineReleaseName, payload, accessToken, returnTraces | |

## Troubleshooting Tips:
### Connector

How to diagnose and fix problems.
| function | params | response |
| :------------------- | :-----------------------------------------------------------: | -----------------: |
| listConnectorResourcesQuery | userName, pageSize, nextPageToken, accessToken, filter | |
| listUserConnectorResourcesQuery | pageSize, nextPageToken, accessToken, filter | |
| listConnectorDefinitionsQuery | connectorDefinitionName, accessToken | |
| getConnectorDefinitionQuery | connectorDefinitionName, accessToken | |
| getUserConnectorResourceQuery | connectorDefinitionName, accessToken | |
| watchUserConnectorResource | userName, payload, accessToken | |
| createUserConnectorResourceMutation | connectorDefinitionName, accessToken | |
| deleteUserConnectorResourceMutation | payload, accessToken | |
| updateUserConnectorResourceMutation | payload, accessToken | |
| renameUserConnectorResource | payload, accessToken | |
| testUserConnectorResourceConnectionAction | connectorDefinitionName, accessToken | |
| connectUserConnectorResourceAction | connectorDefinitionName, accessToken | |
| disconnectUserConnectorResourceAction | connectorDefinitionName, accessToken | |

## License & Version Control:
### Metric

Information about licenses and updates related to the SDK.
| function | params | response |
| :------------------- | :------------------: | -----------------: |
| listPipelineTriggerRecordsQuery | pageSize, nextPageToken, accessToken, filter | |
| listTriggeredPipelineQuery | pageSize, nextPageToken, accessToken, filter | |
| listTriggeredPipelineChartQuery | pageSize, nextPageToken, accessToken, filter | |

## Release Notes:
modelDefinitionName, accessToken,
### Model

| function | params | response |
| :------------------- | :------------------: | -----------------: |
| getModelDefinitionQuery | modelDefinitionName, accessToken | |
| listModelDefinitionsQuery | pageSize, nextPageToken, accessToken | |
| getUserModelQuery | modelName, accessToken | |
| listModelsQuery | pageSize, nextPageToken, accessToken | |
| listUserModelsQuery | userName, pageSize, nextPageToken, accessToken | |
| getUserModelReadmeQuery | modelName, accessToken | |
| watchUserModel | modelName, accessToken | |
| createUserModelMutation | userName, payload, accessToken | |
| updateModelMutation | payload, accessToken | |
| deleteUserModelMutation | modelName, accessToken | |
| deployUserModelAction | modelName, accessToken | |
| undeployUserModeleAction | modelName, accessToken | |

### Operation

| function | params | response |
| :------------------- | :-----------------------------------------------------------: | -----------------: |
| getOperationQuery | operationName, accessToken | |
| checkUntilOperationIsDoen | operationName, accessToken | |

### Mgmt

| function | params | response |
| :------------------- | :------------------: | -----------------: |
| getUserQuery | accessToken | |
| checkUserIdExist | id, accessToken | |
| getApiTokenQuery | tokenName, accessToken | |
| listApiTokensQuery | pageSize, nextPageToken, accessToken | |
| updateUserMutation | payload, accessToken | |
| createApiTokenMutation | payload, accessToken | |
| deleteApiTokenMutation | tokenName, accessToken | |

Details about new releases, changes, bug fixes, improvements, known issues.
## Error Handling:

Explains common errors and ways to resolve them.

## Integration Guide:
### Next APP
- [next-app](./examples/next-app/)
### Node APP
- [node-app](./examples/node-app/)

Guidance on how to incorporate the SDK into other applications.

## Contribution Guidelines:

Please refer to the [Contributing Guidelines](./.github/CONTRIBUTING.md) for more details.

## Release Notes:
[Release](./CHANGELOG.md)

## Support:

Expand Down
79 changes: 46 additions & 33 deletions examples/next-app/README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,53 @@
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
## Config and installation

## Getting Started
### installation

First, run the development server:

```bash
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun run dev
```
npm i @instill-ai/typescript-sdk
```
```
yarn add @instill-ai/typescript-sdk
```
```
pnpm add @instill-ai/typescript-sdk
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.

You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.

[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.

The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.

This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.

## Learn More

To learn more about Next.js, take a look at the following resources:

- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.

You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
### config

## Deploy on Vercel
- make sure you have vdp up running, to run vdp check this [vdp](https://github.com/instill-ai/vdp)
- verify `.env`
- see the changes done in `_document.tsx` and `next.env.mjs`

The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
### Now You are ready.

Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
```
import { Pipeline, listPipelinesQuery } from "@instill-ai/typescript-sdk";
export default function TypescriptSdkDemo() {
const [pipelines, setPipelines] = useState<Pipeline[]>([]);
useEffect(() => {
// Pipeline
listPipelinesQuery({
pageSize: 6,
nextPageToken: null,
accessToken: null,
})
.then((data) => {
// response data
console.log("data", data);
setPipelines(data);
})
.catch((error) => {
// error
console.log("error", error);
});
}, []);
return (
<div>
{JSON.stringify(pipelines)}
</div>
);
}
```
10 changes: 1 addition & 9 deletions examples/next-app/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { Inter } from "next/font/google";
import { useEffect, useState } from "react";
import { Pipeline, listPipelinesQuery } from "@instill-ai/typescript-sdk";

const inter = Inter({ subsets: ["latin"] });

export default function TypescriptSdkDemo() {
const [pipelines, setPipelines] = useState<Pipeline[]>([]);
useEffect(() => {
Expand All @@ -23,11 +21,5 @@ export default function TypescriptSdkDemo() {
});
}, []);

return (
<main
className={`flex min-h-screen flex-col items-center justify-between p-24 ${inter.className}`}
>
{JSON.stringify(pipelines)}
</main>
);
return <div>{JSON.stringify(pipelines)}</div>;
}
16 changes: 16 additions & 0 deletions examples/node-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
NEXT_PUBLIC_API_VERSION=v1alpha
NEXT_PUBLIC_INSTILL_AI_USER_COOKIE_NAME=instill-ai-user
NEXT_PUBLIC_CONSOLE_EDITION=local-ce:dev
NEXT_PUBLIC_API_GATEWAY_URL=http://localhost:8080
NEXT_SERVER_API_GATEWAY_URL=http://localhost:8080
NEXT_PUBLIC_SELF_SIGNED_CERTIFICATION=false
NEXT_PUBLIC_DISABLE_CREATE_UPDATE_DELETE_RESOURCE=false
NEXT_PUBLIC_LIST_PAGE_SIZE=6
NEXT_PUBLIC_USAGE_COLLECTION_ENABLED=true
NEXT_PUBLIC_SET_SECURE_COOKIE=false
NEXT_PUBLIC_AMPLITUDE_KEY=9823fa6e3ff904bec67a8fc90db82fb9
NEXT_PUBLIC_CONSOLE_BASE_URL=http://localhost:3000
NEXT_PUBLIC_MGMT_BACKEND_BASE_URL=http://localhost:8084
NEXT_PUBLIC_PIPELINE_BACKEND_BASE_URL=http://localhost:8081
NEXT_PUBLIC_CONNECTOR_BACKEND_BASE_URL=http://localhost:8082
MODEL_BACKEND_BASE_URL=http://localhost:8083
50 changes: 50 additions & 0 deletions examples/node-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
## Config and installation

### installation

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

### config

- make sure you have vdp up running, to run vdp check this [vdp](https://github.com/instill-ai/vdp)
- verify `.env`

### Now You are ready.

```
// setup express project
const express = require("express");
const instillAI = require("@instill-ai/typescript-sdk");
require("dotenv").config(); // Load environment variables from .env file
const app = express();
const port = process.env.PORT || 5000;
// Define a route for listing pipelines using the SDK
app.get("/list-pipelines", async (req, res) => {
try {
const data = await instillAI.listPipelinesQuery({
pageSize: 6,
nextPageToken: null,
accessToken: null, // Use the environment variable
});
res.json(data);
} catch (error) {
console.error("Error:", error);
res.status(500).json({ error: "An error occurred" });
}
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
```
17 changes: 17 additions & 0 deletions examples/node-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@instill-ai/typescript-sdk": "^0.0.1",
"dotenv": "^16.3.1",
"express": "^4.18.2"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node server.js"
},
"author": "",
"license": "ISC"
}
Loading

0 comments on commit b7e6255

Please sign in to comment.