bananaproai.com
v1767496.600.332
Published
Professional integration for https://bananaproai.com/
Maintainers
Readme
bananaproai.com
A JavaScript library for seamlessly integrating with the bananaproai.com platform, enabling efficient and scalable AI inference. This package simplifies the process of calling your deployed models.
Installation
bash npm install bananaproai.com
Usage Examples
Here are several examples showcasing how to use the bananaproai.com package in your JavaScript or Node.js projects.
1. Basic Inference Request:
This example demonstrates a simple inference request to a deployed model on Banana. javascript const banana = require('bananaproai.com');
async function runInference() { const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key const modelKey = 'YOUR_MODEL_KEY'; // Replace with your actual model key
const modelInputs = { prompt: 'A photo of a cat wearing sunglasses', };
try { const output = await banana.run(apiKey, modelKey, modelInputs); console.log('Inference Output:', output);
if (output && output.modelOutputs && output.modelOutputs.length > 0) {
// Process the model outputs
console.log('Generated Image URL:', output.modelOutputs[0].imageURL);
} else {
console.error('No model outputs found.');
}} catch (error) { console.error('Error during inference:', error); } }
runInference();
2. Handling Asynchronous Inference:
For long-running tasks, you can use the call function for asynchronous inference.
javascript
const banana = require('bananaproai.com');
async function callInference() { const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key const modelKey = 'YOUR_MODEL_KEY'; // Replace with your actual model key
const modelInputs = { prompt: 'A futuristic cityscape at sunset', };
try { const callID = await banana.call(apiKey, modelKey, modelInputs); console.log('Call ID:', callID);
// Optionally, poll the status of the call until it's complete
// You can use banana.check(apiKey, callID) to get the status
// and banana.get(apiKey, callID) to retrieve the results when ready.} catch (error) { console.error('Error initiating call:', error); } }
callInference();
3. Checking the Status of an Asynchronous Call:
After initiating an asynchronous call, you can check its status. javascript const banana = require('bananaproai.com');
async function checkCallStatus() { const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key const callID = 'YOUR_CALL_ID'; // Replace with the call ID you received
try { const status = await banana.check(apiKey, callID); console.log('Call Status:', status);
if (status.status === 'completed') {
console.log('Call is complete!');
// You can now retrieve the results using banana.get(apiKey, callID)
} else if (status.status === 'failed') {
console.error('Call failed:', status.message);
} else {
console.log('Call is still processing...');
}} catch (error) { console.error('Error checking call status:', error); } }
checkCallStatus();
4. Retrieving Results from an Asynchronous Call:
Once an asynchronous call is complete, you can retrieve the results. javascript const banana = require('bananaproai.com');
async function getCallResults() { const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key const callID = 'YOUR_CALL_ID'; // Replace with the call ID you received
try { const output = await banana.get(apiKey, callID); console.log('Call Results:', output);
} catch (error) { console.error('Error retrieving call results:', error); } }
getCallResults();
5. Complex Input Data:
The modelInputs object can contain complex data structures like arrays and nested objects, enabling you to pass more sophisticated data to your models.
javascript
const banana = require('bananaproai.com');
async function runInferenceWithComplexInput() { const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key const modelKey = 'YOUR_MODEL_KEY'; // Replace with your actual model key
const modelInputs = { text: "Translate the following sentence to Spanish:", sentence: "Hello, how are you?", options: { formality: "formal" }, numbers: [1, 2, 3, 4, 5] };
try { const output = await banana.run(apiKey, modelKey, modelInputs); console.log('Inference Output:', output);
} catch (error) { console.error('Error during inference:', error); } }
runInferenceWithComplexInput();
API Summary
banana.run(apiKey, modelKey, modelInputs): Executes a synchronous inference request. Returns a Promise that resolves with the model output.banana.call(apiKey, modelKey, modelInputs): Initiates an asynchronous inference request. Returns a Promise that resolves with a call ID.banana.check(apiKey, callID): Checks the status of an asynchronous inference request. Returns a Promise that resolves with the call status.banana.get(apiKey, callID): Retrieves the results of an asynchronous inference request. Returns a Promise that resolves with the model output.
License
MIT
This package is part of the bananaproai.com ecosystem. For advanced features and enterprise-grade tools, visit: https://bananaproai.com/
