TypeScript
The TypeScript version of the SDK permits you to write browser or server-side code to send jobs to the DeepSquare Grid. Whether you are building a website that launches a parallelized deep learning training, or you are implementing an API, the DeepSquare TypeScript SDK provides you with the tools and flexibility needed to develop software using the DeepSquare Grid.
Getting started
The package is available on NPM. You can use your favorite package manager to install the SDK:
npm install @deepsquare/deepsquare-client
# OR
pnpm add @deepsquare/deepsquare-client
# OR
yarn add @deepsquare/deepsquare-client
# OR
bun install @deepsquare/deepsquare-client
Since the DeepSquare client use Viem, a lightweight, type-safe Ethereum runtime, install it with:
npm install viem
# OR
pnpm add viem
# OR
yarn add viem
# OR
bun install viem
You can use it in your project like this:
import DeepSquareClient, { FormatJobStatus, isJobTerminated } from '@deepsquare/deepsquare-client';
import { createLoggerClient } from '@deepsquare/deepsquare-client/grpc/node';
import { parseEther, type Hex } from 'viem';
async function main() {
// Instantiate the DeepSquareClient
const deepSquareClient = DeepSquareClient.withPrivateKey(
process.env.PRIVATE_KEY as Hex,
createLoggerClient,
process.env.METASCHEDULER_ADDR as Hex,
);
// Worflow
const myJob = {
resources: {
tasks: 1,
gpus: 0,
cpusPerTask: 1,
memPerCpu: 1024,
},
enableLogging: true,
steps: [
{
name: 'hello world',
run: {
command: 'echo "Hello World"',
},
},
],
};
// 'Allowance' lets DeepSquare use a set amount of your tokens to pay for jobs, like a spending limit.
// DeepSquare can only use up to the limit you set, ensuring control and security over your wallet.
const depositAmount = parseEther('1000');
await deepSquareClient.setAllowance(depositAmount);
// Launch the job
// The 'credits' specify how much of your allowance is used for a particular job. For instance,
// if you set an allowance of 1000 and use 100 credits for a job, you'll still have 900 in allowance
// for future jobs, no need to set a new allowance until your total credits exceed it.
const credits = parseEther('1000');
const jobId = await deepSquareClient.submitJob(myJob, 'myJob', credits);
}
main();
See references for more examples.
References
The source code of the SDK is accessible on the Git repository github.com/deepsquare-io/deepsquare-client.
Examples of usage of the SDK are available in the examples
directory.
Contributing
Everyone is welcome to contribute code via pull requests, to file issues on GitHub, to help triage, reproduce, or fix bugs that people have filed, to add to our documentation, or to help out in any other way.