npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

p4u-client-ai

v0.1.6

Published

Empower Your Apps with AI: Access Multiple Models, Automate Tasks, Create AI Agents Easily

Downloads

316

Readme

P4U Client AI Node API Package

Task automation system home

Documentation: API

A tool client for communicating with an AI models hub. Thanks to the tasks you define in the administration panel, you can write your own backend for any application without knowing how to program.

You can access multiple AI models from different vendors in one API. The tool allows for easy and quick implementation of functions that are managed by artificial intelligence models, which we program by describing the task to be performed. The API interface allows you to automate and combine tasks. Thanks to this tool, you can easily create an AI agent that will answer your phone, answer e-mails, chat, write articles or posts on social media.

This library provides convenient access to the REST API from TypeScript or JavaScript.

AIClient User Documentation

Installation

npm install --save p4u-client-ai
# or
yarn add p4u-client-ai

The AIClient class is designed for interacting with the API at task automation system. It manages user authentication, task operations requests.

Overview

The AIClient class provides an interface to interact with the API at https://api.programmers4u.com. This client supports user authentication, task operations such as creating, listing, running, and deleting tasks. It also provides some utility methods for basic API interactions.

Enums

AudioModelsEnum

  • OAIWHISPER1: whisper-1
  • OAITTS1: tts-1
  • OAITTS1HD: tts-1-hd

GPTModelsEnum

  • OAIGPT35Turbo: gpt-3.5-turbo
  • OAIGPT35Turbo1106: gpt-3.5-turbo-1106
  • OAIGPT35Turbo16k: gpt-3.5-turbo-16k
  • OAIGPT35TurboInstruct: gpt-3.5-turbo-instruct
  • OAIGPT4: gpt-4
  • OAIGPT4o: gpt-4o
  • OAIGPT432k: gpt-4-32k
  • OAIGPT4VisionPreview: gpt-4-vision-preview
  • OAIGPT41106Preview: gpt-4-1106-preview
  • Claude3Opus: claude-3-opus-20240229
  • Claude3Sonet: claude-3-sonnet-20240229
  • Claude3Haiku: claude-3-haiku-20240307

Interfaces

IDelete

interface IDelete {
  idTask: string;
}

IInsert

interface IInsert {
  name: string;
  context: string;
  model: string;
  instruction: string;
}

IRequest

interface IRequest {
  ask: string;
  context: string;
  idTask: string;
}

Methods

login(userName: string, password: string): Promise<void>

Logs in the user with the provided username and password.

makeRequest(method: string, endpoint: string, data?: any): Promise<AxiosResponse<any>>

Makes an HTTP request to the specified endpoint using the given HTTP method and optional data.

pingPong(): Promise<AxiosResponse<any>>

Pings the API to check if the connection is alive.

listTasks(): Promise<AxiosResponse<any>>

Lists all tasks available for the user.

runTask(request: IRequest): Promise<AxiosResponse<any>>

Runs a specific task based on the given request.

deleteTask(request: IDelete): Promise<AxiosResponse<any>>

Deletes a task specified by the request.

createTask(request: IInsert): Promise<AxiosResponse<any>>

Creates a new task with the provided request.

Error Handling Mechanism

The code uses try-catch blocks to handle errors that may occur during API requests. If an error occurs during the asynchronous requests, the catch block will handle the error by throwing it to be handled by the calling code.

Overall, this code provides a structured approach to interact with AI-related API endpoints, handle errors, and manage different types of AI models and tasks.

Usage Example

Start test

npm run test
or
yarn test
import { IRequest } from '../interfaces/request.interface';
import AIClient from '../index';

const userName = 'XXX@XXX';
const password = 'XXXXXXX';

const startTest = async () => {
  const client = new AIClient();
  await client.login(userName, password);
  const listOfTasks = await client.listTasks();
  console.log(listOfTasks);

  const testText = 'Your task description here.';
  const taskRequest: IRequest = {
    idTask: '52468971-a06e-413d-9b3a-212b53aad693',
    ask: testText,
    context: ' ',
  };

  const taskRun = await client.runTask(taskRequest);
  console.log(taskRun);
};

startTest();

CURL Usage Documentation

This documentation provides a comprehensive guide to using the AIClient class and making API requests using curl.

Authentication

Login

curl -X POST https://api.programmers4u.com/auth/login \
     -H "Content-Type: application/json" \
     -d '{"username": "your_username", "password": "your_password"}'

Tasks

List Tasks

curl -X GET https://api.programmers4u.com/products/tasks \
     -H "Authorization: Bearer your_access_token"

Run Task

curl -X POST https://api.programmers4u.com/products/tasks/query \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer your_access_token" \
     -d '{
           "idTask": "52468971-a06e-413d-9b3a-212b53aad693",
           "ask": "Your task description here.",
           "context": " "
         }'

Create Task

curl -X PUT https://api.programmers4u.com/products/tasks \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer your_access_token" \
     -d '{
           "name": "Task Name",
           "context": "Task Context",
           "model": "Model Name",
           "instruction": "Task Instructions"
         }'

Delete Task

curl -X DELETE https://api.programmers4u.com/products/tasks/52468971-a06e-413d-9b3a-212b53aad693 \
     -H "Authorization: Bearer your_access_token"

Ping API

curl -X GET https://api.programmers4u.com/ping