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

feat: add example codes #139

Merged
merged 1 commit into from
Dec 13, 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
18 changes: 18 additions & 0 deletions examples/charge.ts
Original file line number Diff line number Diff line change
@@ -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();
20 changes: 20 additions & 0 deletions examples/deploy.ts
Original file line number Diff line number Diff line change
@@ -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();
24 changes: 24 additions & 0 deletions examples/request.ts
Original file line number Diff line number Diff line change
@@ -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();
Loading