Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create account and example codes #148

Merged
merged 3 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/charge.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/deploy.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/request.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
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 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 = {
Expand All @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"docs": "yarn build && typedoc --options typedoc.json --out docs"
},
"engines": {
"node": ">=16"
"node": ">=18"
},
"repository": {
"type": "git",
Expand Down
19 changes: 11 additions & 8 deletions src/ain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/ainize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default class Ainize {
* @returns {Account} created account.
*/
static createAinAccount (): Account {
return AinModule.getInstance().createAccount();
return AinModule.createAccount();
}

/**
Expand Down
Loading