-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from ainize-team/feat/woojae/readme
�refactor: service to model
- Loading branch information
Showing
10 changed files
with
259 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,91 @@ | ||
# ainize-js | ||
|
||
A Typescript JS for the Ainize, a system for running AI services on the AI Network. | ||
A Typescript JS for the Ainize, a system for running AI models on the AI Network. | ||
|
||
## Requirements | ||
|
||
node >= 16 | ||
|
||
## usage | ||
|
||
### Install | ||
|
||
```bash | ||
npm install @ainize-team/ainize-js | ||
|
||
yarn install @ainize-team/ainize-js | ||
``` | ||
|
||
### Import | ||
```typescript | ||
import Ainize from '@ainize-team/ainize-js' | ||
const ainize = new Ainize(<CHAIN_ID>); | ||
``` | ||
|
||
CHAIN_ID | ||
|
||
- 0: AI Network test net | ||
- 1: AI Network main net | ||
|
||
```typescript | ||
|
||
import Ainize from '@ainize-team/ainize-js' | ||
const ainize = new Ainize(<CHAIN_ID>); | ||
``` | ||
|
||
### Login | ||
|
||
You should login to ainize with AI Network account before deploy the container. | ||
|
||
```typescript | ||
ainize.login(<YOUR_PRIVATE_KEY>); | ||
``` | ||
|
||
You can also login using [AIN Wallet](https://chromewebstore.google.com/detail/ain-wallet/hbdheoebpgogdkagfojahleegjfkhkpl) on the web. | ||
|
||
```typescript | ||
ainize.loginWithSigner(); | ||
``` | ||
|
||
This feature is supported from AIN Wallet version 2.0.5 or later. | ||
|
||
### Deploy | ||
You can deploy your AI service to ainize. | ||
### Using model | ||
|
||
You can use a model using `ainize.getModel(<MODEL_NAME>)`. | ||
|
||
```typescript | ||
const service = await ainize.deploy(<CONFIGURATION>); | ||
const model = await ainize.getModel(<MODEL_NAME>); | ||
``` | ||
CONFIGURATION | ||
- serviceName: The name you want to deploying service. | ||
- billingConfig: Billing configuration required for service usage. | ||
- depositAddress: The address for receiving AIN deposits. | ||
- costPerToken: Cost per token for service usage. | ||
- minCost: Minimum cost. | ||
- maxCost: Maximum cost. (optional) | ||
|
||
You can stop or run your service container. Only service deployer can use this. | ||
You should deposit AIN to AI model for credit before using model. | ||
|
||
```typescript | ||
service.stop(); | ||
service.run(); | ||
await model.chargeCredit(<AMOUNT>); | ||
const balance = await model.getCreditBalance(); | ||
``` | ||
|
||
### Using Service | ||
You can use a service using `ainize.getService(<SERVICE_NAME>)`. | ||
If you have enough credit, you can use the model. | ||
|
||
```typescript | ||
const service = await ainize.getService(<SERVICE_NAME>); | ||
const result = await model.request(<REQUEST_DATA>); | ||
``` | ||
|
||
You should deposit AIN to credit before using service. | ||
### Deploy | ||
|
||
You can deploy your AI model to ainize. Anyone can use your AI model with AIN token. | ||
|
||
CONFIGURATION(JSON) | ||
|
||
- modelName: The name you want to deploying model. | ||
- billingConfig: Billing configuration required for model usage. | ||
- depositAddress: The address for receiving AIN deposits. | ||
- costPerToken: Cost per token for model usage. | ||
- minCost: Minimum cost. | ||
- maxCost: Maximum cost. (optional) | ||
|
||
```typescript | ||
await service.chargeCredit(<AMOUNT>); | ||
const balance = await service.getCreditBalance(); | ||
const model = await ainize.deploy(<CONFIGURATION>); | ||
``` | ||
|
||
If you have enough credit, you can use the service. | ||
You can stop or run your model container. Only model deployer can use this. | ||
|
||
```typescript | ||
const result = await service.request(<REQUEST_DATA>); | ||
``` | ||
model.stop(); | ||
model.run(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.