Skip to content

Commit

Permalink
Merge pull request #258 from ainft-team/release/2.0.0
Browse files Browse the repository at this point in the history
Upgrade version to 2.0.0
  • Loading branch information
jiyoung-an authored Mar 6, 2024
2 parents f9438b5 + 4c166d9 commit 4753406
Show file tree
Hide file tree
Showing 42 changed files with 4,584 additions and 1,020 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pr_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 14, 16 ]
node: [ 18, 20 ]
name: Run Test on Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
Expand All @@ -21,3 +21,5 @@ jobs:
node-version: ${{ matrix.node }}
- run: yarn install --immutable --immutable-cache --check-cache
- run: yarn test
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
6 changes: 5 additions & 1 deletion .github/workflows/pr_test_when_merged.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [ 14, 16 ]
node: [ 18, 20 ]
name: Run Test on Node ${{ matrix.node }}
steps:
- uses: actions/checkout@v3
Expand All @@ -22,6 +22,8 @@ jobs:
node-version: ${{ matrix.node }}
- run: yarn install --immutable --immutable-cache --check-cache
- run: yarn test
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
publish:
needs: [ run_test ]
if: ${{ startsWith(github.head_ref, 'release/') && (github.base_ref == 'main') && (github.event.pull_request.merged == true) }}
Expand All @@ -36,6 +38,8 @@ jobs:
run: yarn
- name: Test Success
run: yarn test
env:
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
- name: Publish package
run: |
yarn
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ Introducing the main API functions that can be used in the `ainftToken` module.


## AINFT tutorial
You can view the [tutorial document](https://docs.ainetwork.ai/ainfts/developer-reference/ainft-tutorial) at the following link. and You can also look at scripts created for tutorials in the [tutorial directory](https://github.com/ainft-team/ainft-js/tree/main/tutorials).
You can view the [tutorial document](https://docs.ainetwork.ai/ainfts/developer-reference/ainft-tutorial) at the following link. and You can also look at scripts created for tutorials in the [tutorial directory](https://github.com/ainft-team/ainft-js/tree/main/examples).

Tutorial scripts
- [createAinftObject](https://github.com/ainft-team/ainft-js/blob/master/tutorials/createAinftObject.js)
- [mintAinft](https://github.com/ainft-team/ainft-js/blob/master/tutorials/mintAinft.js)
- [transferAinft](https://github.com/ainft-team/ainft-js/blob/master/tutorials/transferAinft.js)
- [retrieveAinft](https://github.com/ainft-team/ainft-js/blob/master/tutorials/retrieveAinft.js)
- [searchAinft](https://github.com/ainft-team/ainft-js/blob/master/tutorials/searchAinft.js)
- [createAinftObject](https://github.com/ainft-team/ainft-js/blob/master/examples/nft/createAinftObject.js)
- [mintAinft](https://github.com/ainft-team/ainft-js/blob/master/examples/nft/mintNft.js)
- [transferAinft](https://github.com/ainft-team/ainft-js/blob/master/examples/nft/transferNft.js)
- [retrieveAinft](https://github.com/ainft-team/ainft-js/blob/master/examples/nft/retrieve.js)
- [searchAinft](https://github.com/ainft-team/ainft-js/blob/master/examples/nft/search.js)

## API Documentation
API documentation is available at https://ainft-team.github.io/ainft-js.
Expand Down
44 changes: 44 additions & 0 deletions examples/chat/assistant.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// To run this example, you must own an ainft object and token; create one if you don't.
// https://docs.ainetwork.ai/ainfts/developer-reference/ainft-tutorial/create-ainft-object-and-mint

const AinftJs = require('@ainft-team/ainft-js').default;
const config = require('../config.json');

['privateKey', 'objectId', 'appId', 'tokenId'].forEach((key) => {
if (!config[key]?.trim()) {
throw new Error(`${key} is missing or empty in config.json`);
}
});

const { privateKey, objectId, appId, tokenId } = config; // TODO(user): set these in config.json
const params = {
model: 'gpt-4', // TODO(user): update this
name: 'QuickSupport', // TODO(user): update this
instructions: 'Answer tech support questions.', // TODO(user): update this
description: 'A chatbot for quick tech-related queries.', // TODO(user): update this
metadata: { topic: 'Tech', language: 'en' }, // TODO(user): update this
};

const ainft = new AinftJs(privateKey, {
ainftServerEndpoint: 'https://ainft-api-dev.ainetwork.ai',
ainBlockchainEndpoint: 'https://testnet-api.ainetwork.ai',
chainId: 0,
});

async function main() {
try {
console.log('Creating assistant...\n');

const { assistant, tx_hash } = await ainft.chat.assistant.create(objectId, tokenId, 'openai', params);

console.log(`\nSuccessfully created assistant with ID: ${assistant.id}`);
console.log(`assistant: ${JSON.stringify(assistant, null, 2)}`);
console.log(`txHash: ${tx_hash}`);
console.log(`View more details at: https://testnet-insight.ainetwork.ai/database/values/apps/${appId}/tokens/${tokenId}/ai`);
} catch (error) {
console.error('Failed to create assistant: ', error.message);
process.exit(1);
}
}

main();
37 changes: 37 additions & 0 deletions examples/chat/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// To run this example, you must own an ainft object; create one if you don't.
// https://docs.ainetwork.ai/ainfts/developer-reference/ainft-tutorial/create-ainft-object-and-mint

const AinftJs = require('@ainft-team/ainft-js').default;
const config = require('../config.json');

['privateKey', 'objectId', 'appId'].forEach((key) => {
if (!config[key]?.trim()) {
throw new Error(`${key} is missing or empty in config.json`);
}
});

const { privateKey, objectId, appId } = config; // TODO(user): set these in config.json

const ainft = new AinftJs(privateKey, {
ainftServerEndpoint: 'https://ainft-api-dev.ainetwork.ai',
ainBlockchainEndpoint: 'https://testnet-api.ainetwork.ai',
chainId: 0,
});

async function main() {
try {
console.log('Configuring chat...\n');

const { config, tx_hash } = await ainft.chat.configure(objectId, 'openai');

console.log(`Successfully configured chat for ainft object!`);
console.log(`config: ${JSON.stringify(config, null, 2)}`);
console.log(`txHash: ${tx_hash}`);
console.log(`View more details at: https://testnet-insight.ainetwork.ai/database/values/apps/${appId}`);
} catch (error) {
console.error('Failed to configure chat: ', error.message);
process.exit(1);
}
}

main();
46 changes: 46 additions & 0 deletions examples/chat/deposit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const AinftJs = require('@ainft-team/ainft-js').default;
const config = require('../config.json');

if (!config.privateKey?.trim()) {
throw new Error('privateKey is missing or empty in config.json');
}

const { privateKey } = config;

const ainft = new AinftJs(privateKey, {
ainftServerEndpoint: 'https://ainft-api-dev.ainetwork.ai',
ainBlockchainEndpoint: 'https://testnet-api.ainetwork.ai',
chainId: 0,
});

async function main() {
try {
console.log('Depositing credit...\n');

// TODO(user): get testnet AIN from [faucet](https://faucet.ainetwork.ai)
const { tx_hash, address, balance } = await ainft.chat.depositCredit('openai', 10);

console.log(`\nSuccessfully deposited credit for chatting!`);
console.log(`address: ${address}`);
console.log(`balance: ${balance}`);
console.log(`txHash: ${tx_hash}`);
console.log(`View more details at: https://testnet-insight.ainetwork.ai/transactions/${tx_hash}`);
} catch (error) {
console.error('Failed to deposit credit: ', error.message);
process.exit(1);
}

try {
console.log('\nChecking credit...\n');

const balance = await ainft.chat.getCredit('openai');

console.log(`\nSuccessfully checked credit!`);
console.log(`balance: ${balance}`);
} catch (error) {
console.error('Failed to check credit:', error.message);
process.exit(2);
}
}

main();
43 changes: 43 additions & 0 deletions examples/chat/message.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// To run this example you must create a thread (see examples/chat/thread.js)

const AinftJs = require('@ainft-team/ainft-js').default;
const config = require('../config.json');

['privateKey', 'objectId', 'appId', 'tokenId'].forEach((key) => {
if (!config[key]?.trim()) {
throw new Error(`${key} is missing or empty in config.json`);
}
});

const { privateKey, objectId, appId, tokenId } = config; // TODO(user): set these in config.json
const threadId = '<YOUR_THREAD_ID>'; // TODO(user): update this
const params = {
role: 'user',
content: 'What is git?', // TODO(user): update this
metadata: { language: 'en' }, // TODO(user): update this
};

const ainft = new AinftJs(privateKey, {
ainftServerEndpoint: 'https://ainft-api-dev.ainetwork.ai',
ainBlockchainEndpoint: 'https://testnet-api.ainetwork.ai',
chainId: 0,
});

async function main() {
try {
console.log('Creating message...\n');

const { messages, tx_hash } = await ainft.chat.message.create(threadId, objectId, tokenId, 'openai', params);

console.log(`\nSuccessfully created new message with reply:`);
console.log(`messages: ${JSON.stringify(messages, null, 2)}`);
console.log(`txHash: ${tx_hash}`);
// TODO(jiyoung): update service name in path
console.log(`View more details at: https://testnet-insight.ainetwork.ai/database/values/apps/${appId}/tokens/${tokenId}/ai/ainize_openai/history`);
} catch (error) {
console.error('Failed to create message: ', error.message);
process.exit(1);
}
}

main();
35 changes: 35 additions & 0 deletions examples/chat/thread.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const AinftJs = require('@ainft-team/ainft-js').default;
const config = require('../config.json');

['privateKey', 'objectId', 'appId', 'tokenId'].forEach((key) => {
if (!config[key]?.trim()) {
throw new Error(`${key} is missing or empty in config.json`);
}
});

const { privateKey, objectId, appId, tokenId } = config; // TODO(user): set these in config.json

const ainft = new AinftJs(privateKey, {
ainftServerEndpoint: 'https://ainft-api-dev.ainetwork.ai',
ainBlockchainEndpoint: 'https://testnet-api.ainetwork.ai',
chainId: 0,
});

async function main() {
try {
console.log('Creating thread...\n');

const { thread, tx_hash } = await ainft.chat.thread.create(objectId, tokenId, 'openai', {});

console.log(`\nSuccessfully created thread with ID: ${thread.id}`);
console.log(`thread: ${JSON.stringify(thread, null, 2)}`);
console.log(`txHash: ${tx_hash}`);
// TODO(jiyoung): update service name in path
console.log(`View more details at: https://testnet-insight.ainetwork.ai/database/values/apps/${appId}/tokens/${tokenId}/ai/ainize_openai/history`);
} catch (error) {
console.error('Failed to create thread: ', error.message);
process.exit(1);
}
}

main();
6 changes: 6 additions & 0 deletions examples/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"privateKey": "",
"objectId": "",
"appId": "",
"tokenId": ""
}
34 changes: 34 additions & 0 deletions examples/nft/createAinftObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const AinftJs = require('@ainft-team/ainft-js').default;
const config = require('../config.json');

if (!config.privateKey?.trim()) {
throw new Error('privateKey is missing or empty in config.json');
}

const { privateKey } = config; // TODO(user): set this in config.json
const name = 'MyObject'; // TODO(user): update this
const symbol = 'MYOBJ'; // TODO(user): update this

const ainft = new AinftJs(privateKey, {
ainftServerEndpoint: 'https://ainft-api-dev.ainetwork.ai',
ainBlockchainEndpoint: 'https://testnet-api.ainetwork.ai',
});

async function main() {
try {
console.log('Creating ainft object...\n');

const { ainftObject, txHash } = await ainft.nft.create(name, symbol);

console.log(`Successfully created ainft object!`);
console.log(`objectId: ${ainftObject.id}`);
console.log(`appId: ${ainftObject.appId}`);
console.log(`txHash: ${txHash}`);
console.log(`View more details at: https://testnet-insight.ainetwork.ai/database/values/apps/${ainftObject.appId}`);
} catch (error) {
console.error('Failed to create ainft object: ', error.message);
process.exit(1);
}
}

main();
36 changes: 36 additions & 0 deletions examples/nft/mintNft.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const AinftJs = require('@ainft-team/ainft-js').default;
const config = require('../config.json');

['privateKey', 'objectId'].forEach((key) => {
if (!config[key]?.trim()) {
throw new Error(`${key} is missing or empty in config.json`);
}
});

const { privateKey, objectId } = config; // TODO(user): set these in config.json
const to = '0x...'; // TODO(user): update this with recipient's ain address
const tokenId = '1'; // TODO(user): update this as string to unique integer

const ainftJs = new AinftJs(privateKey, {
ainftServerEndpoint: 'https://ainft-api-dev.ainetwork.ai',
ainBlockchainEndpoint: 'https://testnet-api.ainetwork.ai',
});

async function main() {
try {
console.log('Minting ainft token...\n');

const ainftObject = await ainftJs.nft.get(objectId);
const { tx_hash } = await ainftObject.mint(to, tokenId);

console.log(`Successfully minted ainft token!`);
console.log(`tokenId: ${tokenId}`);
console.log(`txHash: ${tx_hash}`);
console.log(`View more details at: https://testnet-insight.ainetwork.ai/database/values/apps/${ainftObject.appId}/tokens/${tokenId}`);
} catch (error) {
console.error('Failed to mint ainft token: ', error.message);
process.exit(1);
}
}

main();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions tutorials/package.json → examples/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "tutorials",
"name": "ainft-examples",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"@ainft-team/ainft-js": "1.0.0-beta.9"
"@ainft-team/ainft-js": "2.0.0"
}
}
File renamed without changes.
Loading

0 comments on commit 4753406

Please sign in to comment.