-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #258 from ainft-team/release/2.0.0
Upgrade version to 2.0.0
- Loading branch information
Showing
42 changed files
with
4,584 additions
and
1,020 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"privateKey": "", | ||
"objectId": "", | ||
"appId": "", | ||
"tokenId": "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Oops, something went wrong.