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

purai.js

v1.0.0-beta.2

Published

NPM package for PurAI API

Downloads

109

Readme

PurAI.js

PurAI.js is a simple JavaScript/TypeScript library that allows you to interact with the PurAI API.

Installation

npm install purai.js

Usage

Setup

First, you need to get an API key from the PurAI Discord server.

const { PurAi, ApiStyle } = require('purai.js');

const purAi = new PurAi('your-api-key', {
    // apiStyle: ApiStyle.OpenAi // Allows you to interact with the PurAI API using the OpenAI style
});

See the available models

await purAi.models();

Example Response

[
  {
    "type": "chatcompletion",
    "id": "claude-3-opus",
    "totalProviders": 2,
    "avaiableProviders": 2
  },
  {
    "type": "chatcompletion",
    "id": "claude-3-haiku",
    "totalProviders": 2,
    "avaiableProviders": 2
  },
  // ...
]

Chat with a model

await purAi.chat('Hello, how are you?');

await purAi.chat({
    role: 'user',
    content: 'Hello, how are you?'
});

await purAi.chat([
    {
        role: 'system',
        content: 'You are a helpful assistant.'
    },
    'Hello, how are you?'
]);

1. PurAI Style Response

{
    "provider": "c17ce511557f23e904e5dbaa8635651bec158d5ad512cce106b33a45a2be2cd2",
    "responseTime": 7229,
    "message": {
        "role": "assistant",
        "content": "Hello! As an AI language model, I don't have feelings, but I'm here and ready to help you with any questions or tasks you have. How can I assist you today?"
    },
    "history": [
        {
            "role": "user",
            "content": "Hello, how are you?"
        },
        {
            "role": "assistant",
            "content": "Hello! As an AI language model, I don't have feelings, but I'm here and ready to help you with any questions or tasks you have. How can I assist you today?"
        }
    ]
}

2. OpenAI Style Response

{
    "provider": "69f6d52b30f0ad4ef863d8fa1d4a8188baf1fcaa662209a27c7c05457c4a2374",
    "responseTime": 3665,
    "choices": [
        {
            "finishReason": "stop",
            "index": 0,
            "message": {
                "content": "Hello! I'm just a computer program, so I don't have feelings, but I'm here and ready to help you. What can I do for you today?",      
                "role": "assistant"
            }
        }
    ],
    "created": 1718905882921,
    "id": "chatcmpl-1718905882921-5wiun8dgp",
    "model": "gpt-4o",
    "object": "chat.completion",
    "usage": {
        "completionTokens": 1,
        "promptTokens": 1,
        "totalTokens": 2
    }
}

Chat with a model using the special Chat class

const { PurAi, Chat } = require('purai.js');

const purAi = new PurAi('your-api-key');
const chat = new Chat(purAi, 'gpt-4o');

await chat.send('Hello, how are you?');

chat.resetHistory();

await chat.send({
    role: 'user',
    content: 'Hello, how are you?'
});

chat.resetHistory();

await chat.send([
    {
        role: 'system',
        content: 'You are a helpful assistant.'
    },
    'Hello, how are you?'
]);

chat.resetHistory();

chat.addMessages({
    role: 'system',
    content: 'You are a helpful assistant.'
});

await chat.send('Hello, how are you?');

The responses are the same as the examples provided here.

Generate an image

[!WARNING] Generally the images are expired after 5 minutes, depending on the provider.

await purAi.generateImage('dalle-3', "Imagine a fluffy, ginger tabby cat lounging lazily in a patch of sunlight filtering through a window. Its fur glows with a warm, golden hue, accentuating the soft stripes that run along its back. The cat's eyes are a deep, amber color, reflecting the tranquility of its surroundings. It's curled up elegantly, with its tail neatly wrapped around its paws, exuding a sense of contentment and peace.");

1. PurAI Style Response

{
    "provider": "c17ce511557f23e904e5dbaa8635651bec158d5ad512cce106b33a45a2be2cd2",
    "responseTime": 7229,
    "image": "https://..."
}

2. OpenAI Style Response

Image generation for OpenAI style is not supported yet.