![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Interact with NanoGPT's API for pay-per-prompt interaction with AI models
Node.js library to Interact with NanoGPT's API. The NanoGPT service enables pay-per-prompt interaction with chat and image generation models. You will need a prefilled NanoGPT wallet and API key to use this library effectively.
npm install --save nanogptjs
const nanogptjs = require('nanogptjs')
const { YOUR_NANO_GPT_API_KEY } = require('./secrets.js')
;(async function () {
const nanogpt = nanogptjs({
apiKey: YOUR_NANO_GPT_API_KEY,
defaultModel: 'chatgpt-4o-latest'
})
let { reply } = await nanogpt.chat('Tell me something about Nano digital currency?')
console.log(reply) // Nano is a feeless and instant cryptocurrency.
})()
Importing nanogptjs
const nanogptjs = require('nanogptjs')
Create a nanogptjs
instance with your NanoGPT API key (required)
const nanogpt = nanogptjs({
apiKey: YOUR_NANO_GPT_API_KEY
})
Alternatively supply a defaultModel
to be used in further function calls
const nanogpt = nanogptjs({
apiKey: YOUR_NANO_GPT_API_KEY,
defaultModel: 'chatgpt-4o-latest'
})
Sends a chat prompt. Requires defaultModel
field be set when creating your nanogptjs
instance.
let reply = await nanogpt.chat('Tell me something about Nano digital currency?')
Returns a Promise that resolves to an Object with the following format:
{
reply: "Nano is a feeless and instant cryptocurrency.", // the reply to your chat prompt
metadata: {
cost: 0.001089, // cost of this interaction
paymentSource: 'XNO', // currency used for payment
inputTokens: 24, // number of tokens your input created
outputTokens: 21 // number of tokens your output created
}
}
Sends a chat prompt. Gives you more control by allowing you to specify model and chat context (i.e. history).
let reply = await nanogpt.chat({
prompt: 'What is my favorite color?', // chat prompt
model: 'chatgpt-4o-latest', // model to use
context: [
nanogpt.contextUser('Blue is my favorite color'),
nanogpt.contextAI('Very interesting! I will remember that.'),
] // context for your chat prompt
})
defaultModel
field is set when creating your nanogptjs
instance.contextUser
and contextAI
to specify who is speaking.Returns a Promise that resolves to an Object with the following format:
{
reply: "Based on prior informations, I think blue is your favorite color!", // the reply to your chat prompt
metadata: {
cost: 0.001089, // cost of this interaction
paymentSource: 'XNO', // currency used for payment
inputTokens: 24, // number of tokens your input created
outputTokens: 21 // number of tokens your output created
}
}
Generates a single image.
let image = await nanogpt.image({
prompt: 'a beautiful landscape, bright sunshine, green fields',
model: 'dreamshaper_8_93211.safetensors',
width: 1024,
height: 1024
})
Returns a Promise that resolves to an Object with the following format:
{
base64: " /9j/4AAQSkZJRgABAQAAAQABAAD...", // base64 encoded version of your generated image
metadata: {
created: 1723814389930, // timestamp of this image generation
cost: 0.0021, // cost of this interaction
paymentSource: 'XNO' // currency used for payment
}
}
Generates a specific number of images.
let imageBatch = await nanogpt.imageBatch({
batchSize: 2,
prompt: 'a beautiful landscape with a large cat',
model: 'dreamshaper_8_93211.safetensors',
width: 1024,
height: 1024
})
Returns a Promise that resolves to an Object with the following format:
{
imageBatch: [ // array of generated images
base64: " /9j/4AAQSkZJRgABAQAAAQAQAQA...", // base64 encoded version of your generated image
base64: " /9j/4AAQSkZJRgABAQAAAQAABAB...", // base64 encoded version of your generated image
]
metadata: {
created: 1723815073228, // timestamp of this image generation
cost: 0.00501, // cost of this interaction
paymentSource: 'XNO' // currency used for payment
}
}
Retrieves information about your NanoGPT account.
let account = await nanogpt.account()
Returns a Promise that resolves to an Object with the following format:
{
nanoDepositAddress: 'nano_3d46mow3fim7bfd15xckfgao9ehabmp56y7gkn9q3nky1i3buehtroxi8q67',
nanoReturnAddress: 'nano_15qzsidyztg1i7at4zdeapzzh5hfgy1rip8e5uz1an3tujuunujgesgzf187',
balance: 3.098908,
receivable: 0,
earned: '0.000000'
}
Retrieves your current NanoGPT account balance.
let balance = await nanogpt.balance()
Returns a Number
4.0678
Retrieves information about the models available on NanoGPT.
let models = await nanogpt.models()
Returns a Promise that resolves to an Object with the following format:
{
"models": {
"text": {
"gpt-4o": {
"name": "GPT 4o",
"model": "gpt-4o",
"description": "OpenAI's most advanced model. It matches GPT-4 Turbo performance on text in English and code, with significant improvement on text in non-English languages, while also being much faster and 50% cheaper.",
"cost": "Average cost: 0.025 Nano",
"costEstimate": 0.025,
"labelVariant": "outline",
"label": "Recommended",
"visible": false
},
// ...more text models
},
"image": {
"dall-e-3": {
"name": "DALL-E-3",
"model": "dall-e-3",
"engine": "dalle",
"description": "The current golden standard in image generation.",
"cost": {
"1024x1024": 0.04,
"1024x1792": 0.08,
"1792x1024": 0.08
},
"label": "Default",
"maxImages": 1,
"resolutions": [
{
"value": "1024x1024"
},
{
"value": "1024x1792",
"comment": "2x the price"
},
{
"value": "1792x1024",
"comment": "2x the price"
}
]
},
// ...more image models
}
}
}
Utility function to aid with creation of the Object field context
in the chat
function.
nanogpt.contextUser('Blue is my favorite color')
Returns an Object with the following format:
{
role: 'user',
content: 'Blue is my favorite color'
}
Utility function to aid with creation of the Object field context
in the chat
function.
nanogpt.contextAI('Very interesting! I will remember that.')
Returns an Object with the following format:
{
role: 'assistant',
content: 'Very interesting! I will remember that.'
}
You can find multiple NanoGPTJS usage examples in the examples folder.
Pull requests and opened issues are welcome!
As always when working with real world value, in this case Nano, be careful when using this library. The authors and contributors shall not be held liable for any use of this library's functionality, intentional or unintentional, that leads to an undesired lose of funds.
MIT
FAQs
Interact with NanoGPT's API for pay-per-prompt interaction with AI models
We found that nanogptjs demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.