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 🙏

© 2025 – Pkg Stats / Ryan Hefner

uniai

v1.19.0

Published

To unify AI models!

Readme

import UniAI from 'uniai'
// fill the config for the provider/model you want to use!
const ai = new UniAI({ OpenAI: { key: 'Your key', proxy: 'Your proxy API' } })
// chat model
const chat = await ai.chat('hello world')
// embedding model
const embedding = await ai.embedding('hello world')
// imagine model
const task = await ai.imagine('a panda is eating bamboo')
// show imagining tasks, get generated images
const image = await ai.task(task.taskId)
// change image, Midjourney only, return a new task
const task2 = await ai.change('midjourney', task.taskId, 'UPSCALE', 4)

English · 🇨🇳 中文说明

Supported Models

Latest update: we have supported Claude latest models!

Applications Developed on UniAI

We have developed several sample applications using uniai:

Install

Using yarn:

yarn add uniai

Using npm:

npm install uniai --save

Example

We have written some simple call demos for you, which is placed in the examples folder. You can read the example files directly to learn how to use UniAI.

You can also read on to learn how to use UniAI based on this documentation.

You can set up environment variables by referring to the dotenv example

Prompt Tree and Markdown

You can use the Prompt class to build a hierarchical prompt tree and automatically generate Markdown from it. This is useful for organizing structured prompts or documentation.

Example:

import { Prompt } from 'uniai'

const prompt = new Prompt('Bot Info', 'This is a simple bot.')
prompt.add(new Prompt('Skills', 'English, Chinese'))
prompt.add(new Prompt('Profile', 'Age: 18\nGender: Male'))

console.log(prompt.toString())

Output Markdown:

# Bot Info

This is a simple bot.

## Skills

English, Chinese

## Profile

Age: 18
Gender: Male

List Models

You can use .models to list all the available models in UniAI.

TypeScript & JavaScript ES6+

import UniAI from 'uniai'

const ai = new UniAI()
console.log(ai.models)

JavaScript ES5

const UniAI = require('uniai').default

const ai = new UniAI()
console.log(ai.models)

Output

[
    {
        "provider": "OpenAI",
        "value": "openai",
        "models": ["gpt-3.5-turbo", "gpt-4o", "chatgpt-4o-latest", "gpt-4o-mini", "gpt-4-turbo", "gpt-4"]
    }
    // ...other providers and models
]

Chat

To interact with a model, use .chat() and remember to provide the required API key or secret parameters when initializing new UniAI().

Default model is OpenAI/gpt-4o, put the OpenAI key and your proxy API.

const key: string | string[] = 'Your OpenAI Key (required), support multi keys'
const proxy = 'Your OpenAI API proxy (optional)'
const uni = new UniAI({ OpenAI: { key, proxy } })
const res = await uni.chat()
console.log(res)

Output

{
    "content": "I am OpenAI's language model trained to assist with information.",
    "model": "gpt-3.5-turbo-0613",
    "object": "chat.completion",
    "promptTokens": 20,
    "completionTokens": 13,
    "totalTokens": 33
}

Chat with image

const input = [
    {
        role: 'user',
        content: 'Describe the image',
        img: 'https://img2.baidu.com/it/u=2595743336,2138195985&fm=253&fmt=auto?w=801&h=800'
        // or base64
    }
]
// Warn: If you choose a non-image model, img attributes will be dropped!
const res = await ai.chat(input, { model: 'gpt-4o' })
console.log(res)

Chat with audio

const input: ChatMessage[] = [
    {
        role: ChatRoleEnum.USER,
        content: '',
        audio: readFileSync(path.join(__dirname, 'test.wav')).toString('base64')
    }
]
// Warn: currently only support gpt-4o-audio-preview
const res = await ai.chat(input, { model: 'gpt-4o-audio-preview' })
console.log(res)

Output

{
    "content": "The image shows a person taking a mirror selfie using a smartphone...",
    "model": "gpt-4-1106-vision-preview",
    "object": "chat.completion",
    "promptTokens": 450,
    "completionTokens": 141,
    "totalTokens": 591
}

Streaming Chat

For streaming chat, the response is a JSON buffer.

The following is an example to chat with Google gemini-pro in stream mode.

const key: string | string[] = 'Your Google Key (required), support multi keys'
const proxy = 'Your google api proxy (optional)'
const uni = new UniAI({ Google: { key, proxy } })
const res = await uni.chat(input, { stream: true, provider: ModelProvider.Google, model: GoogleChatModel.GEM_PRO })
const stream = res as Readable
let data = ''
stream.on('data', chunk => (data += JSON.parse(chunk.toString()).content))
stream.on('end', () => console.log(data))

Output (Stream)

Language model trained by Google, at your service.

OpenAI-Compatible API and Ollama-Deployed Models

If you are connecting to an OpenAI-compatible API, or using Ollama to deploy models locally, you can use the Other provider.

For example, suppose you have deployed a model named qwen3:0.6b:

const OTHER_API = 'Your Ollama-deployed model endpoint, or other OpenAI-compatible APIs.'
const uni = new UniAI({ Other: { api: OTHER_API } })
uni.chat(input, { stream: false, provider: ChatModelProvider.Other, model: 'qwen3:0.6b' })
    .then(console.log)
    .catch(console.error)

Running Tests

UniAI uses jest to run unit tests on all supported models.

yarn test

If you want to run unit tests for a specific model provider:

# OpenAI, Google, Baidu, IFlyTek, MoonShot, GLM, Other, Imagine...
yarn test OpenAI

Thanks

Institute of Intelligent Computing Technology, Suzhou, CAS

Contributors

Youwei Huang

Weilong Yu

Who is using it

| Project | Brief introduction | | :----------------------------------------------------: | :---------------------------------------------------------------------------------------------------: | | UniAI MaaS | UniAI is a unified API platform designed to simplify interaction with a variety of complex AI models. | | LeChat | Document analysis based on large language model, dialogue with WeChat Mini Programs. | | LeChat Pro | Full-platform client based on UniAI, multi-model streaming dialogue platform. |

Star History

Star History Chart

License

MIT