From c3e6761f1831e987ad0e2bc92af64a62f2e05a53 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 18 Dec 2024 09:30:00 +0900 Subject: [PATCH 1/5] fix: no init before create account --- src/ain.ts | 19 +++++++++++-------- src/ainize.ts | 2 +- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ain.ts b/src/ain.ts index f4c8835..1256256 100644 --- a/src/ain.ts +++ b/src/ain.ts @@ -18,20 +18,23 @@ export default class AinModule { return AinModule.instance; } + static createAccount() { + const blockchainAPIEndpoint = getBlockChainAPIEndpoint(0); + const blockchainEventEndpoint = getBlockChainEventEndpoint(0); + const ain = new Ain(blockchainAPIEndpoint, blockchainEventEndpoint, 0); + + const newAccount = ain.wallet.create(1)[0]; + const wallet = ain.wallet.accounts[newAccount]; + + return wallet; + } + initAin(chainId: 0 | 1) { const blockchainAPIEndpoint = getBlockChainAPIEndpoint(chainId); const blockchainEventEndpoint = getBlockChainEventEndpoint(chainId); this.ain = new Ain(blockchainAPIEndpoint, blockchainEventEndpoint, chainId); } - createAccount() { - this.checkAinInitiated(); - const newAccount = this.ain!.wallet.create(1)[0]; - const wallet = this.ain!.wallet.accounts[newAccount]; - this.ain!.wallet.remove(newAccount); - return wallet; - } - setDefaultAccount(privateKey: string) { this.checkAinInitiated(); this.ain!.wallet.addAndSetDefaultAccount(privateKey); diff --git a/src/ainize.ts b/src/ainize.ts index 0dd631e..8c5c926 100644 --- a/src/ainize.ts +++ b/src/ainize.ts @@ -32,7 +32,7 @@ export default class Ainize { * @returns {Account} created account. */ static createAinAccount (): Account { - return AinModule.getInstance().createAccount(); + return AinModule.createAccount(); } /** From 26a08fd1d7f27a3a5774cc32e4fd87601a747891 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 18 Dec 2024 09:32:02 +0900 Subject: [PATCH 2/5] fix: examples --- examples/charge.ts | 6 +++--- examples/deploy.ts | 8 ++++---- examples/request.ts | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/charge.ts b/examples/charge.ts index 7bff876..df95e89 100644 --- a/examples/charge.ts +++ b/examples/charge.ts @@ -1,17 +1,17 @@ -import { Ainize } from '@ainize-team/ainize-js'; +import Ainize from '@ainize-team/ainize-js'; const ainPrivateKey = ''; // Insert your private key here const main = async () => { try { const ainize = new Ainize(1); // 0 for testnet, 1 for mainnet. You can earn testnet AIN at https://faucet.ainetwork.ai/. await ainize.login(ainPrivateKey); console.log('balance: ',await ainize.getAinBalance()); - const model = await ainize.getModel('ainize_free_inference'); + const model = await ainize.getModel('meta-llama/Llama-3.1-8B-instruct'); console.log(model.modelName); console.log("before charge: ",await model.getCreditBalance()); await model.chargeCredit(10); console.log("after charge: ",await model.getCreditBalance()); ainize.logout(); - }catch(e) { + } catch(e) { console.log(e); } } diff --git a/examples/deploy.ts b/examples/deploy.ts index 7e97092..be57a6d 100644 --- a/examples/deploy.ts +++ b/examples/deploy.ts @@ -1,19 +1,19 @@ -import { Ainize } from '@ainize-team/ainize-js'; +import Ainize from '@ainize-team/ainize-js'; const ainPrivateKey = ''; // Insert your private key here const main = async () => { try { const ainize = new Ainize(1); // 0 for testnet, 1 for mainnet. You can earn testnet AIN at https://faucet.ainetwork.ai/. await ainize.login(ainPrivateKey); - console.log('balance: ',await ainize.getAinBalance()); + console.log('balance: ', await ainize.getAinBalance()); const deployConfig = { modelName: 'YOUR_MODEL_NAME', - modelUrl: 'YOUR_MODEL_INFERENCE_URL' // e.g. https://ainize-free-inference.ainetwork.xyz + modelUrl: 'YOUR_MODEL_INFERENCE_URL' } const model = await ainize.deploy(deployConfig); console.log(model.modelName); ainize.logout(); - }catch(e) { + } catch(e) { console.log(e); } } diff --git a/examples/request.ts b/examples/request.ts index f5cc401..b29cc68 100644 --- a/examples/request.ts +++ b/examples/request.ts @@ -1,4 +1,4 @@ -import { Ainize } from '@ainize-team/ainize-js'; +import Ainize from '@ainize-team/ainize-js'; const ainPrivateKey = ''; // Insert your private key here const main = async () => { @@ -6,7 +6,7 @@ const main = async () => { const ainize = new Ainize(1); // 0 for testnet, 1 for mainnet. You can earn testnet AIN at https://faucet.ainetwork.ai/. await ainize.login(ainPrivateKey); console.log('balance: ',await ainize.getAinBalance()); - const inferenceModel = await ainize.getModel('ainize_free_inference'); + const inferenceModel = await ainize.getModel('meta-llama/Llama-3.1-8B-instruct'); console.log(inferenceModel.modelName); console.log(await inferenceModel.getCreditBalance()); const request = { @@ -17,7 +17,7 @@ const main = async () => { const response = await inferenceModel.request(request); console.log(response); ainize.logout(); - }catch(e) { + } catch(e) { console.log(e); } } From 2d7192e3486cd0248bf220a9e7250e13c5c6e564 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 18 Dec 2024 09:48:10 +0900 Subject: [PATCH 3/5] chore: node version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8ddc4bd..749a305 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "docs": "yarn build && typedoc --options typedoc.json --out docs" }, "engines": { - "node": ">=16" + "node": ">=18" }, "repository": { "type": "git", From c1a165b101b63c2e19eaeeedd3440c82088500a3 Mon Sep 17 00:00:00 2001 From: Yoojin Ko Date: Wed, 18 Dec 2024 10:13:50 +0900 Subject: [PATCH 4/5] fix: github action --- .github/workflows/docs.yml | 2 +- .github/workflows/pr_test.yml | 2 +- .github/workflows/pr_test_when_merged.yml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b85caaf..3e7c3b5 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -11,7 +11,7 @@ jobs: fetch-depth: 0 # otherwise, you will failed to push refs to dest repo - uses: actions/setup-node@v3 with: - node-version: 16 # typedoc require node version >= 14.14 + node-version: 18 # typedoc require node version >= 14.14 - name: Build Docs run: yarn && yarn docs - name: Deploy diff --git a/.github/workflows/pr_test.yml b/.github/workflows/pr_test.yml index 88a9d72..0a58b56 100644 --- a/.github/workflows/pr_test.yml +++ b/.github/workflows/pr_test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [ 16 ] + node: [ 18 ] name: Run Test on Node ${{ matrix.node }} steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/pr_test_when_merged.yml b/.github/workflows/pr_test_when_merged.yml index ae6e43c..1c189c6 100644 --- a/.github/workflows/pr_test_when_merged.yml +++ b/.github/workflows/pr_test_when_merged.yml @@ -12,7 +12,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - node: [ 16 ] + node: [ 18 ] name: Run Test on Node ${{ matrix.node }} steps: - uses: actions/checkout@v3 @@ -30,7 +30,7 @@ jobs: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: - node-version: '16.x' + node-version: '18.x' registry-url: 'https://registry.npmjs.org' - name: Install dependencies run: yarn From cd6b85ed6e36c4ed98475083f6c33b965f8dc5ee Mon Sep 17 00:00:00 2001 From: yoojinko Date: Wed, 18 Dec 2024 01:18:05 +0000 Subject: [PATCH 5/5] Upgrade version to 1.3.5 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 749a305..40fc652 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ainize-team/ainize-js", - "version": "1.3.4", + "version": "1.3.5", "main": "dist/ainize.js", "types": "dist/ainize.d.ts", "scripts": {