From 692882c1a968d3d779eccda1a42a2988cfefbda1 Mon Sep 17 00:00:00 2001 From: akaster99 Date: Fri, 13 Dec 2024 14:18:07 +0900 Subject: [PATCH] feat: add example codes --- examples/charge.ts | 18 ++++++++++++++++++ examples/deploy.ts | 20 ++++++++++++++++++++ examples/request.ts | 24 ++++++++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 examples/charge.ts create mode 100644 examples/deploy.ts create mode 100644 examples/request.ts diff --git a/examples/charge.ts b/examples/charge.ts new file mode 100644 index 0000000..8b183e7 --- /dev/null +++ b/examples/charge.ts @@ -0,0 +1,18 @@ +import { Ainize } from '@ainize-team/ainize-js'; +const ainPrivateKey = ''; // Insert your private key here +const main = async () => { + try { + const ainize = new Ainize(0); // 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'); + 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) { + console.log(e); + } +} +main(); diff --git a/examples/deploy.ts b/examples/deploy.ts new file mode 100644 index 0000000..425fb4b --- /dev/null +++ b/examples/deploy.ts @@ -0,0 +1,20 @@ +import { Ainize } from '@ainize-team/ainize-js'; +const ainPrivateKey = ''; // Insert your private key here + +const main = async () => { + try { + const ainize = new Ainize(0); // 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 deployConfig = { + modelName: 'YOUR_MODEL_NAME', + modelUrl: 'YOUR_MODEL_INFERENCE_URL' // e.g. https://ainize-free-inference.ainetwork.xyz + } + const model = await ainize.deploy(deployConfig); + console.log(model.modelName); + ainize.logout(); + }catch(e) { + console.log(e); + } +} +main(); diff --git a/examples/request.ts b/examples/request.ts new file mode 100644 index 0000000..7151cb9 --- /dev/null +++ b/examples/request.ts @@ -0,0 +1,24 @@ +import { Ainize } from '@ainize-team/ainize-js'; +const ainPrivateKey = ''; // Insert your private key here + +const main = async () => { + try { + const ainize = new Ainize(0); // 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'); + console.log(inferenceModel.modelName); + console.log(await inferenceModel.getCreditBalance()); + const request = { + "prompt": "hi" + }; + const cost = await inferenceModel.calculateCost(request.prompt); + console.log(cost); + const response = await inferenceModel.request(request); + console.log(response); + ainize.logout(); + }catch(e) { + console.log(e); + } +} +main();