1.0.19 • Published 1 month ago

ai_devs_2_api v1.0.19

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

AI_DEVS 2 API

A simple Node.js library for interacting with the AI Devs 2 API, allowing you to easily retrieve and submit tasks. This library provides convenient methods for getting task information, obtaining task tokens, fetching tasks, and submitting answers.

Installation

Node.js 16.5 or higher is required

You can install this library using npm:

npm install ai_devs_2_api

Usage

To get started, require the ai_devs_2_api library and create an instance of the AD2_API class, passing your API key as a parameter:

HELLOAPI

const aiDevs2Api = require('ai_devs_2_api/ai_devs'); // AI_DEVS API
const aiDevs2OAApi = require('ai_devs_2_api/openAIapi'); // OpenAI API

const api = new aiDevs2Api('YOUR_AI_DEVS_API_KEY');
const aiApi = new aiDevs2OAApi('YOUR_OPEN_AI_API_KEY');

// Get task info
const taskName = 'helloapi';

api.getTaskInfo(taskName).then((task) => {
    console.log(task);
});

// Get task and send answer
api.getTaskInfo(taskName).then((task) => {
    console.log(task);
    //Send answer to API, sendAnswer(token, answer, timeout = 5000)
    api.sendAnswer(task.token, task.cookie).then(response => {
        console.log(response);
    });
});

MODERATION

aiApi.moderation('TEXT_TO_MODERATE').then((result) => {
    console.log(result);
});

COMPLETIONS

aiApi.setModel('gpt-4'); // Default is set gpt-3.5-turbo
const messages = {
    system: `I'm copywriter and blogger, writing article for blog, use {info} from user, write in Polish and return content to array with 4 rows like input`,
    user: `###info\n${task.msg}\n\n${task.blog}`
}
aiApi.completions(messages, {maxTokens: 1000}).then((response) => {
    console.log(response);
    //firstChoice returns content from first choice from OpenAI API
    response.firstChoice = aiApi.clearJSON(response.firstChoice); // Make JSON from string and clear it
    
    console.log(response.firstChoice);
    
    api.sendAnswer(task.token, response.firstChoice).then(response => {
        console.log(response);
    });
});

EMBEDDING

aiApi.embeddings('Hawaiian pizza').then((embeddings) => {
    
    console.log(embeddings); // All data from embedding API
    console.log(embeddings.embedding); // Only embedding array
    
    if(embeddings.embedding.length > 0) {
        
        api.sendAnswer(task.token, embeddings.embedding).then((response) => {
            console.log(response);
        });
        
    }
});

WHISPER (Speach to text)

const taskName = 'whisper';

api.getTaskInfo(taskName).then(task => {
    console.log(task);

    //Find URL in string and return File Buffer from MP3
    api.getFileBuffer(task.msg).then(buffer => {

        // OpenAI API Whisper:
        // As a second parameter, you can set the model (default is 'whisper-1').
        // Returns RAW text from an MP3 file buffer.
        aiApi.whisper(buffer).then(text => { 
            console.log(text);
            api.sendAnswer(task.token, text).then(response => {
                console.log(response);
            });
        });
    });
});

VISION

//imageURL - URL to image starting with http/https [required]
//messages - object with user message, like in completions [required]
//options - like in completions
aiApi.vision(imageURL, messages = {
    user: 'PROMPT'
}, options = {}).then(result => {
    console.log(result.firstChoice);
});

RenderForm

//apiKey - API key to RenderForm
//templateID - template Identifier
api.renderFormRequest(apiKey, templateID, {
    'image.src': task.image,
    'text.text': task.text
}).then(response => {
    console.log(response);
});

HELPERS

aiApi.setModel('gpt-4'); // set OpenAI model for Completions

aiApi.clearJSON(text); // Make Object from JSON string and clear it before

// Get file buffer, now with optional timeout and headers for request
api.getFileBuffer(url, { timeout: 5000, headers: { } });

Changelog

  • 1.0.19 - Fixed clearJSON method
  • 1.0.18 - Changed clearJSON method
  • 1.0.17 - Added RenderForm API
  • 1.0.16 - Added OpenAI Vision API
  • 1.0.15 - Modified functions: sendAnswer and getFileBuffer
  • 1.0.13 - Added OpenAI Speach To Text API (whisper-1)
  • 1.0.12 - Added OpenAI Embedding API (text-embedding-ada-002)
  • 1.0.11 - Added OpenAI Chat Completions API
  • 1.0.10 - Update README
  • 1.0.9 - Bug fixes
  • 1.0.5 - Added OpenAI Moderation API, change fetch() to Axios
  • 1.0.0 - Initial
1.0.19

1 month ago

1.0.18

1 month ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

6 months ago

1.0.5

6 months ago

1.0.4

6 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago