Skip to content

Latest commit

 

History

History
144 lines (110 loc) · 3.63 KB

README.md

File metadata and controls

144 lines (110 loc) · 3.63 KB

ainize-js

A JavaScript library for the Ainize, a system for running AI models on the AI Network.

Requirements

node >= 18

Installation

// from NPM
npm install @ainize-team/ainize-js

// from Yarn
yarn add @ainize-team/ainize-js

Then import the libraries in your code:

// ES6
import Ainize from '@ainize-team/ainize-js';

// CommonJS
const Ainize = require('@ainize-team/ainize-js').default;

Create account

You should login to ainize with AI Network account before deploy the container.
If you don't have an AI Network account, you can create one with the following script.

import Ainize from '@ainize-team/ainize-js';
const wallet = Ainize.createAinAccount();
console.log(wallet);
// {
//   address: '0x44f2...985B',
//   private_key: '14ba...4e67',
//   public_key: '5fec...7784'
// }

Login

import Ainize from '@ainize-team/ainize-js';
const ainize = new Ainize(1);// 0 for testnet, 1 for mainnet. You can earn testnet AIN at https://faucet.ainetwork.ai/.
ainize.login(<YOUR_PRIVATE_KEY>);

You can also login using AIN Wallet on the web.

import Ainize from '@ainize-team/ainize-js';
const ainize = new Ainize(1);
ainize.loginWithSigner();

This feature is supported from AIN Wallet version 2.0.5 or later.

Using model

You can use a model using ainize.getModel(<MODEL_NAME>). For example, you can use the meta-llama/Llama-3.1-8B-instruct model, which runs Meta's Llama-3.1-8B-instruct model.

import Ainize from '@ainize-team/ainize-js';
const ainPrivateKey = ''; // Insert your private key here

const main = async () => {
  try {
    const ainize = new Ainize(1);
    await ainize.login(ainPrivateKey);
    const inferenceModel = await ainize.getModel('meta-llama/Llama-3.1-8B-instruct');
    const request = {
      "prompt": "Hi! How’s it going?"
    };
    const response = await inferenceModel.request(request);
    console.log(response);
    ainize.logout();
  } catch(e) {
    console.log(e);
  }
}
main();

Currently supported models

Model MODEL_NAME Insight Link
LLaMA 3.1 8B meta-llama/Llama-3.1-8B-instruct Link

Deploy

You can deploy your AI model to ainize. Anyone can use your AI model with AIN token. You need AIN tokens for deploying models.

CONFIGURATION(JSON)

  • modelName: The name you want to deploying model.
  • modelUrl: Inference URL wrapped with ainize-wrapper-server.
import { Ainize } from '@ainize-team/ainize-js';
const ainPrivateKey = ''; // Insert your private key here

const main = async () => {
  try {
    const ainize = new Ainize(1);
    await ainize.login(ainPrivateKey);
    const deployConfig = {
      modelName: 'YOUR_MODEL_NAME', // e.g. meta-llama/Llama-3.1-8B-instruct
      modelUrl: 'https://ainize-free-inference.ainetwork.xyz' // This URL is for tutorial.
    }
    const model = await ainize.deploy(deployConfig);
    console.log(model.modelName);
    ainize.logout();
  } catch(e) {
    console.log(e);
  }
}
main();